Rev 112: Merge Aarons --auto-by-default branch, tweaking to accomodate changes since, and discarding changes to command loading that are not safe. in http://bazaar.launchpad.net/~bzr-loom-devs/bzr-loom/trunk/

Robert Collins robertc at robertcollins.net
Wed Jun 16 04:37:24 BST 2010


At http://bazaar.launchpad.net/~bzr-loom-devs/bzr-loom/trunk/

------------------------------------------------------------
revno: 112 [merge]
revision-id: robertc at robertcollins.net-20100616033723-eggmo84u8ha2du7u
parent: robertc at robertcollins.net-20100614065918-pjvn2dtyu0i7dz0x
parent: aaron at aaronbentley.com-20090324202637-h6cojy84e4i25av4
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Wed 2010-06-16 15:37:23 +1200
message:
  Merge Aarons --auto-by-default branch, tweaking to accomodate changes since, and discarding changes to command loading that are not safe.
modified:
  NEWS                           news-20080228111444-miryhm4hma987q57-1
  __init__.py                    __init__.py-20060620084702-jnrwijq76kg45klj-3
  commands.py                    commands.py-20060620084702-jnrwijq76kg45klj-6
  tests/blackbox.py              blackbox.py-20060620084702-jnrwijq76kg45klj-7
  tests/test_tree.py             test_tree.py-20060701081608-boqb8o8yz1a2bil2-1
  tree.py                        tree.py-20060701085538-3ajq87mglfa5ryqa-1
=== modified file 'NEWS'
--- a/NEWS	2010-06-14 06:59:18 +0000
+++ b/NEWS	2010-06-16 03:37:23 +0000
@@ -18,6 +18,9 @@
 CHANGES
 -------
 
+* --auto is now the default on up-thread. You can supply a thread name to stop
+  at a given thread, or --manual to go up a single thread. (Aaron Bentley)
+
 FEATURES
 --------
 

=== modified file '__init__.py'
--- a/__init__.py	2010-04-20 11:28:12 +0000
+++ b/__init__.py	2010-06-16 03:37:23 +0000
@@ -74,8 +74,12 @@
     'show_loom',
     'up_thread',
     ]:
-    bzrlib.commands.register_command(getattr(commands, 'cmd_' + command))
+    bzrlib.commands.plugin_cmds.register_lazy('cmd_' + command, [],
+        'bzrlib.plugins.loom.commands')
 
+# XXX: bzr fix needed: for status and switch, we have to register directly, not
+# lazily, because register_lazy does not stack in the same way register_command
+# does.
 if not hasattr(bzrlib.builtins, "cmd_switch"):
     # provide a switch command (allows 
     bzrlib.commands.register_command(getattr(commands, 'cmd_switch'))

=== modified file 'commands.py'
--- a/commands.py	2010-04-20 11:13:54 +0000
+++ b/commands.py	2010-06-16 03:37:23 +0000
@@ -326,26 +326,34 @@
 
 
 class cmd_up_thread(bzrlib.commands.Command):
-    """Move the branch up a thread in the loom.
-    
+    """Move the branch up to the top thread in the loom.
+
     This merges the changes done in this thread but not incorporated into
     the next thread up into the next thread up and switches your tree to be
