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 23:13:39 BST 2007


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

------------------------------------------------------------
revno: 2826
revision-id: robertc at robertcollins.net-20070917221329-s63xpy3v0j6btu56
parent: pqm at pqm.ubuntu.com-20070917005035-cshdkpzbj63id1uw
committer: Robert Collins <robertc at robertcollins.net>
branch nick: misc-fixen
timestamp: Tue 2007-09-18 08:13:29 +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 22:13:29 +0000
@@ -567,27 +567,21 @@
     return s.hexdigest()
 
 
-
-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