Rev 2809: Don't check for existing versions when adding texts with random revision ids. in http://people.ubuntu.com/~robertc/baz2.0/knits
Robert Collins
robertc at robertcollins.net
Mon Sep 10 04:53:14 BST 2007
At http://people.ubuntu.com/~robertc/baz2.0/knits
------------------------------------------------------------
revno: 2809
revision-id: robertc at robertcollins.net-20070910035304-iwf9nmqoxeshjaki
parent: robertc at robertcollins.net-20070910033719-nqsmg72617f0tvyo
committer: Robert Collins <robertc at robertcollins.net>
branch nick: knits
timestamp: Mon 2007-09-10 13:53:04 +1000
message:
Don't check for existing versions when adding texts with random revision ids.
modified:
bzrlib/knit.py knit.py-20051212171256-f056ac8f0fbe1bd9
bzrlib/repository.py rev_storage.py-20051111201905-119e9401e46257e3
bzrlib/versionedfile.py versionedfile.py-20060222045106-5039c71ee3b65490
bzrlib/weave.py knit.py-20050627021749-759c29984154256b
=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py 2007-09-10 03:37:19 +0000
+++ b/bzrlib/knit.py 2007-09-10 03:53:04 +0000
@@ -831,32 +831,30 @@
self._index.check_versions_present(version_ids)
def _add_lines_with_ghosts(self, version_id, parents, lines, parent_texts,
- nostore_sha):
+ nostore_sha, random_id):
"""See VersionedFile.add_lines_with_ghosts()."""
- self._check_add(version_id, lines)
+ self._check_add(version_id, lines, random_id)
return self._add(version_id, lines, parents, self.delta,
parent_texts, None, nostore_sha)
def _add_lines(self, version_id, parents, lines, parent_texts,
- left_matching_blocks, nostore_sha):
+ left_matching_blocks, nostore_sha, random_id):
"""See VersionedFile.add_lines."""
- self._check_add(version_id, lines)
+ self._check_add(version_id, lines, random_id)
self._check_versions_present(parents)
return self._add(version_id, lines[:], parents, self.delta,
parent_texts, left_matching_blocks, nostore_sha)
- def _check_add(self, version_id, lines):
+ def _check_add(self, version_id, lines, random_id):
"""check that version_id and lines are safe to add."""
if contains_whitespace(version_id):
raise InvalidRevisionId(version_id, self.filename)
self.check_not_reserved_id(version_id)
- # Technically this is a case of Look Before You Leap, but:
- # - for knits this saves wasted space in the error case
- # - for packs this avoids dead space in the pack
- # - it also avoids undetected poisoning attacks.
- # - its 1.5% of total commit time, so ignore it unless it becomes a
- # larger percentage.
- if self.has_version(version_id):
+ # Technically this could be avoided if we are happy to allow duplicate
+ # id insertion when other things than bzr core insert texts, but it
+ # seems useful for folk using the knit api directly to have some safety
+ # blanket that we can disable.
+ if not random_id and self.has_version(version_id):
raise RevisionAlreadyPresent(version_id, self.filename)
def _add(self, version_id, lines, parents, delta, parent_texts,
=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py 2007-09-10 01:27:10 +0000
+++ b/bzrlib/repository.py 2007-09-10 03:53:04 +0000
@@ -2299,7 +2299,8 @@
versionedfile = self.repository.weave_store.get_weave_or_empty(
file_id, self.repository.get_transaction())
result = versionedfile.add_lines(
- self._new_revision_id, parents, new_lines)[0:2]
+ self._new_revision_id, parents, new_lines,
+ random_id=self.random_revid)[0:2]
versionedfile.clear_cache()
return result
=== modified file 'bzrlib/versionedfile.py'
--- a/bzrlib/versionedfile.py 2007-09-10 03:37:19 +0000
+++ b/bzrlib/versionedfile.py 2007-09-10 03:53:04 +0000
@@ -78,7 +78,7 @@
raise NotImplementedError(self.has_version)
def add_lines(self, version_id, parents, lines, parent_texts=None,
- left_matching_blocks=None, nostore_sha=None):
+ left_matching_blocks=None, nostore_sha=None, random_id=False):
"""Add a single text on top of the versioned file.
Must raise RevisionAlreadyPresent if the new version is
@@ -104,6 +104,12 @@
the SequenceMatcher.get_matching_blocks format.
:param nostore_sha: Raise ExistingContent and do not add the lines to
the versioned file if the digest of the lines matches this.
+ :param random_id: If True a random id has been selected rather than
+ an id determined by some deterministic process such as a converter
+ from a foreign VCS. When True the backend may choose not to check
+ for uniqueness of the resulting key within the versioned file, so
+ this should only be done when the result is expected to be unique
+ anyway.
:return: The text sha1, the number of bytes in the text, and an opaque
representation of the inserted version which can be provided
back to future add_lines calls in the parent_texts dictionary.
@@ -112,15 +118,15 @@
parents = [osutils.safe_revision_id(v) for v in parents]
self._check_write_ok()
return self._add_lines(version_id, parents, lines, parent_texts,
- left_matching_blocks, nostore_sha)
+ left_matching_blocks, nostore_sha, random_id)
def _add_lines(self, version_id, parents, lines, parent_texts,
- left_matching_blocks, nostore_sha):
+ left_matching_blocks, nostore_sha, random_id):
"""Helper to do the class specific add_lines."""
raise NotImplementedError(self.add_lines)
def add_lines_with_ghosts(self, version_id, parents, lines,
- parent_texts=None, nostore_sha=None):
+ parent_texts=None, nostore_sha=None, random_id=False):
"""Add lines to the versioned file, allowing ghosts to be present.
This takes the same parameters as add_lines and returns the same.
@@ -129,10 +135,10 @@
parents = [osutils.safe_revision_id(v) for v in parents]
self._check_write_ok()
return self._add_lines_with_ghosts(version_id, parents, lines,
- parent_texts, nostore_sha)
+ parent_texts, nostore_sha, random_id)
def _add_lines_with_ghosts(self, version_id, parents, lines, parent_texts,
- nostore_sha):
+ nostore_sha, random_id):
"""Helper to do class specific add_lines_with_ghosts."""
raise NotImplementedError(self.add_lines_with_ghosts)
=== modified file 'bzrlib/weave.py'
--- a/bzrlib/weave.py 2007-09-05 22:25:01 +0000
+++ b/bzrlib/weave.py 2007-09-10 03:53:04 +0000
@@ -870,7 +870,7 @@
self._save()
def _add_lines(self, version_id, parents, lines, parent_texts,
- left_matching_blocks, nostore_sha):
+ left_matching_blocks, nostore_sha, random_id):
"""Add a version and save the weave."""
self.check_not_reserved_id(version_id)
result = super(WeaveFile, self)._add_lines(version_id, parents, lines,
More information about the bazaar-commits
mailing list