-    that thread.
+    that thread.  Unless there are conflicts, or --manual is specified, it
+    will then commit and repeat the process.
     """
 
+    takes_args = ['thread?']
+
     takes_options = ['merge-type', Option('auto',
-        help='Automatically commit and merge repeatedly.')]
+        help='Deprecated - now the default.'),
+        Option('manual', help='Perform commit manually.'),
+        ]
 
     _see_also = ['down-thread', 'switch']
 
-    def run(self, merge_type=None, auto=False):
+    def run(self, merge_type=None, manual=False, thread=None, auto=None):
         (tree, path) = workingtree.WorkingTree.open_containing('.')
         branch.require_loom_branch(tree.branch)
         tree = LoomTreeDecorator(tree)
-        if not auto:
+        if manual:
+            if thread is not None:
+                raise errors.BzrCommandError('Specifying a thread does not'
+                                             ' work with --manual.')
             return tree.up_thread(merge_type)
         else:
-            return tree.up_many(merge_type)
+            return tree.up_many(merge_type, thread)
 
 
 class cmd_export_loom(bzrlib.commands.Command):

=== modified file 'tests/blackbox.py'
--- a/tests/blackbox.py	2009-09-22 03:40:53 +0000
+++ b/tests/blackbox.py	2010-06-16 03:37:23 +0000
@@ -416,7 +416,7 @@
         self.assertEqual('', out)
         self.assertEqual(
             'bzr: ERROR: Cannot move up from the highest thread.\n', err)
-        
+
     def test_up_thread_same_revision(self):
         """moving up when the revision is unchanged should work."""
         tree = self.get_vendor_loom()
@@ -428,8 +428,8 @@
         self.assertEqual('', err)
         self.assertEqual('patch', tree.branch.nick)
         self.assertEqual(rev, tree.last_revision())
-        
-    def test_up_thread_preserves_changes(self):
+
+    def test_up_thread_manual_preserves_changes(self):
         tree = self.get_vendor_loom()
         tree.branch.new_thread('patch')
         tree.branch.nick = 'vendor'
@@ -438,7 +438,7 @@
         self.build_tree(['afile'])
         tree.add('afile')
         vendor_release = tree.commit('new vendor release adds a file.')
-        out, err = self.run_bzr(['up-thread'])
+        out, err = self.run_bzr(['up-thread', '--manual'])
         self.assertEqual('', out)
         self.assertEqual(
             "All changes applied successfully.\n"
@@ -455,6 +455,13 @@
         self.run_bzr(['diff'], retcode=1)
         self.assertEqual([patch_rev, vendor_release], tree.get_parent_ids())
 
+    def test_up_thread_manual_rejects_specified_thread(self):
+        tree = self.get_vendor_loom()
+        tree.branch.new_thread('patch')
+        out, err = self.run_bzr('up-thread --manual patch', retcode=3)
+        self.assertContainsRe(err, 'Specifying a thread does not work with'
+                              ' --manual.')
+
     def test_up_thread_gets_conflicts(self):
         """Do a change in both the baseline and the next patch up."""
         tree = self.get_vendor_loom()
@@ -496,11 +503,11 @@
         self.run_bzr(['down-thread'])
         self.run_bzr(['up-thread', '--lca'])
 
-    def test_up_thread_auto(self):
+    def test_up_thread_no_manual(self):
         tree = self.get_vendor_loom()
         tree.branch.new_thread('middle')
         tree.branch.new_thread('top')
-        self.run_bzr('up-thread --auto')
+        self.run_bzr('up-thread')
         branch = _mod_branch.Branch.open('.')
         self.assertEqual('top', branch.nick)
 
@@ -536,12 +543,13 @@
         vendor_release = tree.commit('make the same change to afile')
         # check that the trees no longer differ after the up merge,
         # and that we are 
-        out, err = self.run_bzr(['up-thread'])
+        out, err = self.run_bzr(['up-thread', '--manual'])
         self.assertEqual('', out)
-        self.assertEqual("All changes applied successfully.\n"
+        self.assertStartsWith(err,
+            "All changes applied successfully.\n"
             "Moved to thread 'patch'.\n"
             'This thread is now empty, you may wish to run "bzr '
-            'combine-thread" to remove it.\n', err)
+            'combine-thread" to remove it.\n')
         self.assertEqual('patch', tree.branch.nick)
         # the tree needs to be updated.
         self.assertEqual(patch_rev, tree.last_revision())
@@ -552,6 +560,14 @@
         self.run_bzr(['diff'])
         self.assertEqual([patch_rev, vendor_release], tree.get_parent_ids())
 
+    def test_up_thread_accepts_thread(self):
+        tree = self.get_vendor_loom()
+        tree.branch.new_thread('lower-middle')
+        tree.branch.new_thread('upper-middle')
+        tree.branch.new_thread('top')
+        self.run_bzr('up-thread upper-middle')
+        branch = _mod_branch.Branch.open('.')
+        self.assertEqual('upper-middle', branch.nick)
 
 
 class TestPush(TestsWithLooms):

=== modified file 'tests/test_tree.py'
--- a/tests/test_tree.py	2010-04-20 11:13:54 +0000
+++ b/tests/test_tree.py	2010-06-16 03:37:23 +0000
@@ -193,6 +193,20 @@
         self.assertEqual(['middle-1', 'bottom-2'], tree.get_parent_ids())
         self.assertEqual(1, len(tree.conflicts()))
 
+    def test_up_many_target_thread(self):
+        loom_tree = self.get_loom_with_three_threads()
+        tree = loom_tree.tree
+        loom_tree.up_many(target_thread='middle')
+        self.assertEqual('middle', tree.branch.nick)
+
+    def test_up_many_target_thread_lower(self):
+        loom_tree = self.get_loom_with_three_threads()
+        tree = loom_tree.tree
+        loom_tree.up_many(target_thread='top')
+        e = self.assertRaises(errors.BzrCommandError,
+                              loom_tree.up_many, target_thread='middle')
+        self.assertEqual('Cannot up-thread to lower thread.', str(e))
+
     def test_revert_loom(self):
         tree = self.get_tree_with_loom(',')
         # ensure we have some stuff to revert

=== modified file 'tree.py'
--- a/tree.py	2010-02-26 14:32:25 +0000
+++ b/tree.py	2010-06-16 03:37:23 +0000
@@ -137,13 +137,25 @@
         else:
             return 0
 
-    def up_many(self, merge_type=None):
-        threads = self.branch.get_loom_state().get_threads()
-        top_thread_name = threads[-1][0]
-        while self.branch.nick != top_thread_name:
+    def up_many(self, merge_type=None, target_thread=None):
+        loom_state = self.branch.get_loom_state()
+        threads = loom_state.get_threads()
+        if target_thread is None:
+            target_thread = threads[-1][0]
+            if self.branch.nick == target_thread:
+                raise bzrlib.errors.BzrCommandError(
+                    'Cannot move up from the highest thread.')
+        else:
+            upper_thread_i = loom_state.thread_index(target_thread)
+            lower_thread_i = loom_state.thread_index(self.branch.nick)
+            if lower_thread_i > upper_thread_i:
+                raise bzrlib.errors.BzrCommandError(
+                    "Cannot up-thread to lower thread.")
+        while self.branch.nick != target_thread:
             old_nick = self.branch.nick
-            if self.up_thread(merge_type) != 0:
-                break
+            result = self.up_thread(merge_type)
+            if result != 0:
+                return result
             if len(self.tree.get_parent_ids()) > 1:
                 self.tree.commit('Merge %s into %s' % (old_nick,
                                                        self.branch.nick))
@@ -151,12 +163,11 @@
     @needs_write_lock
     def down_thread(self, name=None):
         """Move to a thread down in the loom.
