Patchwork [2,of,2] rebase: perform update through the 'update' command

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 14, 2016, 1:15 a.m.
Message ID <74104192e7a75aee75c3.1455412533@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/13170/
State Accepted
Headers show

Comments

Pierre-Yves David - Feb. 14, 2016, 1:15 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1455410717 0
#      Sun Feb 14 00:45:17 2016 +0000
# Node ID 74104192e7a75aee75c37e40f115a0f448153190
# Parent  0842ac1829bbc270e9e73cce5ccc2781d25e19a8
# Available At http://hg.netv6.net/marmoute-wip/mercurial/
#              hg pull http://hg.netv6.net/marmoute-wip/mercurial/ -r 74104192e7a7
rebase: perform update through the 'update' command

The update logic have grow more and more complicated over time (eg bookmark
movement, new destination logic, warning on other head, etc). The rebase
extension was reimplementing its own basic version of update to be used by 'hg
pull --rebase'. We remove the custom code and use a combination of higher level
functions.

A test is added to check that the update is properly warning about other branch
heads.
Martin von Zweigbergk - Feb. 14, 2016, 7:14 a.m.
On Sat, Feb 13, 2016 at 5:15 PM, Pierre-Yves David
<pierre-yves.david@ens-lyon.org> wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1455410717 0
> #      Sun Feb 14 00:45:17 2016 +0000
> # Node ID 74104192e7a75aee75c37e40f115a0f448153190
> # Parent  0842ac1829bbc270e9e73cce5ccc2781d25e19a8
> # Available At http://hg.netv6.net/marmoute-wip/mercurial/
> #              hg pull http://hg.netv6.net/marmoute-wip/mercurial/ -r 74104192e7a7
> rebase: perform update through the 'update' command

Pushed to the clowncopter, thanks!

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -14,11 +14,11 @@  For more information:
 https://mercurial-scm.org/wiki/RebaseExtension
 '''
 
 from mercurial import hg, util, repair, merge, cmdutil, commands, bookmarks
 from mercurial import extensions, patch, scmutil, phases, obsolete, error
-from mercurial import copies, repoview, revset
+from mercurial import copies, destutil, repoview, revset
 from mercurial.commands import templateopts
 from mercurial.node import nullrev, nullid, hex, short
 from mercurial.lock import release
 from mercurial.i18n import _
 import os, errno
@@ -1143,11 +1143,10 @@  def pullrebase(orig, ui, repo, *args, **
             if opts.get('update'):
                 del opts['update']
                 ui.debug('--update and --rebase are not compatible, ignoring '
                          'the update flag\n')
 
-            movemarkfrom = repo['.'].node()
             revsprepull = len(repo)
             origpostincoming = commands.postincoming
             def _dummy(*args, **kwargs):
                 pass
             commands.postincoming = _dummy
@@ -1164,20 +1163,15 @@  def pullrebase(orig, ui, repo, *args, **
                 # positional argument from pull conflicts with rebase's own
                 # --source.
                 if 'source' in opts:
                     del opts['source']
                 if 1 == rebase(ui, repo, **opts):
-                    # nothing to rebase
-                    branch = repo[None].branch()
-                    dest = repo[branch].rev()
-                    if dest != repo['.'].rev():
-                        # there was nothing to rebase we force an update
-                        hg.update(repo, dest)
-                        if bookmarks.update(repo, [movemarkfrom],
-                                            repo['.'].node()):
-                            ui.status(_("updating bookmark %s\n")
-                                      % repo._activebookmark)
+                    rev, _a, _b = destutil.destupdate(repo)
+                    if rev != repo['.'].rev(): # we could update
+                        # not passing argument to get the bare update behavior
+                        # with warning and trumpets
+                        commands.update(ui, repo)
         finally:
             release(lock, wlock)
     else:
         if opts.get('tool'):
             raise error.Abort(_('--tool can only be used with --rebase'))
diff --git a/tests/test-rebase-pull.t b/tests/test-rebase-pull.t
--- a/tests/test-rebase-pull.t
+++ b/tests/test-rebase-pull.t
@@ -264,5 +264,48 @@  pull --rebase only update if there is no
   |
   o  1: 'C2'
   |
   o  0: 'C1'
   
+
+pull --rebase update (no rebase) use proper update:
+
+- warn about other head.
+
+  $ cd ../a
+  $ echo R6 > R6
+  $ hg ci -Am R6
+  adding R6
+  $ cd ../c
+  $ hg up 'desc(R5)'
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ 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 (+1 heads)
+  nothing to rebase - working directory parent is already an ancestor of destination 65bc164c1d9b
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  1 other heads for branch "default"
+  $ hg tglog
+  @  9: 'R6'
+  |
+  | o  8: 'L2'
+  | |
+  | o  7: 'L1'
+  |/
+  o  6: 'R5'
+  |
+  o  5: 'R4'
+  |
+  o  4: 'R3'
+  |
+  o  3: 'R2'
+  |
+  o  2: 'R1'
+  |
+  o  1: 'C2'
+  |
+  o  0: 'C1'
+