[PATCH 2 of 2] Added more named branch support to the fetch command (fetch extension)

Sune Foldager cryo at cyanite.org
Tue Aug 26 05:45:12 CDT 2008


# HG changeset patch
# User Sune Foldager <cryo at cyanite.org>
# Date 1219747446 -7200
# Node ID 270fd622e4ebe23de0efeded678f6a37f5e1b060
# Parent  c4c14e1a60fac20280fcaa5db80a948ae0aa0669
Added more named branch support to the fetch command (fetch extension).

Previously, fetch didn't really work when there were multiple named branches
in the repository. Now it tries to do the right thing(tm) in all situations.

diff -r c4c14e1a60fa -r 270fd622e4eb hgext/fetch.py
--- a/hgext/fetch.py	Tue Aug 26 12:44:05 2008 +0200
+++ b/hgext/fetch.py	Tue Aug 26 12:44:06 2008 +0200
@@ -29,22 +29,34 @@
     '''
 
     def postincoming(other, modheads):
+
+        # Are there any changes at all?
         if modheads == 0:
             return 0
-        if modheads == 1:
-            return hg.clean(repo, repo.changelog.tip())
-        newheads = repo.heads(parent)
-        newchildren = [n for n in repo.heads(parent) if n != parent]
+
+        # Is this a simple fast-forward along the current branch?
+        newheads = repo.branchheads(branch)
+        newchildren = repo.changelog.nodesbetween([parent], newheads)[2]
+        if len(newheads) == 1:
+            if newchildren[0] != parent:
+              return hg.clean(repo, newchildren[0])
+            else:
+              return
+
+        # Are there more than one additional branch heads?
+        newchildren = [n for n in newchildren if n != parent]
         newparent = parent
         if newchildren:
             newparent = newchildren[0]
             hg.clean(repo, newparent)
-        newheads = [n for n in repo.heads() if n != newparent]
+        newheads = [n for n in newheads if n != newparent]
         if len(newheads) > 1:
-            ui.status(_('not merging with %d other new heads '
-                        '(use "hg heads" and "hg merge" to merge them)') %
+            ui.status(_('not merging with %d other new branch heads '
+                        '(use "hg heads -b" and "hg merge" to merge them)') %
                       (len(newheads) - 1))
             return
+
+        # Otherwise, let's merge.
         err = False
         if newheads:
             # By default, we consider the repository we're pulling
@@ -95,9 +107,10 @@
         opts['date'] = util.parsedate(date)
 
     parent, p2 = repo.dirstate.parents()
-    if parent != repo.changelog.tip():
-        raise util.Abort(_('working dir not at tip '
-                           '(use "hg update" to check out tip)'))
+    branch = repo[parent].branch()
+    if parent != repo[branch].node():
+        raise util.Abort(_('working dir not at branch tip '
+                           '(use "hg update" to check out branch tip)'))
     if p2 != nullid:
         raise util.Abort(_('outstanding uncommitted merge'))
     wlock = lock = None
@@ -109,9 +122,9 @@
             raise util.Abort(_('outstanding uncommitted changes'))
         if del_:
             raise util.Abort(_('working directory is missing some files'))
-        if len(repo.heads()) > 1:
-            raise util.Abort(_('multiple heads in this repository '
-                               '(use "hg heads" and "hg merge" to merge)'))
+        if len(repo.branchheads(branch)) > 1:
+            raise util.Abort(_('multiple heads in this branch '
+                               '(use "hg heads -b" and "hg merge" to merge)'))
         return pull()
     finally:
         del lock, wlock


More information about the Mercurial-devel mailing list