[PATCH] largefiles: Use sha1sum.py since OS X has generic shasum utility

Lee Cantey lcantey at gmail.com
Mon Oct 24 13:15:57 CDT 2011


# HG changeset patch
# User Lee Cantey <lcantey at gmail.com>
# Date 1319479837 25200
# Branch stable
# Node ID 17323a5ee76870b1b48e7308511c34c98825f35a
# Parent  8b8dd13295dbd733cc03ebb3c2af2f33d24d5428
largefiles: Use sha1sum.py since OS X has generic shasum utility.

Also switch to from echo -n to printf

diff -r 8b8dd13295db -r 17323a5ee768 tests/sha1sum.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/sha1sum.py	Mon Oct 24 11:10:37 2011 -0700
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+#
+# Based on python's Tools/scripts/md5sum.py
+#
+# This software may be used and distributed according to the terms
+# of the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2, which is
+# GPL-compatible.
+
+import sys, os
+
+try:
+    from hashlib import sha1
+except ImportError:
+    from sha import sha as sha1
+
+try:
+    import msvcrt
+    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
+    msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
+except ImportError:
+    pass
+
+for filename in sys.argv[1:]:
+    try:
+        fp = open(filename, 'rb')
+    except IOError, msg:
+        sys.stderr.write('%s: Can\'t open: %s\n' % (filename, msg))
+        sys.exit(1)
+
+    m = sha1()
+    try:
+        while True:
+            data = fp.read(8192)
+            if not data:
+                break
+            m.update(data)
+    except IOError, msg:
+        sys.stderr.write('%s: I/O error: %s\n' % (filename, msg))
+        sys.exit(1)
+    sys.stdout.write('%s  %s\n' % (m.hexdigest(), filename))
+
+sys.exit(0)
diff -r 8b8dd13295db -r 17323a5ee768 tests/test-lfconvert.t
--- a/tests/test-lfconvert.t	Sun Oct 23 14:25:48 2011 -0400
+++ b/tests/test-lfconvert.t	Mon Oct 24 11:10:37 2011 -0700
@@ -48,7 +48,7 @@
   normal
   $ cat sub/normal2
   alsonormal
-  $ sha1sum large sub/maybelarge.dat
+  $ $TESTDIR/sha1sum.py large sub/maybelarge.dat
   2e000fa7e85759c7f4c254d4d9c33ef481e459a7  large
   34e163be8e43c5631d8b92e9c43ab0bf0fa62b9c  sub/maybelarge.dat
 
@@ -74,7 +74,7 @@
   $ echo blah >> normal3
   $ echo blah >> sub/normal2
   $ echo blah >> sub/maybelarge.dat
-  $ sha1sum sub/maybelarge.dat
+  $ $TESTDIR/sha1sum.py sub/maybelarge.dat
   76236b6a2c6102826c61af4297dd738fb3b1de38  sub/maybelarge.dat
   $ hg commit -A -m"add normal3, modify sub/*"
   adding normal3
@@ -151,7 +151,7 @@
   $ cat stuff/normal2
   alsonormal
   blah
-  $ sha1sum stuff/maybelarge.dat
+  $ $TESTDIR/sha1sum.py stuff/maybelarge.dat
   76236b6a2c6102826c61af4297dd738fb3b1de38  stuff/maybelarge.dat
   $ cat .hglf/stuff/maybelarge.dat
   76236b6a2c6102826c61af4297dd738fb3b1de38
@@ -168,7 +168,7 @@
   abort: repository nosuchrepo not found!
   [255]
   $ hg share -q -U bigfile-repo shared
-  $ echo -n bogus > shared/.hg/sharedpath
+  $ printf bogus > shared/.hg/sharedpath
   $ hg lfconvert shared foo
   abort: .hg/sharedpath points to nonexistent directory $TESTTMP/bogus!
   [255]


More information about the Mercurial-devel mailing list