Rev 2784: Knit support for commit refactoring. in http://people.ubuntu.com/~robertc/baz2.0/commit

Robert Collins robertc at robertcollins.net
Wed Sep 5 04:53:36 BST 2007


At http://people.ubuntu.com/~robertc/baz2.0/commit

------------------------------------------------------------
revno: 2784
revision-id: robertc at robertcollins.net-20070905035316-1gp1s0fx6gmvbnqu
parent: robertc at robertcollins.net-20070904100858-971b6sssddwfmwrw
parent: robertc at robertcollins.net-20070905035159-6j1mh2gnrhpez5jp
committer: Robert Collins <robertc at robertcollins.net>
branch nick: commit
timestamp: Wed 2007-09-05 13:53:16 +1000
message:
  Knit support for commit refactoring.
modified:
  bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
  bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
  bzrlib/reconcile.py            reweave_inventory.py-20051108164726-1e5e0934febac06e
  bzrlib/tests/test_versionedfile.py test_versionedfile.py-20060222045249-db45c9ed14a1c2e5
  bzrlib/versionedfile.py        versionedfile.py-20060222045106-5039c71ee3b65490
  bzrlib/weave.py                knit.py-20050627021749-759c29984154256b
    ------------------------------------------------------------
    revno: 2776.2.19
    revision-id: robertc at robertcollins.net-20070905035159-6j1mh2gnrhpez5jp
    parent: pqm at pqm.ubuntu.com-20070904035759-iv4xl6d7ez69txba
    parent: robertc at robertcollins.net-20070816083953-sbfb70vw6tmh3vak
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: knits
    timestamp: Wed 2007-09-05 13:51:59 +1000
    message:
      Allow knits to be instructed not to add a text based on a sha, for commit.
    modified:
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
      bzrlib/reconcile.py            reweave_inventory.py-20051108164726-1e5e0934febac06e
      bzrlib/tests/test_versionedfile.py test_versionedfile.py-20060222045249-db45c9ed14a1c2e5
      bzrlib/versionedfile.py        versionedfile.py-20060222045106-5039c71ee3b65490
      bzrlib/weave.py                knit.py-20050627021749-759c29984154256b
    ------------------------------------------------------------
    revno: 2698.2.5
    revision-id: robertc at robertcollins.net-20070816083953-sbfb70vw6tmh3vak
    parent: robertc at robertcollins.net-20070816081927-rhroje8susrd3a40
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: knits
    timestamp: Thu 2007-08-16 18:39:53 +1000
    message:
      Decouple parsing and iterating the lines in knit records from getting the data, making it suitable for use in pack repositories.
    modified:
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
    ------------------------------------------------------------
    revno: 2698.2.4
    revision-id: robertc at robertcollins.net-20070816081927-rhroje8susrd3a40
    parent: robertc at robertcollins.net-20070816081549-dpowek5gwvox1x56
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: knits
    timestamp: Thu 2007-08-16 18:19:27 +1000
    message:
      Remove full history scan during iter_lines_added_or_present in KnitVersionedFile.
    modified:
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
    ------------------------------------------------------------
    revno: 2698.2.3
    revision-id: robertc at robertcollins.net-20070816081549-dpowek5gwvox1x56
    parent: robertc at robertcollins.net-20070816081414-ps82io1cs4cij6vz
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: knits
    timestamp: Thu 2007-08-16 18:15:49 +1000
    message:
      Remove an unneeded pre-check in KnitVersionedFile.iter_lines_added_or_present_in_version.
    modified:
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
    ------------------------------------------------------------
    revno: 2698.2.2
    revision-id: robertc at robertcollins.net-20070816081414-ps82io1cs4cij6vz
    parent: robertc at robertcollins.net-20070816080814-49b7t5gghdrhcx4d
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: knits
    timestamp: Thu 2007-08-16 18:14:14 +1000
    message:
      Use the low-level sorting facility in KnitVersionedFile.iter_records
    modified:
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
    ------------------------------------------------------------
    revno: 2698.2.1
    revision-id: robertc at robertcollins.net-20070816080814-49b7t5gghdrhcx4d
    parent: pqm at pqm.ubuntu.com-20070814221506-6rw0b0oolfdeqrdw
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: knits
    timestamp: Thu 2007-08-16 18:08:14 +1000
    message:
      Add new get_raw_records_unsorted method on knit access, to allow low level sorting and optimisation when the upper layer does not need results in a particular order.
    modified:
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
      bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2007-09-03 08:39:17 +0000
