Rev 2826: Micro-tweaks to sha routines. in http://people.ubuntu.com/~robertc/baz2.0/misc-fixen

Robert Collins robertc at robertcollins.net
Mon Sep 17 08:28:30 BST 2007


At http://people.ubuntu.com/~robertc/baz2.0/misc-fixen

------------------------------------------------------------
revno: 2826
revision-id: robertc at robertcollins.net-20070917072821-avuip2u0zco6aky5
parent: pqm at pqm.ubuntu.com-20070917005035-cshdkpzbj63id1uw
committer: Robert Collins <robertc at robertcollins.net>
branch nick: misc-fixen
timestamp: Mon 2007-09-17 17:28:21 +1000
message:
  Micro-tweaks to sha routines.
modified:
  bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2007-08-21 01:32:29 +0000
+++ b/bzrlib/osutils.py	2007-09-17 07:28:21 +0000
@@ -568,26 +568,21 @@
 
 
 
-def sha_strings(strings):
+def sha_strings(strings, factory=sha.new):
     """Return the sha-1 of concatenation of strings"""
-    s = sha.new()
+    s = factory()
     map(s.update, strings)
     return s.hexdigest()
 
 
-def sha_string(f):
-    s = sha.new()
-    s.update(f)
-    return s.hexdigest()
+def sha_string(f, factory=sha.new):
+    return factory(f).hexdigest()
 
 
 def fingerprint_file(f):
-    s = sha.new()
     b = f.read()
-    s.update(b)
-    size = len(b)
-    return {'size': size,
-            'sha1': s.hexdigest()}
+    return {'size': len(b),
+            'sha1': sha.new(b).hexdigest()}
 
 
 def compare_files(a, b):



More information about the bazaar-commits mailing list