about summary refs log tree commit diff
path: root/src/normalise.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-07-29T14·28+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-07-29T14·28+0000
commit884646593488bfacd851bec72b7ac1a4841bf458 (patch)
tree0417e939be5e5d12645966da3fe6f41fefde0ea2 /src/normalise.cc
parentdc14a3de46ee08a28158a886b6abba2c4144f6cd (diff)
* Get garbage collection and cache population to work *properly*.
  Renamed `fstateRefs' to `fstateRequisites'.  The semantics of this
  function is that it returns a list of all paths necessary to realise
  a given expression.  For a derive expression, this is the union of
  requisites of the inputs; for a slice expression, it is the path of
  each element in the slice.  Also included are the paths of the
  expressions themselves.  Optionally, one can also include the
  requisites of successor expressions (to recycle intermediate
  results).

* `nix-switch' now distinguishes between an expression and its normal
  form.  Usually, only the normal form is registered as a root of the
  garbage collector.  With the `--source-root' flag, it will also
  register the original expression as a root.

* `nix-collect-garbage' now has a flag `--keep-successors' which
  causes successors not to be included in the list of garbage paths.

* `nix-collect-garbage' now has a flag `--invert' which will print all
  paths that should *not* be garbage collected.

Diffstat (limited to 'src/normalise.cc')
-rw-r--r--src/normalise.cc20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/normalise.cc b/src/normalise.cc
index eefb790b6f98..5ef4d82ac139 100644
--- a/src/normalise.cc
+++ b/src/normalise.cc
@@ -244,7 +244,8 @@ Strings fstatePaths(const FSId & id)
 }
 
 
-static void fstateRefsSet(const FSId & id, StringSet & paths)
+static void fstateRequisitesSet(const FSId & id, 
+    bool includeExprs, bool includeSuccessors, StringSet & paths)
 {
     FState fs = parseFState(termFromId(id));
 
@@ -257,17 +258,28 @@ static void fstateRefsSet(const FSId & id, StringSet & paths)
     else if (fs.type == FState::fsDerive) {
         for (FSIds::iterator i = fs.derive.inputs.begin();
              i != fs.derive.inputs.end(); i++)
-            fstateRefsSet(*i, paths);
+            fstateRequisitesSet(*i,
+                includeExprs, includeSuccessors, paths);
     }
 
     else abort();
+
+    if (includeExprs) 
+        paths.insert(expandId(id));
+
+    string idSucc;
+    if (includeSuccessors &&
+        queryDB(nixDB, dbSuccessors, id, idSucc))
+        fstateRequisitesSet(parseHash(idSucc), 
+            includeExprs, includeSuccessors, paths);
 }
 
 
-Strings fstateRefs(const FSId & id)
+Strings fstateRequisites(const FSId & id,
+    bool includeExprs, bool includeSuccessors)
 {
     StringSet paths;
-    fstateRefsSet(id, paths);
+    fstateRequisitesSet(id, includeExprs, includeSuccessors, paths);
     return Strings(paths.begin(), paths.end());
 }