about summary refs log tree commit diff
path: root/src/nix-hash/nix-hash.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-08-14T10·09+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-08-14T10·09+0000
commit039936567539c1d6d7a3b824b94726b3fed3343b (patch)
treed4fccd763f14bc38e1b82e65e634c5a441b556ff /src/nix-hash/nix-hash.cc
parent2fd22c63600a3c91d25316b566fc00aa2415bfee (diff)
* nix-hash: option `--truncate' to truncate the hash to 160 bits. Hmm,
  kind of ad hoc ;-)

Diffstat (limited to 'src/nix-hash/nix-hash.cc')
-rw-r--r--src/nix-hash/nix-hash.cc3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/nix-hash/nix-hash.cc b/src/nix-hash/nix-hash.cc
index 78c6f44012b4..4a7c943963d9 100644
--- a/src/nix-hash/nix-hash.cc
+++ b/src/nix-hash/nix-hash.cc
@@ -16,12 +16,14 @@ void run(Strings args)
     HashType ht = htMD5;
     bool flat = false;
     bool base32 = false;
+    bool truncate = false;
     
     for (Strings::iterator i = args.begin();
          i != args.end(); i++)
     {
         if (*i == "--flat") flat = true;
         else if (*i == "--base32") base32 = true;
+        else if (*i == "--truncate") truncate = true;
         else if (*i == "--type") {
             ++i;
             if (i == args.end()) throw UsageError("`--type' requires an argument");
@@ -31,6 +33,7 @@ void run(Strings args)
         }
         else {
             Hash h = flat ? hashFile(ht, *i) : hashPath(ht, *i);
+            if (truncate && h.hashSize > 20) h = compressHash(h, 20);
             cout << format("%1%\n") %
                 (base32 ? printHash32(h) : printHash(h));
         }