[Pkg-bazaar-commits] ./bzr/unstable r676: - lock branch while checking
Martin Pool
mbp at sourcefrog.net
Fri Apr 10 08:20:40 UTC 2009
------------------------------------------------------------
revno: 676
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Sat 2005-06-11 11:58:46 +1000
message:
- lock branch while checking
modified:
bzrlib/check.py
-------------- next part --------------
=== modified file 'bzrlib/check.py'
--- a/bzrlib/check.py 2005-06-11 01:52:47 +0000
+++ b/bzrlib/check.py 2005-06-11 01:58:46 +0000
@@ -31,174 +31,183 @@
from bzrlib.errors import BzrCheckError
from bzrlib.osutils import fingerprint_file
from bzrlib.progress import ProgressBar
-
- out = sys.stdout
-
- pb = ProgressBar(show_spinner=True)
- last_ptr = None
- checked_revs = {}
-
- missing_inventory_sha_cnt = 0
-
- history = branch.revision_history()
- revno = 0
- revcount = len(history)
-
- checked_texts = {}
-
- updated_revisions = []
-
- # Set to True in the case that the previous revision entry
- # was updated, since this will affect future revision entries
- updated_previous_revision = False
-
- for rid in history:
- revno += 1
- pb.update('checking revision', revno, revcount)
- mutter(' revision {%s}' % rid)
- rev = branch.get_revision(rid)
- if rev.revision_id != rid:
- raise BzrCheckError('wrong internal revision id in revision {%s}' % rid)
- if rev.precursor != last_ptr:
- raise BzrCheckError('mismatched precursor in revision {%s}' % rid)
- last_ptr = rid
- if rid in checked_revs:
- raise BzrCheckError('repeated revision {%s}' % rid)
- checked_revs[rid] = True
-
- ## TODO: Check all the required fields are present on the revision.
-
- updated = False
- if rev.inventory_sha1:
- #mutter(' checking inventory hash {%s}' % rev.inventory_sha1)
- inv_sha1 = branch.get_inventory_sha1(rev.inventory_id)
- if inv_sha1 != rev.inventory_sha1:
- raise BzrCheckError('Inventory sha1 hash doesn\'t match'
- ' value in revision {%s}' % rid)
- elif update:
- inv_sha1 = branch.get_inventory_sha1(rev.inventory_id)
- rev.inventory_sha1 = inv_sha1
- updated = True
- else:
- missing_inventory_sha_cnt += 1
- mutter("no inventory_sha1 on revision {%s}" % rid)
-
- if rev.precursor:
- if rev.precursor_sha1:
- precursor_sha1 = branch.get_revision_sha1(rev.precursor)
- if updated_previous_revision:
- # we don't expect the hashes to match, because
- # we had to modify the previous revision_history entry.
+
+ if update:
+ branch.lock_write()
+ else:
+ branch.lock_read()
+
+ try:
+
+ out = sys.stdout
+
+ pb = ProgressBar(show_spinner=True)
+ last_ptr = None
+ checked_revs = {}
+
+ missing_inventory_sha_cnt = 0
+
+ history = branch.revision_history()
+ revno = 0
+ revcount = len(history)
+
+ checked_texts = {}
+
+ updated_revisions = []
+
+ # Set to True in the case that the previous revision entry
+ # was updated, since this will affect future revision entries
+ updated_previous_revision = False
+
+ for rid in history:
+ revno += 1
+ pb.update('checking revision', revno, revcount)
+ mutter(' revision {%s}' % rid)
+ rev = branch.get_revision(rid)
+ if rev.revision_id != rid:
+ raise BzrCheckError('wrong internal revision id in revision {%s}' % rid)
+ if rev.precursor != last_ptr:
+ raise BzrCheckError('mismatched precursor in revision {%s}' % rid)
+ last_ptr = rid
+ if rid in checked_revs:
+ raise BzrCheckError('repeated revision {%s}' % rid)
+ checked_revs[rid] = True
+
+ ## TODO: Check all the required fields are present on the revision.
+
+ updated = False
+ if rev.inventory_sha1:
+ #mutter(' checking inventory hash {%s}' % rev.inventory_sha1)
+ inv_sha1 = branch.get_inventory_sha1(rev.inventory_id)
+ if inv_sha1 != rev.inventory_sha1:
+ raise BzrCheckError('Inventory sha1 hash doesn\'t match'
+ ' value in revision {%s}' % rid)
+ elif update:
+ inv_sha1 = branch.get_inventory_sha1(rev.inventory_id)
+ rev.inventory_sha1 = inv_sha1
+ updated = True
+ else:
+ missing_inventory_sha_cnt += 1
+ mutter("no inventory_sha1 on revision {%s}" % rid)
+
+ if rev.precursor:
+ if rev.precursor_sha1:
+ precursor_sha1 = branch.get_revision_sha1(rev.precursor)
+ if updated_previous_revision:
+ # we don't expect the hashes to match, because
+ # we had to modify the previous revision_history entry.
+ rev.precursor_sha1 = precursor_sha1
+ updated = True
+ else:
+ #mutter(' checking precursor hash {%s}' % rev.precursor_sha1)
+ if rev.precursor_sha1 != precursor_sha1:
+ raise BzrCheckError('Precursor sha1 hash doesn\'t match'
+ ' value in revision {%s}' % rid)
+ elif update:
+ precursor_sha1 = branch.get_revision_sha1(rev.precursor)
rev.precursor_sha1 = precursor_sha1
updated = True
- else:
- #mutter(' checking precursor hash {%s}' % rev.precursor_sha1)
- if rev.precursor_sha1 != precursor_sha1:
- raise BzrCheckError('Precursor sha1 hash doesn\'t match'
- ' value in revision {%s}' % rid)
- elif update:
- precursor_sha1 = branch.get_revision_sha1(rev.precursor)
- rev.precursor_sha1 = precursor_sha1
- updated = True
-
- if updated:
- updated_previous_revision = True
- # We had to update this revision entries hashes
- # Now we need to write out a new value
- # This is a little bit invasive, since we are *rewriting* a
- # revision entry. I'm not supremely happy about it, but
- # there should be *some* way of making old entries have
- # the full meta information.
- import tempfile, os, errno
- rev_tmp = tempfile.TemporaryFile()
- rev.write_xml(rev_tmp)
- rev_tmp.seek(0)
-
- tmpfd, tmp_path = tempfile.mkstemp(prefix=rid, suffix='.gz',
- dir=branch.controlfilename('revision-store'))
- os.close(tmpfd)
- def special_rename(p1, p2):
- if sys.platform == 'win32':
- try:
- os.remove(p2)
- except OSError, e:
- if e.errno != e.ENOENT:
- raise
- os.rename(p1, p2)
-
- try:
- # TODO: We may need to handle the case where the old revision
- # entry was not compressed (and thus did not end with .gz)
-
- # Remove the old revision entry out of the way
- rev_path = branch.controlfilename(['revision-store', rid+'.gz'])
- special_rename(rev_path, tmp_path)
- branch.revision_store.add(rev_tmp, rid) # Add the new one
- os.remove(tmp_path) # Remove the old name
- mutter(' Updated revision entry {%s}' % rid)
- except:
- # On any exception, restore the old entry
- special_rename(tmp_path, rev_path)
- raise
- rev_tmp.close()
- updated_revisions.append(rid)
- else:
- updated_previous_revision = False
-
- inv = branch.get_inventory(rev.inventory_id)
- seen_ids = {}
- seen_names = {}
-
- ## p('revision %d/%d file ids' % (revno, revcount))
- for file_id in inv:
- if file_id in seen_ids:
- raise BzrCheckError('duplicated file_id {%s} '
- 'in inventory for revision {%s}'
- % (file_id, rid))
- seen_ids[file_id] = True
-
- i = 0
- len_inv = len(inv)
- for file_id in inv:
- i += 1
- if i & 31 == 0:
- pb.tick()
-
- ie = inv[file_id]
-
- if ie.parent_id != None:
- if ie.parent_id not in seen_ids:
- raise BzrCheckError('missing parent {%s} in inventory for revision {%s}'
- % (ie.parent_id, rid))
-
- if ie.kind == 'file':
- if ie.text_id in checked_texts:
- fp = checked_texts[ie.text_id]
- else:
- if not ie.text_id in branch.text_store:
- raise BzrCheckError('text {%s} not in text_store' % ie.text_id)
-
- tf = branch.text_store[ie.text_id]
- fp = fingerprint_file(tf)
- checked_texts[ie.text_id] = fp
-
- if ie.text_size != fp['size']:
- raise BzrCheckError('text {%s} wrong size' % ie.text_id)
- if ie.text_sha1 != fp['sha1']:
- raise BzrCheckError('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:
- raise BzrCheckError('directory {%s} has text in revision {%s}'
- % (file_id, rid))
-
- pb.tick()
- for path, ie in inv.iter_entries():
- if path in seen_names:
- raise BzrCheckError('duplicated path %r '
- 'in inventory for revision {%s}'
- % (path, revid))
+
+ if updated:
+ updated_previous_revision = True
+ # We had to update this revision entries hashes
+ # Now we need to write out a new value
+ # This is a little bit invasive, since we are *rewriting* a
+ # revision entry. I'm not supremely happy about it, but
+ # there should be *some* way of making old entries have
+ # the full meta information.
+ import tempfile, os, errno
+ rev_tmp = tempfile.TemporaryFile()
+ rev.write_xml(rev_tmp)
+ rev_tmp.seek(0)
+
+ tmpfd, tmp_path = tempfile.mkstemp(prefix=rid, suffix='.gz',
+ dir=branch.controlfilename('revision-store'))
+ os.close(tmpfd)
+ def special_rename(p1, p2):
+ if sys.platform == 'win32':
+ try:
+ os.remove(p2)
+ except OSError, e:
+ if e.errno != e.ENOENT:
+ raise
+ os.rename(p1, p2)
+
+ try:
+ # TODO: We may need to handle the case where the old revision
+ # entry was not compressed (and thus did not end with .gz)
+
+ # Remove the old revision entry out of the way
+ rev_path = branch.controlfilename(['revision-store', rid+'.gz'])
+ special_rename(rev_path, tmp_path)
+ branch.revision_store.add(rev_tmp, rid) # Add the new one
+ os.remove(tmp_path) # Remove the old name
+ mutter(' Updated revision entry {%s}' % rid)
+ except:
+ # On any exception, restore the old entry
+ special_rename(tmp_path, rev_path)
+ raise
+ rev_tmp.close()
+ updated_revisions.append(rid)
+ else:
+ updated_previous_revision = False
+
+ inv = branch.get_inventory(rev.inventory_id)
+ seen_ids = {}
+ seen_names = {}
+
+ ## p('revision %d/%d file ids' % (revno, revcount))
+ for file_id in inv:
+ if file_id in seen_ids:
+ raise BzrCheckError('duplicated file_id {%s} '
+ 'in inventory for revision {%s}'
+ % (file_id, rid))
+ seen_ids[file_id] = True
+
+ i = 0
+ len_inv = len(inv)
+ for file_id in inv:
+ i += 1
+ if i & 31 == 0:
+ pb.tick()
+
+ ie = inv[file_id]
+
+ if ie.parent_id != None:
+ if ie.parent_id not in seen_ids:
+ raise BzrCheckError('missing parent {%s} in inventory for revision {%s}'
+ % (ie.parent_id, rid))
+
+ if ie.kind == 'file':
+ if ie.text_id in checked_texts:
+ fp = checked_texts[ie.text_id]
+ else:
+ if not ie.text_id in branch.text_store:
+ raise BzrCheckError('text {%s} not in text_store' % ie.text_id)
+
+ tf = branch.text_store[ie.text_id]
+ fp = fingerprint_file(tf)
+ checked_texts[ie.text_id] = fp
+
+ if ie.text_size != fp['size']:
+ raise BzrCheckError('text {%s} wrong size' % ie.text_id)
+ if ie.text_sha1 != fp['sha1']:
+ raise BzrCheckError('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:
+ raise BzrCheckError('directory {%s} has text in revision {%s}'
+ % (file_id, rid))
+
+ pb.tick()
+ for path, ie in inv.iter_entries():
+ if path in seen_names:
+ raise BzrCheckError('duplicated path %r '
+ 'in inventory for revision {%s}'
+ % (path, revid))
seen_names[path] = True
+ finally:
+ branch.unlock()
pb.clear()
More information about the Pkg-bazaar-commits
mailing list