Rev 4478: update BranchBuilder to support 'committer' in http://bazaar.launchpad.net/~jameinel/bzr/1.17-rework-annotate

John Arbash Meinel john at arbash-meinel.com
Fri Jun 19 22:26:18 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/1.17-rework-annotate

------------------------------------------------------------
revno: 4478
revision-id: john at arbash-meinel.com-20090619212551-4j7929u7kmngz3ls
parent: john at arbash-meinel.com-20090618220742-10czy03gxzh337fl
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.17-rework-annotate
timestamp: Fri 2009-06-19 16:25:51 -0500
message:
  update BranchBuilder to support 'committer'
  Update test_annotate to use BranchBuilder rather than lots of trees and tree.commit.
-------------- next part --------------
=== modified file 'bzrlib/branchbuilder.py'
--- a/bzrlib/branchbuilder.py	2009-05-07 05:08:46 +0000
+++ b/bzrlib/branchbuilder.py	2009-06-19 21:25:51 +0000
@@ -161,7 +161,8 @@
         self._tree = None
 
     def build_snapshot(self, revision_id, parent_ids, actions,
-        message=None, timestamp=None, allow_leftmost_as_ghost=False):
+        message=None, timestamp=None, allow_leftmost_as_ghost=False,
+        committer=None):
         """Build a commit, shaped in a specific way.
 
         :param revision_id: The handle for the new commit, can be None
@@ -176,6 +177,7 @@
             commit message will be written.
         :param timestamp: If non-None, set the timestamp of the commit to this
             value.
+        :param committer: An optional username to use for commit
         :param allow_leftmost_as_ghost: True if the leftmost parent should be
             permitted to be a ghost.
         :return: The revision_id of the new commit
@@ -241,7 +243,7 @@
             for file_id, content in new_contents.iteritems():
                 tree.put_file_bytes_non_atomic(file_id, content)
             return self._do_commit(tree, message=message, rev_id=revision_id,
-                timestamp=timestamp)
+                timestamp=timestamp, committer=committer)
         finally:
             tree.unlock()
 

=== modified file 'bzrlib/tests/test_annotate.py'
--- a/bzrlib/tests/test_annotate.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/test_annotate.py	2009-06-19 21:25:51 +0000
@@ -176,38 +176,23 @@
          |
         rev-3
         """
-
-        tree1 = self.make_branch_and_tree('tree1')
-        self.build_tree_contents([('tree1/a', 'first\n')])
-        tree1.add(['a'], ['a-id'])
-        tree1.commit('a', rev_id='rev-1',
-                     committer="joe at foo.com",
-                     timestamp=1166046000.00, timezone=0)
-
-        tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
-
-        self.build_tree_contents([('tree1/a', 'first\nsecond\n')])
-        tree1.commit('b', rev_id='rev-2',
-                     committer='joe at foo.com',
-                     timestamp=1166046001.00, timezone=0)
-
-        self.build_tree_contents([('tree2/a', 'first\nthird\n')])
-        tree2.commit('c', rev_id='rev-1_1_1',
-                     committer="barry at foo.com",
-                     timestamp=1166046002.00, timezone=0)
-
-        num_conflicts = tree1.merge_from_branch(tree2.branch)
-        self.assertEqual(1, num_conflicts)
-
-        self.build_tree_contents([('tree1/a',
-                                 'first\nsecond\nthird\n')])
-        tree1.set_conflicts(conflicts.ConflictList())
-        tree1.commit('merge 2', rev_id='rev-3',
-                     committer='sal at foo.com',
-                     timestamp=1166046003.00, timezone=0)
-        tree1.lock_read()
-        self.addCleanup(tree1.unlock)
-        return tree1, tree2
+        builder = self.make_branch_builder('branch')
+        builder.start_series()
+        self.addCleanup(builder.finish_series)
+        builder.build_snapshot('rev-1', None, [
+            ('add', ('', 'root-id', 'directory', None)),
+            ('add', ('a', 'a-id', 'file', 'first\n')),
+            ], timestamp=1166046000.00, committer="joe at foo.com")
+        builder.build_snapshot('rev-2', ['rev-1'], [
+            ('modify', ('a-id', 'first\nsecond\n')),
+            ], timestamp=1166046001.00, committer="joe at foo.com")
+        builder.build_snapshot('rev-1_1_1', ['rev-1'], [
+            ('modify', ('a-id', 'first\nthird\n')),
+            ], timestamp=1166046002.00, committer="barry at foo.com")
+        builder.build_snapshot('rev-3', ['rev-2', 'rev-1_1_1'], [
+            ('modify', ('a-id', 'first\nsecond\nthird\n')),
+            ], timestamp=1166046003.00, committer="sal at foo.com")
+        return builder
 
     def create_deeply_merged_trees(self):
         """Create some trees with a more complex merge history.
@@ -232,37 +217,25 @@
          |
         rev-6
         """
