aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2011-12-30 15:02:50 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2011-12-30 15:02:50 +0000
commit6f5e3326cef2a2049c8f4ea757accafe4fc9d53f (patch)
tree89e50e0261f4c38b1b78cdedcbc55312cfbcbc3a
parentb1004f40f7e4dd02feec2d0cb26bd6c95dd66dde (diff)
* Move topoSortPaths() out of gc.cc.
-rw-r--r--src/libstore/gc.cc36
-rw-r--r--src/libstore/misc.cc36
2 files changed, 36 insertions, 36 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index ec7751133..14c8ba0bf 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -371,42 +371,6 @@ static void addAdditionalRoots(StoreAPI & store, PathSet & roots)
}
-static void dfsVisit(StoreAPI & store, const PathSet & paths,
- const Path & path, PathSet & visited, Paths & sorted,
- PathSet & parents)
-{
- if (parents.find(path) != parents.end())
- throw BuildError(format("cycle detected in the references of `%1%'") % path);
- parents.insert(path);
-
- if (visited.find(path) != visited.end()) return;
- visited.insert(path);
-
- PathSet references;
- if (store.isValidPath(path))
- store.queryReferences(path, references);
-
- foreach (PathSet::iterator, i, references)
- /* Don't traverse into paths that don't exist. That can
- happen due to substitutes for non-existent paths. */
- if (*i != path && paths.find(*i) != paths.end())
- dfsVisit(store, paths, *i, visited, sorted, parents);
-
- sorted.push_front(path);
- parents.erase(path);
-}
-
-
-Paths topoSortPaths(StoreAPI & store, const PathSet & paths)
-{
- Paths sorted;
- PathSet visited, parents;
- foreach (PathSet::const_iterator, i, paths)
- dfsVisit(store, paths, *i, visited, sorted, parents);
- return sorted;
-}
-
-
struct GCLimitReached { };
diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc
index d4bbccd11..abe59d162 100644
--- a/src/libstore/misc.cc
+++ b/src/libstore/misc.cc
@@ -97,4 +97,40 @@ void queryMissing(StoreAPI & store, const PathSet & targets,
}
+static void dfsVisit(StoreAPI & store, const PathSet & paths,
+ const Path & path, PathSet & visited, Paths & sorted,
+ PathSet & parents)
+{
+ if (parents.find(path) != parents.end())
+ throw BuildError(format("cycle detected in the references of `%1%'") % path);
+ parents.insert(path);
+
+ if (visited.find(path) != visited.end()) return;
+ visited.insert(path);
+
+ PathSet references;
+ if (store.isValidPath(path))
+ store.queryReferences(path, references);
+
+ foreach (PathSet::iterator, i, references)
+ /* Don't traverse into paths that don't exist. That can
+ happen due to substitutes for non-existent paths. */
+ if (*i != path && paths.find(*i) != paths.end())
+ dfsVisit(store, paths, *i, visited, sorted, parents);
+
+ sorted.push_front(path);
+ parents.erase(path);
+}
+
+
+Paths topoSortPaths(StoreAPI & store, const PathSet & paths)
+{
+ Paths sorted;
+ PathSet visited, parents;
+ foreach (PathSet::const_iterator, i, paths)
+ dfsVisit(store, paths, *i, visited, sorted, parents);
+ return sorted;
+}
+
+
}