Skip to content

Commit

Permalink
Merge pull request #9411 from edolstra/path-display
Browse files Browse the repository at this point in the history
Improve SourceAccessor path display
  • Loading branch information
roberth authored Nov 21, 2023
2 parents 4d8decb + a0162d5 commit 9cd69e1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,9 @@ EvalState::EvalState(
, baseEnv(allocEnv(128))
, staticBaseEnv{std::make_shared<StaticEnv>(false, nullptr)}
{
corepkgsFS->setPathDisplay("<nix", ">");
internalFS->setPathDisplay("«nix-internal»", "");

countCalls = getEnv("NIX_COUNT_CALLS").value_or("0") != "0";

assert(gcInitialised);
Expand Down
1 change: 1 addition & 0 deletions src/libfetchers/fs-input-accessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct FSInputAccessorImpl : FSInputAccessor, PosixSourceAccessor
, allowedPaths(std::move(allowedPaths))
, makeNotAllowedError(std::move(makeNotAllowedError))
{
displayPrefix = root.isRoot() ? "" : root.abs();
}

void readFile(
Expand Down
2 changes: 2 additions & 0 deletions src/libfetchers/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,8 @@ struct GitInputScheme : InputScheme

auto accessor = repo->getAccessor(rev);

accessor->setPathDisplay("«" + input.to_string() + "»");

/* If the repo has submodules, fetch them and return a mounted
input accessor consisting of the accessor for the top-level
repo and the accessors for the submodules. */
Expand Down
2 changes: 1 addition & 1 deletion src/libutil/posix-source-accessor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace nix {
/**
* A source accessor that uses the Unix filesystem.
*/
struct PosixSourceAccessor : SourceAccessor
struct PosixSourceAccessor : virtual SourceAccessor
{
/**
* The most recent mtime seen by lstat(). This is a hack to
Expand Down
9 changes: 8 additions & 1 deletion src/libutil/source-accessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ static std::atomic<size_t> nextNumber{0};

SourceAccessor::SourceAccessor()
: number(++nextNumber)
, displayPrefix{"«unknown»"}
{
}

Expand Down Expand Up @@ -55,9 +56,15 @@ SourceAccessor::Stat SourceAccessor::lstat(const CanonPath & path)
throw Error("path '%s' does not exist", showPath(path));
}

void SourceAccessor::setPathDisplay(std::string displayPrefix, std::string displaySuffix)
{
this->displayPrefix = std::move(displayPrefix);
this->displaySuffix = std::move(displaySuffix);
}

std::string SourceAccessor::showPath(const CanonPath & path)
{
return path.abs();
return displayPrefix + path.abs() + displaySuffix;
}

}
4 changes: 4 additions & 0 deletions src/libutil/source-accessor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ struct SourceAccessor
{
const size_t number;

std::string displayPrefix, displaySuffix;

SourceAccessor();

virtual ~SourceAccessor()
Expand Down Expand Up @@ -117,6 +119,8 @@ struct SourceAccessor
return number < x.number;
}

void setPathDisplay(std::string displayPrefix, std::string displaySuffix = "");

virtual std::string showPath(const CanonPath & path);
};

Expand Down

0 comments on commit 9cd69e1

Please sign in to comment.