Rev 3806: Change the code to check before adding the new lines to the store. in http://bzr.arbash-meinel.com/branches/bzr/brisbane/look_before_you_leap
John Arbash Meinel
john at arbash-meinel.com
Tue Dec 23 17:41:06 GMT 2008
At http://bzr.arbash-meinel.com/branches/bzr/brisbane/look_before_you_leap
------------------------------------------------------------
revno: 3806
revision-id: john at arbash-meinel.com-20081223174050-5s6el1nhg8mx63r3
parent: john at arbash-meinel.com-20081219230732-ri1i1tujtrh2d3sl
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: look_before_you_leap
timestamp: Tue 2008-12-23 11:40:50 -0600
message:
Change the code to check before adding the new lines to the store.
-------------- next part --------------
=== modified file 'bzrlib/chk_map.py'
--- a/bzrlib/chk_map.py 2008-12-12 21:50:41 +0000
+++ b/bzrlib/chk_map.py 2008-12-23 17:40:50 +0000
@@ -43,6 +43,7 @@
lazy_import.lazy_import(globals(), """
from bzrlib import versionedfile
""")
+from bzrlib import osutils
from bzrlib.lru_cache import LRUCache
# approx 2MB
@@ -563,8 +564,12 @@
lines.append("%d\n" % self._len)
for key, value in sorted(self._items.items()):
lines.append("%s\x00%s\n" % ('\x00'.join(key), value))
- sha1, _, _ = store.add_lines((None,), (), lines)
- self._key = ("sha1:" + sha1,)
+ sha1 = osutils.sha_strings(lines)
+ key = ('sha1:' + sha1,)
+ if not store.has_key(key):
+ # We know the key doesn't exist, because we just checked
+ store.add_lines(key, (), lines, random_id=True)
+ self._key = key
_page_cache.add(self._key, ''.join(lines))
return [self._key]
@@ -838,8 +843,12 @@
else:
key = node._key[0]
lines.append("%s\x00%s\n" % (prefix, key))
- sha1, _, _ = store.add_lines((None,), (), lines)
- self._key = ("sha1:" + sha1,)
+ sha1 = osutils.sha_strings(lines)
+ key = ('sha1:' + sha1,)
+ if not store.has_key(key):
+ # We know the key doesn't exist, because we just checked
+ store.add_lines(key, (), lines, random_id=True)
+ self._key = key
_page_cache.add(self._key, ''.join(lines))
yield self._key
More information about the bazaar-commits
mailing list