From 3acba7951aa6597b789423233ad2b28f31ee83fb Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Tue, 17 Dec 2024 16:25:00 +0100 Subject: [PATCH] libexpr: use StorePath::to_string in string contexts `path.abs()` does the same thing, but `to_string` communicates intent as well. Change-Id: I9619a9f2e32317f0a1cc8e092ce8898471b980ac --- lix/legacy/nix-env.cc | 2 +- lix/libexpr/eval.cc | 4 ++-- lix/libexpr/primops.cc | 2 +- lix/libexpr/value-to-json.cc | 2 +- lix/libexpr/value-to-xml.cc | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lix/legacy/nix-env.cc b/lix/legacy/nix-env.cc index 3862288f4..97b59a7ab 100644 --- a/lix/legacy/nix-env.cc +++ b/lix/legacy/nix-env.cc @@ -138,7 +138,7 @@ static void getAllExprs(Evaluator & state, attrName = std::string(attrName, 0, attrName.size() - 4); if (!seen.insert(attrName).second) { std::string suggestionMessage = ""; - if (path2.path.abs().find("channels") != std::string::npos && path.path.abs().find("channels") != std::string::npos) + if (path2.to_string().find("channels") != std::string::npos && path.to_string().find("channels") != std::string::npos) suggestionMessage = fmt("\nsuggestion: remove '%s' from either the root channels or the user channels", attrName); printError("warning: name collision in input Nix expressions, skipping '%1%'" "%2%", path2, suggestionMessage); diff --git a/lix/libexpr/eval.cc b/lix/libexpr/eval.cc index 6f52566a3..dae7daafc 100644 --- a/lix/libexpr/eval.cc +++ b/lix/libexpr/eval.cc @@ -805,7 +805,7 @@ void EvalState::mkPos(Value & v, PosIdx p) auto origin = ctx.positions.originOf(p); if (auto path = std::get_if(&origin)) { auto attrs = ctx.buildBindings(3); - attrs.alloc(ctx.s.file).mkString(path->path.abs()); + attrs.alloc(ctx.s.file).mkString(path->to_string()); makePositionThunks(*this, p, attrs.alloc(ctx.s.line), attrs.alloc(ctx.s.column)); v.mkAttrs(attrs); } else @@ -2269,7 +2269,7 @@ BackedStringView EvalState::coerceToString( v._path : copyToStore ? ctx.store->printStorePath(ctx.paths.copyPathToStore(context, v.path(), ctx.repair)) - : std::string(v.path().path.abs()); + : v.path().to_string(); } if (v.type() == nAttrs) { diff --git a/lix/libexpr/primops.cc b/lix/libexpr/primops.cc index 328ce250b..d88a5525a 100644 --- a/lix/libexpr/primops.cc +++ b/lix/libexpr/primops.cc @@ -1153,7 +1153,7 @@ static void prim_toPath(EvalState & state, const PosIdx pos, Value * * args, Val { NixStringContext context; auto path = state.coerceToPath(pos, *args[0], context, "while evaluating the first argument passed to builtins.toPath"); - v.mkString(path.path.abs(), context); + v.mkString(path.to_string(), context); } /* Allow a valid store path to be used in an expression. This is diff --git a/lix/libexpr/value-to-json.cc b/lix/libexpr/value-to-json.cc index 4a2ad7062..0ba517604 100644 --- a/lix/libexpr/value-to-json.cc +++ b/lix/libexpr/value-to-json.cc @@ -39,7 +39,7 @@ json printValueAsJSON(EvalState & state, bool strict, out = state.ctx.store->printStorePath( state.ctx.paths.copyPathToStore(context, v.path(), state.ctx.repair)); else - out = v.path().path.abs(); + out = v.path().to_string(); break; case nNull: diff --git a/lix/libexpr/value-to-xml.cc b/lix/libexpr/value-to-xml.cc index 17426b12e..49c21623f 100644 --- a/lix/libexpr/value-to-xml.cc +++ b/lix/libexpr/value-to-xml.cc @@ -22,7 +22,7 @@ static void printValueAsXML(EvalState & state, bool strict, bool location, static void posToXML(EvalState & state, XMLAttrs & xmlAttrs, const Pos & pos) { if (auto path = std::get_if(&pos.origin)) - xmlAttrs["path"] = path->path.abs(); + xmlAttrs["path"] = path->to_string(); xmlAttrs["line"] = fmt("%1%", pos.line); xmlAttrs["column"] = fmt("%1%", pos.column); }