+++ b/bzrlib/errors.py	2007-09-05 03:51:59 +0000
@@ -1854,6 +1854,12 @@
     _fmt = "Diff3 is not installed on this machine."
 
 
+class ExistingContent(BzrError):
+    """Added in bzrlib 0.92, used by VersionedFile.add_lines."""
+
+    _fmt = "The content being inserted is already present."
+
+
 class ExistingLimbo(BzrError):
 
     _fmt = """This tree contains left-over files from a failed operation.

=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2007-09-03 21:19:07 +0000
+++ b/bzrlib/knit.py	2007-09-05 03:51:59 +0000
@@ -855,18 +855,20 @@
         """Check that all specified versions are present."""
         self._index.check_versions_present(version_ids)
 
-    def _add_lines_with_ghosts(self, version_id, parents, lines, parent_texts):
+    def _add_lines_with_ghosts(self, version_id, parents, lines, parent_texts,
+        nostore_sha):
         """See VersionedFile.add_lines_with_ghosts()."""
         self._check_add(version_id, lines)
-        return self._add(version_id, lines[:], parents, self.delta, parent_texts)
+        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=None):
+                   left_matching_blocks, nostore_sha):
         """See VersionedFile.add_lines."""
         self._check_add(version_id, lines)
         self._check_versions_present(parents)
         return self._add(version_id, lines[:], parents, self.delta,
-                         parent_texts, left_matching_blocks)
+            parent_texts, left_matching_blocks, nostore_sha)
 
     def _check_add(self, version_id, lines):
         """check that version_id and lines are safe to add."""
@@ -881,7 +883,7 @@
         self._check_lines_are_lines(lines)
 
     def _add(self, version_id, lines, parents, delta, parent_texts,
-             left_matching_blocks=None):
+             left_matching_blocks, nostore_sha):
         """Add a set of lines on top of version specified by parents.
 
         If delta is true, compress the text as a line-delta against
@@ -915,6 +917,8 @@
             delta = False
 
         digest = sha_strings(lines)
+        if nostore_sha == digest:
+            raise errors.ExistingContent
         text_length = sum(map(len, lines))
         options = []
         if lines:

=== modified file 'bzrlib/reconcile.py'
--- a/bzrlib/reconcile.py	2006-10-05 05:37:25 +0000
+++ b/bzrlib/reconcile.py	2007-09-05 03:51:59 +0000
@@ -170,8 +170,8 @@
                 # This is done to avoid a revision_count * time-to-write additional overhead on 
                 # reconcile.
                 new_inventory_vf._check_write_ok()
-                Weave._add_lines(new_inventory_vf, rev_id, parents, self.inventory.get_lines(rev_id),
-                                 None)
+                Weave._add_lines(new_inventory_vf, rev_id, parents,
+                    self.inventory.get_lines(rev_id), None, None, None)
             else:
                 new_inventory_vf.add_lines(rev_id, parents, self.inventory.get_lines(rev_id))
 

=== modified file 'bzrlib/tests/test_versionedfile.py'
--- a/bzrlib/tests/test_versionedfile.py	2007-09-03 21:19:07 +0000
+++ b/bzrlib/tests/test_versionedfile.py	2007-09-05 03:51:59 +0000
@@ -167,6 +167,51 @@
         self.assertRaises(errors.ReservedId,
             vf.add_delta, 'a:', [], None, 'sha1', False, ((0, 0, 0, []),))
 
+    def test_add_lines_nostoresha(self):
+        """When nostore_sha is supplied using old content raises."""
+        vf = self.get_file()
+        empty_text = ('a', [])
+        sample_text_nl = ('b', ["foo\n", "bar\n"])
+        sample_text_no_nl = ('c', ["foo\n", "bar"])
+        shas = []
+        for version, lines in (empty_text, sample_text_nl, sample_text_no_nl):
+            sha, _, _ = vf.add_lines(version, [], lines)
+            shas.append(sha)
+        # we now have a copy of all the lines in the vf.
+        for sha, (version, lines) in zip(
+            shas, (empty_text, sample_text_nl, sample_text_no_nl)):
+            self.assertRaises(errors.ExistingContent,
+                vf.add_lines, version + "2", [], lines,
+                nostore_sha=sha)
+            # and no new version should have been added.
+            self.assertRaises(errors.RevisionNotPresent, vf.get_lines,
+                version + "2")
+
+    def test_add_lines_nostoresha(self):
+        """When nostore_sha is supplied using old content raises."""
+        vf = self.get_file()
+        empty_text = ('a', [])
+        sample_text_nl = ('b', ["foo\n", "bar\n"])
+        sample_text_no_nl = ('c', ["foo\n", "bar"])
+        shas = []
+        for version, lines in (empty_text, sample_text_nl, sample_text_no_nl):
+            sha, _, _ = vf.add_lines(version, [], lines)
+            shas.append(sha)
+        # we now have a copy of all the lines in the vf.
+        # is the test applicable to this vf implementation?
+        try:
+            vf.add_lines_with_ghosts('d', [], [])
+        except NotImplementedError:
+            raise TestSkipped("add_lines_with_ghosts is optional")
+        for sha, (version, lines) in zip(
+            shas, (empty_text, sample_text_nl, sample_text_no_nl)):
+            self.assertRaises(errors.ExistingContent,
+                vf.add_lines_with_ghosts, version + "2", [], lines,
+                nostore_sha=sha)
+            # and no new version should have been added.
+            self.assertRaises(errors.RevisionNotPresent, vf.get_lines,
+                version + "2")
+
     def test_add_lines_return_value(self):
         # add_lines should return the sha1 and the text size.
         vf = self.get_file()

