[PATCH] New option to choose fast-forwarding on merge (take 2)

Jan Hudec bulb at ucw.cz
Sat Nov 25 20:40:30 GMT 2006


Hello All,

Since the general reaction to my previous proposal seemed to be that --pull
is nice, but the default case should retain the current semantics. Therefore
I redid the patch without the --trivial option.

So, this patch adds a --pull option to merge, which causes it to fall back to
pull if local is fully merged to remote. This matches the behaviour eg. in
git.

Of course people who don't want their revision numbers should not use this
option. But people used to more git-like workflow (like me) can use it to get
simpler ancestry graph.

Note, that depending on how you view the meaning of pull and merge commands,
pull --merge might look reasonable, but it would mean, that pull would have
to get some other options from merge as well and also the implementation
would be more complicated.

Note: This bundle does NOT include the previous one. I took the diff, removed
the stuff for trivial and applied it to current bzr.dev again, to keep the
history clean.

-- 
						 Jan 'Bulb' Hudec <bulb at ucw.cz>
-------------- next part --------------
# Bazaar revision bundle v0.8
#
# message:
#   Option --pull for merge command.
#   
#   Option --pull was added to merge command, that, if the merge would be
#   trivial, ie. if the common ancestor is equal to the local tip, causes pull of
#   the remote instead of creating the merger.
#   
#   Simple test for this option is included.
#   
# committer: Jan Hudec <bulb at ucw.cz>
# date: Sat 2006-11-25 21:38:39.760999918 +0100

=== modified file NEWS
--- NEWS
+++ NEWS
@@ -23,6 +23,9 @@
     * WSGI-compatible HTTP smart server.  See ``doc/http_smart_server.txt``.
       (Andrew Bennetts)
 
+    * ``bzr merge`` now has an option ``--pull`` to fall back to pull if
+      local is fully merged into remote.
+
   INTERNALS:
 
     * New -D option given before the command line turns on debugging output

=== modified file bzrlib/builtins.py
--- bzrlib/builtins.py
+++ bzrlib/builtins.py
@@ -2197,7 +2197,10 @@
                      Option('show-base', help="Show base revision text in "
                             "conflicts"), 
                      Option('uncommitted', help='Apply uncommitted changes'
-                            ' from a working copy, instead of branch changes')]
+                            ' from a working copy, instead of branch changes'),
+                     Option('pull', help='If the branches are not diverged,'
+                            ' chage to remote revision as via pull command'),
+                     ]
 
     def help(self):
         from inspect import getdoc
@@ -2205,7 +2208,7 @@
 
     def run(self, branch=None, revision=None, force=False, merge_type=None,
             show_base=False, reprocess=False, remember=False, 
-            uncommitted=False):
+            uncommitted=False, pull=False):
         if merge_type is None:
             merge_type = _mod_merge.Merge3Merger
 
@@ -2276,6 +2279,7 @@
                     merge_type=merge_type,
                     reprocess=reprocess,
                     show_base=show_base,
+                    pull=pull,
                     pb=pb, file_list=interesting_files)
             finally:
                 pb.finished()
@@ -2932,6 +2936,7 @@
                   this_dir=None, backup_files=False,
                   merge_type=None,
                   file_list=None, show_base=False, reprocess=False,
+                  pull=False,
                   pb=DummyProgress()):
     """Merge changes into a tree.
 
@@ -2986,6 +2991,12 @@
         if merger.base_rev_id == merger.other_rev_id:
             note('Nothing to do.')
             return 0
+        if file_list is None:
+            if pull and merger.base_rev_id == merger.this_rev_id:
+                count = merger.this_tree.pull(merger.this_branch,
+                        False, merger.other_rev_id)
+                note('%d revision(s) pulled.' % (count,))
+                return 0
         merger.backup_files = backup_files
         merger.merge_type = merge_type 
         merger.set_interesting_files(file_list)

=== modified file bzrlib/tests/blackbox/test_merge.py
--- bzrlib/tests/blackbox/test_merge.py
+++ bzrlib/tests/blackbox/test_merge.py
@@ -239,3 +239,33 @@
         tree_b.revert([])
         self.run_bzr_error(('Cannot use --uncommitted and --revision',), 
                            'merge', '../a', '--uncommitted', '-r1')
+
+    def pullable_branch(self):
+        os.mkdir('a')
+        os.chdir('a')
+        self.example_branch()
+        os.chdir('..')
+        self.runbzr('branch a b')
+        os.chdir('b')
+        file('goodbye', 'wt').write('quux')
+        self.runbzr(['commit', '-m', "mode u's are always good"])
+        os.chdir('../a')
+
+    def pullable_branch(self):
+        tree_a = self.make_branch_and_tree('a')
+        self.build_tree(['a/file'])
+        tree_a.add(['file'])
+        self.id1 = tree_a.commit('commit 1')
+        
+        tree_b = self.make_branch_and_tree('b')
+        tree_b.pull(tree_a.branch)
+        file('b/file', 'wb').write('foo')
+        self.id2 = tree_b.commit('commit 2')
+
+    def test_merge_pull(self):
+        self.pullable_branch()
+        os.chdir('a')
+        (out, err) = self.run_bzr('merge', '--pull', '../b')
+        self.assertContainsRe(err, '1 revision\\(s\\) pulled')
+        tree_a = WorkingTree.open('.')
+        self.assertEqual([self.id2], tree_a.get_parent_ids())

=== modified directory  // last-changed:bulb at ucw.cz-20061125203839-9nuhv32z63hb
... 8811
# revision id: bulb at ucw.cz-20061125203839-9nuhv32z63hb8811
# sha1: 71571ead611a65568e6d26e13ba50548f092fd50
# inventory sha1: 8f8e5d0c6e66c7a7a92dfc606d868953060a149e
# parent ids:
#   pqm at pqm.ubuntu.com-20061123070038-57f13b951191257e
# base id: pqm at pqm.ubuntu.com-20061123070038-57f13b951191257e
# properties:
#   branch-nick: bzr.pointless-merges

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20061125/83caaf6e/attachment.pgp 


More information about the bazaar mailing list