about summary refs log tree commit diff
path: root/src/nix.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-10-10T15·25+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-10-10T15·25+0000
commit1d61e473c88568fae7ef5edebc77acd53e4126f9 (patch)
tree403c4cec6f2093cb16e95362b60ea058af714eb7 /src/nix.cc
parent0abe185688aa19c9ca87c9d22e24a54b4b359969 (diff)
* New query `nix --query --predecessors' to print the predecessors of
  a Nix expression.

Diffstat (limited to 'src/nix.cc')
-rw-r--r--src/nix.cc15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/nix.cc b/src/nix.cc
index 9907f5c74da6..9bbbf4ae8c85 100644
--- a/src/nix.cc
+++ b/src/nix.cc
@@ -73,7 +73,7 @@ Path maybeNormalise(const Path & ne, bool normalise)
 /* Perform various sorts of queries. */
 static void opQuery(Strings opFlags, Strings opArgs)
 {
-    enum { qList, qRequisites, qGenerators, qGraph 
+    enum { qList, qRequisites, qGenerators, qPredecessors, qGraph 
     } query = qList;
     bool normalise = false;
     bool includeExprs = true;
@@ -84,6 +84,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
         if (*i == "--list" || *i == "-l") query = qList;
         else if (*i == "--requisites" || *i == "-r") query = qRequisites;
         else if (*i == "--generators" || *i == "-g") query = qGenerators;
+        else if (*i == "--predecessors") query = qPredecessors;
         else if (*i == "--graph") query = qGraph;
         else if (*i == "--normalise" || *i == "-n") normalise = true;
         else if (*i == "--exclude-exprs") includeExprs = false;
@@ -139,6 +140,18 @@ static void opQuery(Strings opFlags, Strings opArgs)
         }
 #endif
 
+        case qPredecessors: {
+            for (Strings::iterator i = opArgs.begin();
+                 i != opArgs.end(); i++)
+            {
+                Paths preds = queryPredecessors(checkPath(*i));
+                for (Paths::iterator j = preds.begin();
+                     j != preds.end(); j++)
+                    cout << format("%s\n") % *j;
+            }
+            break;
+        }
+
         case qGraph: {
             PathSet roots;
             for (Strings::iterator i = opArgs.begin();