[PATCH] Limit merge to the current named branch

Petersen, Allen Allen.Petersen at HSTX.com
Thu Jun 5 18:40:55 CDT 2008


# HG changeset patch
# User Allen Petersen <allen.petersen at hstx.com> # Date 1212634241 -43200
# Node ID 4cde10836cf097dae7c5397a68ad77a6ba3c72bd
# Parent  d6caebe9c293094e578eb9f5494cc7d711f34293
Limit merge to the current named branch.

Adding a feature to limit the scope of a merge to the current named
branch.  This new behavior is activated only if the
'single-branch-merge' option is set to True in the [ui] section of the
hgrc. The behavior can also be overridden with an '-a' option on the
command line.

diff -r d6caebe9c293 -r 4cde10836cf0 mercurial/commands.py
--- a/mercurial/commands.py	Tue Jun 03 09:31:36 2008 +0200
+++ b/mercurial/commands.py	Thu Jun 05 14:50:41 2008 +1200
@@ -1851,7 +1851,7 @@
             ui.write("%3s %1s " % (perm, type))
         ui.write("%s\n" % f)
 
-def merge(ui, repo, node=None, force=None, rev=None):
+def merge(ui, repo, node=None, force=None, rev=None, allheads=None):
     """merge working directory with another revision
 
     Merge the contents of the current working directory and the @@
-1872,12 +1872,25 @@
 
     if not node:
         heads = repo.heads()
+        old_heads = heads
+        if  ui.config("ui","single-branch-merge") and not allheads:
+            new_heads = []
+            log = repo.changelog
+            for h in heads:
+                changes = log.read(h)
+                if repo.dirstate.branch() == changes[5].get("branch"):
+                    new_heads.append(h)
+            heads = new_heads
+
         if len(heads) > 2:
             raise util.Abort(_('repo has %d heads - '
                                'please merge with an explicit rev') %
                              len(heads))
         parent = repo.dirstate.parents()[0]
         if len(heads) == 1:
+            if len(old_heads) > 1:
+                raise util.Abort(_('there is nothing to merge for the
current branch - '
+                                   'use "hg merge -a" instead'))
             msg = _('there is nothing to merge')
             if parent != repo.lookup(repo.workingctx().branch()):
                 msg = _('%s - use "hg update" instead') % msg @@
-3134,8 +3147,9 @@
         (merge,
          [('f', 'force', None, _('force a merge with outstanding
changes')),
           ('r', 'rev', '', _('revision to merge')),
+          ('a', 'allheads', None, _('force merge to include all 
+ heads')),
              ],
-         _('hg merge [-f] [[-r] REV]')),
+         _('hg merge [-f] [[-r] REV] [-a]')),
     "outgoing|out":
         (outgoing,
          [('f', 'force', None,



More information about the Mercurial-devel mailing list