-        tree1, tree2 = self.create_merged_trees()
-        tree1.unlock()
-
-        tree3 = tree2.bzrdir.sprout('tree3').open_workingtree()
-
-        tree2.commit('noop', rev_id='rev-1_1_2')
-        self.assertEqual(0, tree1.merge_from_branch(tree2.branch))
-        tree1.commit('noop merge', rev_id='rev-4')
-
-        self.build_tree_contents([('tree3/a', 'first\nthird\nfourth\n')])
-        tree3.commit('four', rev_id='rev-1_2_1',
-                     committer='jerry at foo.com',
-                     timestamp=1166046003.00, timezone=0)
-
-        tree4 = tree3.bzrdir.sprout('tree4').open_workingtree()
-
-        tree3.commit('noop', rev_id='rev-1_2_2',
-                     committer='jerry at foo.com',
-                     timestamp=1166046004.00, timezone=0)
-        self.assertEqual(0, tree1.merge_from_branch(tree3.branch))
-        tree1.commit('merge four', rev_id='rev-5')
-
-        self.build_tree_contents([('tree4/a',
-                                   'first\nthird\nfourth\nfifth\nsixth\n')])
-        tree4.commit('five and six', rev_id='rev-1_3_1',
-                     committer='george at foo.com',
-                     timestamp=1166046005.00, timezone=0)
-        self.assertEqual(0, tree1.merge_from_branch(tree4.branch))
-        tree1.commit('merge five and six', rev_id='rev-6')
-        tree1.lock_read()
-        return tree1
+        builder = self.create_merged_trees()
+        builder.build_snapshot('rev-1_1_2', ['rev-1_1_1'], [])
+        builder.build_snapshot('rev-4', ['rev-3', 'rev-1_1_2'], [])
+        builder.build_snapshot('rev-1_2_1', ['rev-1_1_1'], [
+            ('modify', ('a-id', 'first\nthird\nfourth\n')),
+            ], timestamp=1166046003.00, committer="jerry at foo.com")
+        builder.build_snapshot('rev-1_2_2', ['rev-1_2_1'], [],
+            timestamp=1166046004.00, committer="jerry at foo.com")
+        builder.build_snapshot('rev-5', ['rev-4', 'rev-1_2_2'], [
+            ('modify', ('a-id', 'first\nsecond\nthird\nfourth\n')),
+            ], timestamp=1166046004.00, committer="jerry at foo.com")
+        builder.build_snapshot('rev-1_3_1', ['rev-1_2_1'], [
+            ('modify', ('a-id', 'first\nthird\nfourth\nfifth\nsixth\n')),
+            ], timestamp=1166046005.00, committer="george at foo.com")
+        builder.build_snapshot('rev-6', ['rev-5', 'rev-1_3_1'], [
+            ('modify', ('a-id',
+                        'first\nsecond\nthird\nfourth\nfifth\nsixth\n')),
+            ])
+        return builder
 
     def create_duplicate_lines_tree(self):
         tree1 = self.make_branch_and_tree('tree1')
@@ -319,10 +292,10 @@
         self.assertRepoAnnotate(duplicate_E, repo, 'file-id', 'rev-E')
 
     def test_annotate_shows_dotted_revnos(self):
-        tree1, tree2 = self.create_merged_trees()
+        builder = self.create_merged_trees()
 
         sio = StringIO()
-        annotate.annotate_file(tree1.branch, 'rev-3', 'a-id',
+        annotate.annotate_file(builder.get_branch(), 'rev-3', 'a-id',
                                to_file=sio)
         self.assertEqualDiff('1     joe at foo | first\n'
                              '2     joe at foo | second\n'
@@ -331,10 +304,10 @@
 
     def test_annotate_limits_dotted_revnos(self):
         """Annotate should limit dotted revnos to a depth of 12"""
-        tree1 = self.create_deeply_merged_trees()
+        builder = self.create_deeply_merged_trees()
 
         sio = StringIO()
-        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
+        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
                                to_file=sio, verbose=False, full=False)
         self.assertEqualDiff('1     joe at foo | first\n'
                              '2     joe at foo | second\n'
@@ -345,7 +318,7 @@
                              sio.getvalue())
 
         sio = StringIO()
-        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
+        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
                                to_file=sio, verbose=False, full=True)
         self.assertEqualDiff('1     joe at foo | first\n'
                              '2     joe at foo | second\n'
@@ -357,7 +330,7 @@
 
         # verbose=True shows everything, the full revno, user id, and date
         sio = StringIO()
-        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
+        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
                                to_file=sio, verbose=True, full=False)
         self.assertEqualDiff('1     joe at foo.com    20061213 | first\n'
                              '2     joe at foo.com    20061213 | second\n'
@@ -368,7 +341,7 @@
                              sio.getvalue())
 
         sio = StringIO()
-        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
+        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
                                to_file=sio, verbose=True, full=True)
         self.assertEqualDiff('1     joe at foo.com    20061213 | first\n'
                              '2     joe at foo.com    20061213 | second\n'
@@ -384,10 +357,10 @@
         When annotating a non-mainline revision, the annotation should still
         use dotted revnos from the mainline.
         """
-        tree1 = self.create_deeply_merged_trees()
+        builder = self.create_deeply_merged_trees()
 
         sio = StringIO()
-        annotate.annotate_file(tree1.branch, 'rev-1_3_1', 'a-id',
+        annotate.annotate_file(builder.get_branch(), 'rev-1_3_1', 'a-id',
                                to_file=sio, verbose=False, full=False)
         self.assertEqualDiff('1     joe at foo | first\n'
                              '1.1.1 barry at f | third\n'
@@ -397,10 +370,10 @@
                              sio.getvalue())
 
     def test_annotate_show_ids(self):
-        tree1 = self.create_deeply_merged_trees()
+        builder = self.create_deeply_merged_trees()
 
         sio = StringIO()
-        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
+        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
                                to_file=sio, show_ids=True, full=False)
 
         # It looks better with real revision ids :)
@@ -413,7 +386,7 @@
                              sio.getvalue())
 
         sio = StringIO()
-        annotate.annotate_file(tree1.branch, 'rev-6', 'a-id',
+        annotate.annotate_file(builder.get_branch(), 'rev-6', 'a-id',
                                to_file=sio, show_ids=True, full=True)
 
         self.assertEqualDiff('    rev-1 | first\n'



More information about the bazaar-commits mailing list