[Pkg-bazaar-commits] ./bzr/unstable r124: - check file text for past revisions is correct

mbp at sourcefrog.net mbp at sourcefrog.net
Fri Apr 10 07:51:11 UTC 2009


------------------------------------------------------------
revno: 124
committer: mbp at sourcefrog.net
timestamp: Tue 2005-03-29 10:23:20 +1000
message:
  - check file text for past revisions is correct
  - new fingerprint_file function
modified:
  bzrlib/check.py
  bzrlib/osutils.py
-------------- next part --------------
=== modified file 'bzrlib/check.py'
--- a/bzrlib/check.py	2005-03-29 00:10:32 +0000
+++ b/bzrlib/check.py	2005-03-29 00:23:20 +0000
@@ -26,7 +26,7 @@
 import bzrlib
 from trace import mutter
 from errors import bailout
-
+import osutils
 
 def check(branch, progress=True):
     out = sys.stdout
@@ -95,6 +95,13 @@
         if ie.kind == 'file':
             if not ie.text_id in branch.text_store:
                 bailout('text {%s} not in text_store' % ie.text_id)
+
+            tf = branch.text_store[ie.text_id]
+            fp = osutils.fingerprint_file(tf)
+            if ie.text_size != fp['size']:
+                bailout('text {%s} wrong size' % ie.text_id)
+            if ie.text_sha1 != fp['sha1']:
+                bailout('text {%s} wrong sha1' % ie.text_id)
         elif ie.kind == 'directory':
             if ie.text_sha1 != None or ie.text_size != None or ie.text_id != None:
                 bailout('directory {%s} has text in revision {%s}'

=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2005-03-23 12:30:39 +0000
+++ b/bzrlib/osutils.py	2005-03-29 00:23:20 +0000
@@ -117,6 +117,22 @@
 
 
 
+def fingerprint_file(f):
+    import sha
+    s = sha.new()
+    size = 0
+    BUFSIZE = 64<<10
+    while True:
+        b = f.read(BUFSIZE)
+        if b == '':
+            break
+        s.update(b)
+        size += len(b)
+    return {'size': size,
+            'sha1': s.hexdigest()}
+
+
+
 def username():
     """Return email-style username.
 



More information about the Pkg-bazaar-commits mailing list