-        
+
         :param name: If None, use the next lower thread; otherwise the nae of
             the thread to move to.
         """
         self._check_switch()
-        current_revision = self.tree.last_revision()
         threadname = self.tree.branch.nick
         state = self.tree.branch.get_loom_state()
         threads = state.get_threads()
@@ -181,17 +192,30 @@
             new_thread_rev = bzrlib.revision.NULL_REVISION
         if old_thread_rev == EMPTY_REVISION:
             old_thread_rev = bzrlib.revision.NULL_REVISION
-        basis_tree = self.tree.branch.repository.revision_tree(old_thread_rev)
-        to_tree = self.tree.branch.repository.revision_tree(new_thread_rev)
+        repository = self.tree.branch.repository
+        try:
+            basis_tree = self.tree.revision_tree(old_thread_rev)
+        except bzrlib.errors.NoSuchRevisionInTree:
+            basis_tree = repository.revision_tree(old_thread_rev)
+        to_tree = repository.revision_tree(new_thread_rev)
         result = bzrlib.merge.merge_inner(self.tree.branch,
             to_tree,
             basis_tree,
             this_tree=self.tree)
-        self.tree.branch.generate_revision_history(new_thread_rev)
-        self.tree.set_last_revision(new_thread_rev)
+        branch_revno, branch_revision = self.tree.branch.last_revision_info()
+        graph = repository.get_graph()
+        new_thread_revno = graph.find_distance_to_null(new_thread_rev,
+            [(branch_revision, branch_revno)])
+        self.tree.branch.set_last_revision_info(new_thread_revno,
+                                                new_thread_rev)
+        if new_thread_rev == bzrlib.revision.NULL_REVISION:
+            parent_list = []
+        else:
+            parent_list = [(new_thread_rev, to_tree)]
+        self.tree.set_parent_trees(parent_list)
         bzrlib.trace.note("Moved to thread '%s'." % new_thread_name)
         return result
-        
+
     def lock_write(self):
         self.tree.lock_write()
 




More information about the bazaar-commits mailing list