Rev 2760: Merge more commit refactoring. in http://people.ubuntu.com/~robertc/baz2.0/repository

Robert Collins robertc at robertcollins.net
Wed Sep 12 05:38:24 BST 2007


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

------------------------------------------------------------
revno: 2760
revision-id: robertc at robertcollins.net-20070912043809-98gc15f2rk87k0nf
parent: robertc at robertcollins.net-20070911042300-hd063aao8izk1hz8
parent: robertc at robertcollins.net-20070911090940-2lbw0h6ev8z2zp6w
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Wed 2007-09-12 14:38:09 +1000
message:
  Merge more commit refactoring.
modified:
  bzrlib/commit.py               commit.py-20050511101309-79ec1a0168e0e825
  bzrlib/inventory.py            inventory.py-20050309040759-6648b84ca2005b37
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
  bzrlib/tests/workingtree_implementations/test_inv.py test_inv.py-20070311221604-ighlq8tbn5xq0kuo-1
    ------------------------------------------------------------
    revno: 2592.1.25.2.7.1.28.1.6.1.3.1.9.2.1.3.74.1.44
    revision-id: robertc at robertcollins.net-20070911090940-2lbw0h6ev8z2zp6w
    parent: robertc at robertcollins.net-20070909224707-s1vrl45nvle0k51m
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: commit
    timestamp: Tue 2007-09-11 19:09:40 +1000
    message:
      Fixup various commit test failures falling out from the other commit changes.
    modified:
      bzrlib/commit.py               commit.py-20050511101309-79ec1a0168e0e825
      bzrlib/inventory.py            inventory.py-20050309040759-6648b84ca2005b37
      bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
      bzrlib/tests/workingtree_implementations/test_inv.py test_inv.py-20070311221604-ighlq8tbn5xq0kuo-1
=== modified file 'bzrlib/commit.py'
--- a/bzrlib/commit.py	2007-09-09 23:01:47 +0000
+++ b/bzrlib/commit.py	2007-09-12 04:38:09 +0000
@@ -659,13 +659,17 @@
         if specific_files:
             for path, new_ie in self.basis_inv.iter_entries():
                 if new_ie.file_id in self.builder.new_inventory:
+                    # already added - skip.
                     continue
                 if is_inside_any(specific_files, path):
+                    # was inside the selected path, if not present it has been
+                    # deleted so skip.
                     continue
+                # not in final inv yet, was not in the selected files, so is an
+                # entry to be preserved unaltered.
                 ie = new_ie.copy()
-                ie.revision = None
                 self.builder.record_entry_contents(ie, self.parent_invs, path,
-                                                   self.basis_tree)
+                                                   self.basis_tree, None)
 
         # Report what was deleted. We could skip this when no deletes are
         # detected to gain a performance win, but it arguably serves as a
@@ -718,12 +722,21 @@
                 # enforce repository nested tree policy.
                 if (not self.work_tree.supports_tree_reference() or
                     # repository does not support it either.
-                    not self.branch.repository._format.supports_tree_reference()):
+                    not self.branch.repository._format.supports_tree_reference):
                     content_summary = ('directory',) + content_summary[1:]
             kind = content_summary[0]
             # TODO: specific_files filtering before nested tree processing
-            if kind == 'tree-reference' and self.builder.recursive == 'down':
-                self._commit_nested_tree(file_id, path)
+            # TODO: push this down into record_entry so the new ie can be set
+            # directly.
+            if kind == 'tree-reference':
+                if self.builder.recursive == 'down':
+                    nested_revision_id = self._commit_nested_tree(
+                        file_id, path)
+                    content_summary = content_summary[:3] + (
+                        nested_revision_id,)
+                else:
+                    content_summary = content_summary[:3] + (
+                        self.work_tree.get_reference_revision(file_id),)
 
             # Record an entry for this item
             # Note: I don't particularly want to have the existing_ie
@@ -750,7 +763,7 @@
             sub_tree.branch.repository = \
                 self.work_tree.branch.repository
         try:
-            sub_tree.commit(message=None, revprops=self.revprops,
+            return sub_tree.commit(message=None, revprops=self.revprops,
                 recursive=self.builder.recursive,
                 message_callback=self.message_callback,
                 timestamp=self.timestamp, timezone=self.timezone,
@@ -759,7 +772,7 @@
                 strict=self.strict, verbose=self.verbose,
                 local=self.local, reporter=self.reporter)
         except errors.PointlessCommit:
-            pass
+            return self.work_tree.get_reference_revision(file_id)
 
     def _record_entry(self, path, file_id, specific_files, kind, name,
         parent_id, definitely_changed, existing_ie, content_summary):

=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py	2007-09-05 05:51:34 +0000
+++ b/bzrlib/inventory.py	2007-09-11 09:09:40 +0000
@@ -432,32 +432,6 @@
                    self.parent_id,
                    self.revision))
 
