changeset 1892:b1fadc089b82

update: change default update destination to take topic in account When within a branch update to ngtip(branch). When within a topic update to the top topic.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Sun, 13 Mar 2016 12:29:43 +0000
parents 077c40f206d1
children 9d1157fcdc6c
files src/topic/destination.py tests/test-topic-dest.t
diffstat 2 files changed, 195 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/topic/destination.py	Sun Mar 13 13:07:54 2016 +0000
+++ b/src/topic/destination.py	Sun Mar 13 12:29:43 2016 +0000
@@ -2,6 +2,7 @@
 from mercurial import util
 from mercurial import destutil
 from mercurial import extensions
+from mercurial import bookmarks
 from mercurial.i18n import _
 
 def _destmergebranch(orig, repo, action='merge', sourceset=None, onheadcheck=True):
@@ -42,6 +43,18 @@
     else:
         return orig(repo)
 
+def _destupdatetopic(repo, clean, check):
+    """decide on an update destination from current topic"""
+    movemark = node = None
+    topic = repo.currenttopic
+    revs = repo.revs('.::topic("%s")' % topic)
+    if not revs:
+        return None, None, None
+    node = revs.last()
+    if bookmarks.isactivewdirparent(repo):
+        movemark = repo['.'].node()
+    return node, movemark, None
+
 def setupdest():
     if util.safehasattr(destutil, '_destmergebranch'):
         extensions.wrapfunction(destutil, '_destmergebranch', _destmergebranch)
@@ -50,6 +63,10 @@
             # logic not shared with merge yet < hg-3.8
             and not util.safehasattr(rebase, '_definesets')):
         extensions.wrapfunction(rebase, '_destrebase', _destmergebranch)
+    if util.safehasattr(destutil, 'destupdatesteps'):
+        bridx = destutil.destupdatesteps.index('branch')
+        destutil.destupdatesteps.insert(bridx, 'topic')
+        destutil.destupdatestepmap['topic'] = _destupdatetopic
 
 def ngtip(repo, branch, all=False):
     """tip new generation"""
--- a/tests/test-topic-dest.t	Sun Mar 13 13:07:54 2016 +0000
+++ b/tests/test-topic-dest.t	Sun Mar 13 12:29:43 2016 +0000
@@ -255,3 +255,181 @@
   |
   o  0 () c_alpha
   
+
+Default destination for update
+===============================
+
+initial setup
+
+  $ hg up elephant
+  switching to topic elephant
+  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo arthur >> jungle
+  $ hg ci -m arthur
+  created new head
+  $ echo pompadour >> jungle
+  $ hg ci -m pompadour
+  created new head
+  $ hg up 'roots(all())'
+  0 files updated, 0 files merged, 6 files removed, 0 files unresolved
+  $ hg log -G
+  o  15 (elephant) pompadour
+  |
+  o  14 (elephant) arthur
+  |
+  | o    13 (monkey) merge with default
+  | |\
+  o---+  12 (elephant) babar
+   / /
+  | o  11 () c_zeta
+  | |
+  o |  10 (monkey) Huc
+  | |
+  o |  8 (monkey) zephir
+  |/
+  o  6 () c_epsilon
+  |
+  o  3 () c_delta
+  |
+  o  2 () c_gamma
+  |
+  o  1 () c_beta
+  |
+  @  0 () c_alpha
+  
+
+testing default destination on a branch
+
+  $ hg up
+  5 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg log -G
+  o  15 (elephant) pompadour
+  |
+  o  14 (elephant) arthur
+  |
+  | o    13 (monkey) merge with default
+  | |\
+  o---+  12 (elephant) babar
+   / /
+  | @  11 () c_zeta
+  | |
+  o |  10 (monkey) Huc
+  | |
+  o |  8 (monkey) zephir
+  |/
+  o  6 () c_epsilon
+  |
+  o  3 () c_delta
+  |
+  o  2 () c_gamma
+  |
+  o  1 () c_beta
+  |
+  o  0 () c_alpha
+  
+
+extra setup for topic
+(making sure tip is not the topic)
+
+  $ hg up 'desc(c_zeta)'
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ echo 'eta' >> 'eta'
+  $ hg add 'eta'
+  $ hg commit -m 'c_eta'
+  $ hg log -G
+  @  16 () c_eta
+  |
+  | o  15 (elephant) pompadour
+  | |
+  | o  14 (elephant) arthur
+  | |
+  +---o  13 (monkey) merge with default
+  | | |
+  | o |  12 (elephant) babar
+  |/ /
+  o |  11 () c_zeta
+  | |
+  | o  10 (monkey) Huc
+  | |
+  | o  8 (monkey) zephir
+  |/
+  o  6 () c_epsilon
+  |
+  o  3 () c_delta
+  |
+  o  2 () c_gamma
+  |
+  o  1 () c_beta
+  |
+  o  0 () c_alpha
+  
+
+Testing default destination for topic
+
+  $ hg up 'roots(topic(elephant))'
+  switching to topic elephant
+  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg up
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg log -G
+  o  16 () c_eta
+  |
+  | @  15 (elephant) pompadour
+  | |
+  | o  14 (elephant) arthur
+  | |
+  +---o  13 (monkey) merge with default
+  | | |
+  | o |  12 (elephant) babar
+  |/ /
+  o |  11 () c_zeta
+  | |
+  | o  10 (monkey) Huc
+  | |
+  | o  8 (monkey) zephir
+  |/
+  o  6 () c_epsilon
+  |
+  o  3 () c_delta
+  |
+  o  2 () c_gamma
+  |
+  o  1 () c_beta
+  |
+  o  0 () c_alpha
+  
+
+Testing default destination for topic
+
+  $ hg up 'p1(roots(topic(elephant)))'
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg topic elephant
+  $ hg up
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg log -G
+  o  16 () c_eta
+  |
+  | @  15 (elephant) pompadour
+  | |
+  | o  14 (elephant) arthur
+  | |
+  +---o  13 (monkey) merge with default
+  | | |
+  | o |  12 (elephant) babar
+  |/ /
+  o |  11 () c_zeta
+  | |
+  | o  10 (monkey) Huc
+  | |
+  | o  8 (monkey) zephir
+  |/
+  o  6 () c_epsilon
+  |
+  o  3 () c_delta
+  |
+  o  2 () c_gamma
+  |
+  o  1 () c_beta
+  |
+  o  0 () c_alpha
+