about summary refs log tree commit diff
path: root/src/nix-store/main.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-03-02T15·57+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-03-02T15·57+0000
commit07b4399fb6f04d0cae58b8cf0a13efeeaf9d590b (patch)
treecd35f9205c15098f51c6c11da5148b27e4c7060f /src/nix-store/main.cc
parent9e50e648a47c1ef3b734bf12945c8b29a8c8f9f8 (diff)
* `nix-store -q --hash' to quickly query the hash of the contents of a
  store path (which is stored in the database).

Diffstat (limited to 'src/nix-store/main.cc')
-rw-r--r--src/nix-store/main.cc23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/nix-store/main.cc b/src/nix-store/main.cc
index 6e590ba06f9c..543a84210bd2 100644
--- a/src/nix-store/main.cc
+++ b/src/nix-store/main.cc
@@ -228,8 +228,9 @@ static void printDrvTree(const Path & drvPath,
 /* Perform various sorts of queries. */
 static void opQuery(Strings opFlags, Strings opArgs)
 {
-    enum { qOutputs, qRequisites, qReferences, qReferers,
-           qReferersClosure, qDeriver, qBinding, qTree, qGraph } query = qOutputs;
+    enum { qOutputs, qRequisites, qReferences, qReferers
+         , qReferersClosure, qDeriver, qBinding, qHash
+         , qTree, qGraph } query = qOutputs;
     bool useOutput = false;
     bool includeOutputs = false;
     bool forceRealise = false;
@@ -250,6 +251,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
             opArgs.pop_front();
             query = qBinding;
         }
+        else if (*i == "--hash") query = qHash;
         else if (*i == "--tree") query = qTree;
         else if (*i == "--graph") query = qGraph;
         else if (*i == "--use-output" || *i == "-u") useOutput = true;
@@ -279,8 +281,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
             for (Strings::iterator i = opArgs.begin();
                  i != opArgs.end(); i++)
             {
-                *i = fixPath(*i);
-                Path path = maybeUseOutput(*i, useOutput, forceRealise);
+                Path path = maybeUseOutput(fixPath(*i), useOutput, forceRealise);
                 if (query == qRequisites)
                     storePathRequisites(path, includeOutputs, paths);
                 else if (query == qReferences) queryReferences(noTxn, path, paths);
@@ -295,8 +296,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
             for (Strings::iterator i = opArgs.begin();
                  i != opArgs.end(); i++)
             {
-                *i = fixPath(*i);
-                Path deriver = queryDeriver(noTxn, *i);
+                Path deriver = queryDeriver(noTxn, fixPath(*i));
                 cout << format("%1%\n") %
                     (deriver == "" ? "unknown-deriver" : deriver);
             }
@@ -316,6 +316,17 @@ static void opQuery(Strings opFlags, Strings opArgs)
             }
             break;
 
+        case qHash:
+            for (Strings::iterator i = opArgs.begin();
+                 i != opArgs.end(); i++)
+            {
+                Path path = maybeUseOutput(fixPath(*i), useOutput, forceRealise);
+                Hash hash = queryPathHash(path);
+                assert(hash.type == htSHA256);
+                cout << format("sha256:%1%\n") % printHash32(hash);
+            }
+            break;
+
         case qTree: {
             PathSet done;
             for (Strings::iterator i = opArgs.begin();