diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2007-02-21 22:45:10 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2007-02-21 22:45:10 +0000 |
commit | 9da367b7d5e7c71efd802b87c99c11faff141499 (patch) | |
tree | 211ee4b64462765ffe10e587981ce61ca473c616 /src/nix-store/nix-store.cc | |
parent | 881feb96987dace75f983c16fec1013b70602d4f (diff) |
* `nix-store -qR' and friends: print the paths sorted topologically
under the references relation. This is useful for commands that
want to copy paths to another Nix store in the right order.
Diffstat (limited to 'src/nix-store/nix-store.cc')
-rw-r--r-- | src/nix-store/nix-store.cc | 43 |
1 files changed, 5 insertions, 38 deletions
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 6399c0974..293becc68 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -210,14 +210,6 @@ static Path maybeUseOutput(const Path & storePath, bool useOutput, bool forceRea } -static void printPathSet(const PathSet & paths) -{ - for (PathSet::iterator i = paths.begin(); - i != paths.end(); ++i) - cout << format("%s\n") % *i; -} - - /* Some code to print a tree representation of a derivation dependency graph. Topological sorting is used to keep the tree relatively flat. */ @@ -227,34 +219,6 @@ const string treeLine = "| "; const string treeNull = " "; -static void dfsVisit(const PathSet & paths, const Path & path, - PathSet & visited, Paths & sorted) -{ - if (visited.find(path) != visited.end()) return; - visited.insert(path); - - PathSet closure; - computeFSClosure(path, closure); - - for (PathSet::iterator i = closure.begin(); - i != closure.end(); ++i) - if (*i != path && paths.find(*i) != paths.end()) - dfsVisit(paths, *i, visited, sorted); - - sorted.push_front(path); -} - - -static Paths topoSort(const PathSet & paths) -{ - Paths sorted; - PathSet visited; - for (PathSet::const_iterator i = paths.begin(); i != paths.end(); ++i) - dfsVisit(paths, *i, visited, sorted); - return sorted; -} - - static void printTree(const Path & path, const string & firstPad, const string & tailPad, PathSet & done) { @@ -279,7 +243,7 @@ static void printTree(const Path & path, closure(B). That is, if derivation A is an (possibly indirect) input of B, then A is printed first. This has the effect of flattening the tree, preventing deeply nested structures. */ - Paths sorted = topoSort(references); + Paths sorted = topoSortPaths(references); reverse(sorted.begin(), sorted.end()); for (Paths::iterator i = sorted.begin(); i != sorted.end(); ++i) { @@ -355,7 +319,10 @@ static void opQuery(Strings opFlags, Strings opArgs) else if (query == qReferrers) store->queryReferrers(path, paths); else if (query == qReferrersClosure) computeFSClosure(path, paths, true); } - printPathSet(paths); + Paths sorted = topoSortPaths(paths); + for (Paths::reverse_iterator i = sorted.rbegin(); + i != sorted.rend(); ++i) + cout << format("%s\n") % *i; break; } |