-    def snapshot(self, revision, path, previous_entries,
-        work_tree, commit_builder, store_if_unchanged):
-        """Make a snapshot of this entry which may or may not have changed.
-        
-        This means that all its fields are populated, that it has its
-        text stored in the text store or weave.
-
-        :return: True if anything was recorded
-        """
-        # cannot be unchanged unless there is only one parent file rev.
-        # self._read_tree_state(path, work_tree)
-        if len(previous_entries) == 1:
-            parent_ie = previous_entries.values()[0]
-            if self._unchanged(parent_ie):
-                self.revision = parent_ie.revision
-                return False
-        self.revision = revision
-        return self._snapshot_text(previous_entries, work_tree, commit_builder)
-
-    def _snapshot_text(self, file_parents, work_tree, commit_builder): 
-        """Record the 'text' of this entry, whatever form that takes.
-
-        :return: True if anything was recorded
-        """
-        raise NotImplementedError(self._snapshot_text)
-
     def __eq__(self, other):
         if not isinstance(other, InventoryEntry):
             return NotImplemented

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2007-09-11 04:23:00 +0000
+++ b/bzrlib/repository.py	2007-09-12 04:38:09 +0000
@@ -78,7 +78,7 @@
 
     _file_ids_altered_regex = lazy_regex.lazy_compile(
         r'file_id="(?P<file_id>[^"]+)"'
-        r'.*revision="(?P<revision_id>[^"]+)"'
+        r'.* revision="(?P<revision_id>[^"]+)"'
         )
 
     def abort_write_group(self):
@@ -2391,7 +2391,7 @@
                 ' record_entry_contents, as of bzr 0.10.',
                  DeprecationWarning, stacklevel=2)
             self.record_entry_contents(tree.inventory.root.copy(), parent_invs,
-                                       '', tree)
+                                       '', tree, tree.path_content_summary(''))
         else:
             # In this revision format, root entries have no knit or weave When
             # serializing out to disk and back in root.revision is always
@@ -2411,11 +2411,17 @@
         :param tree: The tree which contains this entry and should be used to 
             obtain content.
         :param content_summary: Summary data from the tree about the paths
