[PATCH 3 of 3]: merge: when merging with ancestor, move active bookmark and update

Waldemar Kornewald wkornewald at gmail.com
Sun Nov 8 00:19:45 UTC 2015


# HG changeset patch
# User Waldemar Kornewald <wkornewald>
# Date 1446936643 -3600
#      Sat Nov 07 23:50:43 2015 +0100
# Node ID 22af720813819806077417102c1a21fc9d7f266c
# Parent  f9984f76fd90e439221425d751e29bae17bec995
merge: when merging with ancestor, move active bookmark and update

>From the perspective of the "branching" concept (implemented in hg through
bookmarks), merging actually means "import those changes into my branch".

The old behavior was confusing and inconsistent:

A merge with a different head would import as expected.
A merge with an ancestor would fail with an error.

We now deal with the second case (ancestor merge) differently:
In order to comply with the merging=importing idea, we simply move the
bookmark forward to the ancestor revision and do an update.

diff -r f9984f76fd90 -r 22af72081381 mercurial/hg.py
--- a/mercurial/hg.py Wed Nov 04 15:17:52 2015 -0600
+++ b/mercurial/hg.py Sat Nov 07 23:50:43 2015 +0100
@@ -620,7 +620,7 @@

 def _showstats(repo, stats):
     repo.ui.status(_("%d files updated, %d files merged, "
-                     "%d files removed, %d files unresolved\n") % stats)
+                     "%d files removed, %d files unresolved\n") % stats[:4])

 def updaterepo(repo, node, overwrite):
     """Update the working directory to node.
@@ -658,7 +658,7 @@
     if stats[3]:
         repo.ui.status(_("use 'hg resolve' to retry unresolved file merges "
                          "or 'hg update -C .' to abandon\n"))
-    elif remind:
+    elif remind and stats[4]:
         repo.ui.status(_("(branch merge, don't forget to commit)\n"))
     return stats[3] > 0

diff -r f9984f76fd90 -r 22af72081381 mercurial/merge.py
--- a/mercurial/merge.py Wed Nov 04 15:17:52 2015 -0600
+++ b/mercurial/merge.py Sat Nov 07 23:50:43 2015 +0100
@@ -20,10 +20,12 @@
     nullrev,
 )
 from . import (
+    bookmarks,
     copies,
     destutil,
     error,
     filemerge,
+    hg,
     obsolete,
     subrepo,
     util,
@@ -1135,7 +1137,9 @@
     4 = abort: uncommitted changes (checked in commands.py)
     5 = incompatible options (checked in commands.py)

-    Return the same tuple as applyupdates().
+    Return the same tuple as applyupdates(), plus an extra bool entry
at the end
+    that is True if we've done a merge and a commit is necessary. No commit is
+    needed when a merge just moves a bookmark.
     """

     onode = node
@@ -1176,6 +1180,12 @@
                                    " has no effect"))
             elif pas == [p1]:
                 if not mergeancestor and p1.branch() == p2.branch():
+                    if repo._activebookmark:
+                        active = repo[repo._activebookmark].node()
+                        stats = hg.updaterepo(repo, node, False)
+                        bookmarks.update(repo, [active], node)
+                        return stats
+
                     raise error.Abort(_("nothing to merge"),
                                      hint=_("use 'hg update' "
                                             "or check 'hg heads'"))
@@ -1190,7 +1200,7 @@
                 # call the hooks and exit early
                 repo.hook('preupdate', throw=True, parent1=xp2, parent2='')
                 repo.hook('update', parent1=xp2, parent2='', error=0)
-                return 0, 0, 0, 0
+                return 0, 0, 0, 0, branchmerge

             if pas not in ([p1], [p2]):  # nonlinear
                 dirty = wc.dirty(missing=True)
@@ -1277,6 +1287,7 @@
             repo.vfs.write('updatestate', p2.hex())

         stats = applyupdates(repo, actions, wc, p2, overwrite, labels=labels)
+        stats += (branchmerge,)

         # divergent renames
         for f, fl in sorted(diverge.iteritems()):


More information about the Mercurial-devel mailing list