=== modified file 'bzrlib/versionedfile.py'
--- a/bzrlib/versionedfile.py	2007-09-03 20:23:05 +0000
+++ b/bzrlib/versionedfile.py	2007-09-05 03:51:59 +0000
@@ -114,7 +114,7 @@
         self.add_lines(version_id, parents, new_full)
 
     def add_lines(self, version_id, parents, lines, parent_texts=None,
-                  left_matching_blocks=None):
+                  left_matching_blocks=None, nostore_sha=None):
         """Add a single text on top of the versioned file.
 
         Must raise RevisionAlreadyPresent if the new version is
@@ -130,6 +130,8 @@
         :param left_matching_blocks: a hint about which areas are common
             between the text and its left-hand-parent.  The format is
             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.
         :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.
@@ -138,26 +140,27 @@
         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)
+            left_matching_blocks, nostore_sha)
 
     def _add_lines(self, version_id, parents, lines, parent_texts,
-                   left_matching_blocks):
+        left_matching_blocks, nostore_sha):
         """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):
+                              parent_texts=None, nostore_sha=None):
         """Add lines to the versioned file, allowing ghosts to be present.
         
-        This takes the same parameters as add_lines.
+        This takes the same parameters as add_lines and returns the same.
         """
         version_id = osutils.safe_revision_id(version_id)
         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)
+            parent_texts, nostore_sha)
 
-    def _add_lines_with_ghosts(self, version_id, parents, lines, parent_texts):
+    def _add_lines_with_ghosts(self, version_id, parents, lines, parent_texts,
+        nostore_sha):
         """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-03 02:58:58 +0000
+++ b/bzrlib/weave.py	2007-09-05 03:51:59 +0000
@@ -417,12 +417,13 @@
         return idx
 
     def _add_lines(self, version_id, parents, lines, parent_texts,
-                   left_matching_blocks=None):
+       left_matching_blocks, nostore_sha):
         """See VersionedFile.add_lines."""
-        idx = self._add(version_id, lines, map(self._lookup, parents))
+        idx = self._add(version_id, lines, map(self._lookup, parents),
+            nostore_sha=nostore_sha)
         return sha_strings(lines), sum(map(len, lines)), idx
 
-    def _add(self, version_id, lines, parents, sha1=None):
+    def _add(self, version_id, lines, parents, sha1=None, nostore_sha=None):
         """Add a single text on top of the weave.
   
         Returns the index number of the newly added version.
@@ -436,13 +437,16 @@
             
         lines
             Sequence of lines to be added in the new version.
+
+        :param nostore_sha: See VersionedFile.add_lines.
         """
-
         assert isinstance(version_id, basestring)
         self._check_lines_not_unicode(lines)
         self._check_lines_are_lines(lines)
         if not sha1:
             sha1 = sha_strings(lines)
+        if sha1 == nostore_sha:
+            raise errors.ExistingContent
         if version_id in self._name_map:
             return self._check_repeated_add(version_id, parents, lines, sha1)
 
@@ -1022,11 +1026,11 @@
             self._save()
 
     def _add_lines(self, version_id, parents, lines, parent_texts,
-        left_matching_blocks=None):
+        left_matching_blocks, nostore_sha):
         """Add a version and save the weave."""
         self.check_not_reserved_id(version_id)
         result = super(WeaveFile, self)._add_lines(version_id, parents, lines,
-                                                   parent_texts)
+            parent_texts, left_matching_blocks, nostore_sha)
         self._save()
         return result
 



More information about the bazaar-commits mailing list