Skip to content

Commit

Permalink
Print the store paths to be fetched sorted by StorePath name() and no…
Browse files Browse the repository at this point in the history
…t baseName

Presently when nix says something like:

```
these 486 paths will be fetched (511.54 MiB download, 6458.64 MiB unpacked):
 ...path1
 ...path2
 ...path3
    ...
    ...
 ...path486
```

It sorts path1, path2, path3, ..., path486 in lexicographic order of the
store path.

After this commit, nix will show path1, path2, path3, ..., path486 sorted by
StorePath name() (basically everything after the hash) rather than the store path.

This makes it easier to review what exactly is being downloaded at a glance,
especially when many paths need to be fetched.
  • Loading branch information
sidkshatriya committed Feb 23, 2023
1 parent 4a921ba commit ff9e8a0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/libmain/shared.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ void printMissing(ref<Store> store, const StorePathSet & willBuild,
downloadSizeMiB,
narSizeMiB);
}
for (auto & i : willSubstitute)
auto willSubstituteSorted = NameSortedStorePathSetView(willSubstitute.begin(), willSubstitute.end());
for (auto & i : willSubstituteSorted)
printMsg(lvl, " %s", store->printStorePath(i));
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstore/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ StorePathSet Store::parseStorePathSet(const PathSet & paths) const
return res;
}

std::string Store::printStorePath(const StorePath & path) const
std::string Store::printStorePath(const StorePathView & path) const
{
return (storeDir + "/").append(path.to_string());
}
Expand Down
40 changes: 40 additions & 0 deletions src/libstore/path.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace nix {

struct Hash;
class StorePathView;

class StorePath
{
Expand Down Expand Up @@ -64,7 +65,46 @@ public:
static StorePath random(std::string_view name);
};

class StorePathView {
const StorePath *pStorePath;

public:
StorePathView() = delete;

StorePathView(const StorePath &spath) : pStorePath(&spath) {}

std::string_view to_string() const { return pStorePath->to_string(); }

bool isDerivation() const { return pStorePath->isDerivation(); }

std::string_view name() const { return pStorePath->name(); }

std::string_view hashPart() const { return pStorePath->hashPart(); }

bool operator<(const StorePathView &other) const {
return *pStorePath < *other.pStorePath;
}

bool operator==(const StorePathView &other) const {
return *pStorePath == *other.pStorePath;
}

bool operator!=(const StorePathView &other) const {
return *pStorePath != *other.pStorePath;
}
};

struct NameSortedLessForStorePathView {
bool operator()(const StorePathView &lhs, const StorePathView &rhs) const {
if (lhs.name() == rhs.name())
return lhs.to_string() < rhs.to_string();
else
return lhs.name() < rhs.name();
}
};

typedef std::set<StorePath> StorePathSet;
typedef std::set<StorePathView, NameSortedLessForStorePathView> NameSortedStorePathSetView;
typedef std::vector<StorePath> StorePaths;

/* Extension of derivations in the Nix store. */
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/store-api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public:

std::optional<StorePath> maybeParseStorePath(std::string_view path) const;

std::string printStorePath(const StorePath & path) const;
std::string printStorePath(const StorePathView & path) const;

// FIXME: remove
StorePathSet parseStorePathSet(const PathSet & paths) const;
Expand Down

0 comments on commit ff9e8a0

Please sign in to comment.