-            content - stat, length, exec, sha/link target.
+            content - stat, length, exec, sha/link target. This is only
+            accessed when the entry has a revision of None - that is when it is
+            a candidate to commit.
         """
         if self.new_inventory.root is None:
             self._check_root(ie, parent_invs, tree)
-        kind = content_summary[0]
+        if ie.revision is None:
+            kind = content_summary[0]
+        else:
+            # ie is carried over from a prior commit
+            kind = ie.kind
         # XXX: repository specific check for nested tree support goes here - if
         # the repo doesn't want nested trees we skip it ?
         if (kind == 'tree-reference' and
@@ -2512,7 +2518,8 @@
                 return
         elif kind == 'directory':
             if not store:
-                # all data is meta here, so carry over:
+                # all data is meta here, nothing specific to directory, so
+                # carry over:
                 ie.revision = parent_entry.revision
                 return
             lines = []
@@ -2525,6 +2532,7 @@
                 if current_link_target != parent_entry.symlink_target:
                     store = True
             if not store:
+                # unchanged, carry over.
                 ie.revision = parent_entry.revision
                 ie.symlink_target = parent_entry.symlink_target
                 return
@@ -2533,9 +2541,14 @@
             self._add_text_to_weave(ie.file_id, lines, heads, None)
         elif kind == 'tree-reference':
             if not store:
-                # all data is meta here, so carry over:
+                if content_summary[3] != parent_entry.reference_revision:
+                    store = True
+            if not store:
+                # unchanged, carry over.
+                ie.reference_revision = parent_entry.reference_revision
                 ie.revision = parent_entry.revision
                 return
+            ie.reference_revision = content_summary[3]
             lines = []
             self._add_text_to_weave(ie.file_id, lines, heads, None)
         else:

=== modified file 'bzrlib/tests/workingtree_implementations/test_inv.py'
--- a/bzrlib/tests/workingtree_implementations/test_inv.py	2007-08-29 16:09:51 +0000
+++ b/bzrlib/tests/workingtree_implementations/test_inv.py	2007-09-11 09:09:40 +0000
@@ -43,93 +43,6 @@
         self.assertEqual(len(wt.inventory), 1)
 
 
-class TestSnapshot(TestCaseWithWorkingTree):
-
-    def setUp(self):
-        # for full testing we'll need a branch
-        # with a subdir to test parent changes.
-        # and a file, link and dir under that.
-        # but right now I only need one attribute
-        # to change, and then test merge patterns
-        # with fake parent entries.
-        super(TestSnapshot, self).setUp()
-        self.wt = self.make_branch_and_tree('.')
-        self.branch = self.wt.branch
-        self.build_tree(['subdir/', 'subdir/file'], line_endings='binary')
-        self.wt.add(['subdir', 'subdir/file'],
-                                       ['dirid', 'fileid'])
-        self.wt.commit('message_1', rev_id = '1')
-        self.tree_1 = self.branch.repository.revision_tree('1')
-        self.inv_1 = self.branch.repository.get_inventory('1')
-        self.file_1 = self.inv_1['fileid']
-        self.wt.lock_write()
-        self.addCleanup(self.wt.unlock)
-        self.file_active = self.wt.inventory['fileid']
-        self.builder = self.branch.get_commit_builder([], timestamp=time.time(), revision_id='2')
-
-    def test_snapshot_new_revision(self):
-        # This tests that a simple commit with no parents makes a new
-        # revision value in the inventory entry
-        self.file_active.snapshot('2', 'subdir/file', {}, self.wt, self.builder)
-        # expected outcome - file_1 has a revision id of '2', and we can get
-        # its text of 'file contents' out of the weave.
-        self.assertEqual(self.file_1.revision, '1')
-        self.assertEqual(self.file_active.revision, '2')
-        # this should be a separate test probably, but lets check it once..
-        lines = self.branch.repository.weave_store.get_weave(
-            'fileid', 
-            self.branch.repository.get_transaction()).get_lines('2')
-        self.assertEqual(lines, ['contents of subdir/file\n'])
-        self.wt.branch.repository.commit_write_group()
-
-    def test_snapshot_unchanged(self):
-        #This tests that a simple commit does not make a new entry for
-        # an unchanged inventory entry
-        self.file_active.snapshot('2', 'subdir/file', {'1':self.file_1},
-                                  self.wt, self.builder)
-        self.assertEqual(self.file_1.revision, '1')
-        self.assertEqual(self.file_active.revision, '1')
-        vf = self.branch.repository.weave_store.get_weave(
-            'fileid', 
-            self.branch.repository.get_transaction())
-        self.assertRaises(errors.RevisionNotPresent,
-                          vf.get_lines,
-                          '2')
-        self.wt.branch.repository.commit_write_group()
-
-    def test_snapshot_merge_identical_different_revid(self):
-        # This tests that a commit with two identical parents, one of which has
-        # a different revision id, results in a new revision id in the entry.
-        # 1->other, commit a merge of other against 1, results in 2.
-        other_ie = inventory.InventoryFile('fileid', 'newname', self.file_1.parent_id)
-        other_ie = inventory.InventoryFile('fileid', 'file', self.file_1.parent_id)
-        other_ie.revision = '1'
-        other_ie.text_sha1 = self.file_1.text_sha1
-        other_ie.text_size = self.file_1.text_size
-        self.assertEqual(self.file_1, other_ie)
-        other_ie.revision = 'other'
-        self.assertNotEqual(self.file_1, other_ie)
-        versionfile = self.branch.repository.weave_store.get_weave(
-            'fileid', self.branch.repository.get_transaction())
-        versionfile.clone_text('other', '1', ['1'])
-        self.file_active.snapshot('2', 'subdir/file', 
-                                  {'1':self.file_1, 'other':other_ie},
-                                  self.wt, self.builder)
-        self.assertEqual(self.file_active.revision, '2')
-        self.wt.branch.repository.commit_write_group()
-
-    def test_snapshot_changed(self):
-        # This tests that a commit with one different parent results in a new
-        # revision id in the entry.
-        self.wt.rename_one('subdir/file', 'subdir/newname')
-        self.file_active = self.wt.inventory['fileid']
-        self.file_active.snapshot('2', 'subdir/newname', {'1':self.file_1}, 
-                                  self.wt, self.builder)
-        # expected outcome - file_1 has a revision id of '2'
-        self.assertEqual(self.file_active.revision, '2')
-        self.wt.branch.repository.commit_write_group()
-
-
 class TestApplyInventoryDelta(TestCaseWithWorkingTree):
 
     def test_add(self):



More information about the bazaar-commits mailing list