about summary refs log tree commit diff
path: root/src/nix.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-07-29T10·43+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-07-29T10·43+0000
commit79ba0431db223c1c08b46e8f3d1819e3457f21a0 (patch)
treed1d95370475a85bf9008f442489d7461f06f1d10 /src/nix.cc
parent5acb45446e756c023bcb6f052331181671580a5e (diff)
* `fstateRefs' now works on derive expressions as well. TODO: make
  this more efficient.
* A flag `-n' in 'nix --query' to normalise the argument.  Default is
  not to normalise.

Diffstat (limited to 'src/nix.cc')
-rw-r--r--src/nix.cc16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/nix.cc b/src/nix.cc
index 6dc5776e25db..e9f04ff59d74 100644
--- a/src/nix.cc
+++ b/src/nix.cc
@@ -80,17 +80,24 @@ static void opAdd(Strings opFlags, Strings opArgs)
 }
 
 
-string dotQuote(const string & s)
+static string dotQuote(const string & s)
 {
     return "\"" + s + "\"";
 }
 
 
+FSId maybeNormalise(const FSId & id, bool normalise)
+{
+    return normalise ? normaliseFState(id) : id;
+}
+
+
 /* Perform various sorts of queries. */
 static void opQuery(Strings opFlags, Strings opArgs)
 {
     enum { qList, qRefs, qGenerators, qExpansion, qGraph 
     } query = qList;
+    bool normalise = false;
 
     for (Strings::iterator i = opFlags.begin();
          i != opFlags.end(); i++)
@@ -99,6 +106,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
         else if (*i == "--generators" || *i == "-g") query = qGenerators;
         else if (*i == "--expansion" || *i == "-e") query = qExpansion;
         else if (*i == "--graph") query = qGraph;
+        else if (*i == "--normalise" || *i == "-n") normalise = true;
         else throw UsageError(format("unknown flag `%1%'") % *i);
 
     switch (query) {
@@ -108,7 +116,8 @@ static void opQuery(Strings opFlags, Strings opArgs)
             for (Strings::iterator i = opArgs.begin();
                  i != opArgs.end(); i++)
             {
-                Strings paths2 = fstatePaths(argToId(*i), true);
+                Strings paths2 = fstatePaths(
+                    maybeNormalise(argToId(*i), normalise));
                 paths.insert(paths2.begin(), paths2.end());
             }
             for (StringSet::iterator i = paths.begin(); 
@@ -122,7 +131,8 @@ static void opQuery(Strings opFlags, Strings opArgs)
             for (Strings::iterator i = opArgs.begin();
                  i != opArgs.end(); i++)
             {
-                Strings paths2 = fstateRefs(argToId(*i));
+                Strings paths2 = fstateRefs(
+                    maybeNormalise(argToId(*i), normalise));
                 paths.insert(paths2.begin(), paths2.end());
             }
             for (StringSet::iterator i = paths.begin();