about summary refs log tree commit diff
path: root/src/nix-store
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-01-19T16·59+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-01-19T16·59+0000
commite0f4e587c3a5110f57fbf4e85e14fdc606b1eaf6 (patch)
treec10ad0a943e6dac38b553b49633288dfee9ce84e /src/nix-store
parent96de272b48f8e9bdabffddb699ed4f2292d4f1d7 (diff)
* Nix-store queries `--references' and `referers' to query the pointer
  graph.  That is, `nix-store --query --references PATH' shows the set
  of paths referenced by PATH, and `nix-store --query --referers PATH'
  shows the set of paths referencing PATH.

Diffstat (limited to 'src/nix-store')
-rw-r--r--src/nix-store/main.cc37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/nix-store/main.cc b/src/nix-store/main.cc
index f8ddfd5d7887..e922a9755cc6 100644
--- a/src/nix-store/main.cc
+++ b/src/nix-store/main.cc
@@ -64,10 +64,18 @@ static Path maybeUseOutput(const Path & storePath, bool useOutput)
 }
 
 
+static void printPathSet(const PathSet & paths)
+{
+    for (PathSet::iterator i = paths.begin(); 
+         i != paths.end(); i++)
+        cout << format("%s\n") % *i;
+}
+
+
 /* Perform various sorts of queries. */
 static void opQuery(Strings opFlags, Strings opArgs)
 {
-    enum { qOutputs, qRequisites, qPredecessors, qGraph } query = qOutputs;
+    enum { qOutputs, qRequisites, qReferences, qReferers, qGraph } query = qOutputs;
     bool useOutput = false;
     bool includeOutputs = false;
 
@@ -75,6 +83,8 @@ static void opQuery(Strings opFlags, Strings opArgs)
          i != opFlags.end(); i++)
         if (*i == "--outputs") query = qOutputs;
         else if (*i == "--requisites" || *i == "-R") query = qRequisites;
+        else if (*i == "--references") query = qReferences;
+        else if (*i == "--referers") query = qReferers;
         else if (*i == "--graph") query = qGraph;
         else if (*i == "--use-output" || *i == "-u") useOutput = true;
         else if (*i == "--include-outputs") includeOutputs = true;
@@ -92,33 +102,24 @@ static void opQuery(Strings opFlags, Strings opArgs)
             break;
         }
 
-        case qRequisites: {
+        case qRequisites:
+        case qReferences:
+        case qReferers: {
             PathSet paths;
             for (Strings::iterator i = opArgs.begin();
                  i != opArgs.end(); i++)
             {
                 Path path = maybeUseOutput(*i, useOutput);
-                storePathRequisites(path, includeOutputs, paths);
+                if (query == qRequisites)
+                    storePathRequisites(path, includeOutputs, paths);
+                else if (query == qReferences) queryReferences(path, paths);
+                else if (query == qReferers) queryReferers(path,  paths);
             }
-            for (PathSet::iterator i = paths.begin(); 
-                 i != paths.end(); i++)
-                cout << format("%s\n") % *i;
+            printPathSet(paths);
             break;
         }
 
 #if 0            
-        case qPredecessors: {
-            for (Strings::iterator i = opArgs.begin();
-                 i != opArgs.end(); i++)
-            {
-                Paths preds = queryPredecessors(*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();