[PATCH] rebase: 'pull --rebase' rebase on new branching only

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu May 5 16:04:03 UTC 2016


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1462366525 -7200
#      Wed May 04 14:55:25 2016 +0200
# Node ID 7e72800c070d941f294c4e7ed91db29a08bac073
# Parent  906a1c8a75fd8a18e43e8545eedcbe5222f84647
# EXP-Topic pull.rebase
rebase: 'pull --rebase' rebase on new branching only

Previously, if two heads existed on the current branch before the pull and the
pull add changeset on the one unrelated to the working copy 'hg pull --rebase'
would trigger a rebase on that branch. This might not what the user wants
as they could have resolved the head situation before pulling if they wanted to.

Therefore, we restrict the set of destination candidate to 'hg pull --rebase' to
the set of pulled changesets that create a branching from the current working
copy branch.

diff -r 906a1c8a75fd -r 7e72800c070d hgext/rebase.py
--- a/hgext/rebase.py	Wed May 04 06:44:44 2016 +0900
+++ b/hgext/rebase.py	Wed May 04 14:55:25 2016 +0200
@@ -1245,15 +1245,18 @@ def pullrebase(orig, ui, repo, *args, **
                 if 'source' in opts:
                     del opts['source']
                 # revsprepull is the len of the repo, not revnum of tip.
-                destspace = list(repo.changelog.revs(start=revsprepull))
+                destspace = repo.revs("(%ld and children(::.))::",
+                                      repo.changelog.revs(start=revsprepull))
                 opts['_destspace'] = destspace
                 try:
                     rebase(ui, repo, **opts)
                 except error.NoMergeDestAbort:
                     # we can maybe update instead
                     rev, _a, _b = destutil.destupdate(repo)
-                    if rev == repo['.'].rev():
-                        ui.status(_('nothing to rebase\n'))
+                    wcp = repo['.']
+                    if rev == wcp.rev():
+                        ui.status(_('nothing to rebase - no branching from %s '
+                                    'pulled\n') % wcp)
                     else:
                         ui.status(_('nothing to rebase - updating instead\n'))
                         # not passing argument to get the bare update behavior
@@ -1353,7 +1356,8 @@ def uisetup(ui):
     #Replace pull with a decorator to provide --rebase option
     entry = extensions.wrapcommand(commands.table, 'pull', pullrebase)
     entry[1].append(('', 'rebase', None,
-                     _("rebase working directory to branch head")))
+                     _("rebase when pulling new branching from working "
+                       "directory parent")))
     entry[1].append(('t', 'tool', '',
                      _("specify merge tool for rebase")))
     cmdutil.summaryhooks.add('rebase', summaryhook)
diff -r 906a1c8a75fd -r 7e72800c070d tests/test-rebase-pull.t
--- a/tests/test-rebase-pull.t	Wed May 04 06:44:44 2016 +0900
+++ b/tests/test-rebase-pull.t	Wed May 04 14:55:25 2016 +0200
@@ -145,14 +145,20 @@ pull --rebase works when a specific revi
   $ hg ci -Am L1
   adding L1
   created new head
+
+(strip extra "remote" changeset to ensure we pull new branching)
+
+  $ hg strip --rev 'desc(R1)' --config extensions.strip=
+  saved backup bundle to $TESTTMP/c/.hg/strip-backup/77ae9631bcca-d0f9f803-backup.hg (glob)
+
   $ hg pull --rev tip --rebase
   pulling from $TESTTMP/a (glob)
   searching for changes
   adding changesets
   adding manifests
   adding file changes
-  added 2 changesets with 2 changes to 2 files
-  rebasing 3:ff8d69a621f9 "L1"
+  added 3 changesets with 3 changes to 3 files (+1 heads)
+  rebasing 2:ff8d69a621f9 "L1"
   saved backup bundle to $TESTTMP/c/.hg/strip-backup/ff8d69a621f9-160fa373-backup.hg (glob)
   $ hg tglog
   @  5: 'L1'
@@ -335,7 +341,7 @@ pre-existing heads.
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files
-  nothing to rebase
+  nothing to rebase - no branching from 6dc0ea5dcf55 pulled
 
 There is two local heads and we pull a third one.
 The second local head should not confuse the `hg pull rebase`.
@@ -354,6 +360,14 @@ The second local head should not confuse
   $ cd ../c
   $ hg up 'desc(L2)'
   2 files updated, 0 files merged, 2 files removed, 0 files unresolved
+
+(rebase on latest "remote" change to remove pre-existing branching)
+
+  $ hg rebase -d 'desc(R6)'
+  rebasing 7:864e0a2d2614 "L1"
+  rebasing 8:6dc0ea5dcf55 "L2"
+  saved backup bundle to $TESTTMP/c/.hg/strip-backup/864e0a2d2614-2f72c89c-backup.hg (glob)
+
   $ hg pull --rebase
   pulling from $TESTTMP/a (glob)
   searching for changes
@@ -361,9 +375,9 @@ The second local head should not confuse
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files (+1 heads)
-  rebasing 7:864e0a2d2614 "L1"
-  rebasing 8:6dc0ea5dcf55 "L2"
-  saved backup bundle to $TESTTMP/c/.hg/strip-backup/864e0a2d2614-2f72c89c-backup.hg (glob)
+  rebasing 10:40410cfbcfce "L1"
+  rebasing 11:76f58da1b646 "L2"
+  saved backup bundle to $TESTTMP/c/.hg/strip-backup/40410cfbcfce-1aff5e0f-backup.hg (glob)
   $ hg tglog
   @  12: 'L2'
   |
@@ -391,3 +405,34 @@ The second local head should not confuse
   |
   o  0: 'C1'
   
+
+Pulling change on other pre-existing heads should not trigger a rebase
+----------------------------------------------------------------------
+
+(push the other head in "a" so that we can add changeset on it there)
+
+  $ hg push -fr 'desc(M1)' ../a
+  pushing to ../a
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files (+1 heads)
+  $ cd ../a
+  $ hg up 'desc(M1)'
+  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo M2 > M2
+  $ hg commit -Am M2
+  adding M2
+  $ cd ../c
+
+Pulling does not create branching, so we do not rebase.
+
+  $ hg pull --rebase
+  pulling from $TESTTMP/a (glob)
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  nothing to rebase - no branching from 590d79f77016 pulled


More information about the Mercurial-devel mailing list