topic: makes split keep the topic
authorBoris Feld <boris.feld@octobus.net>
Tue, 27 Jun 2017 15:21:38 +0200
changeset 2667 e7079bba383d
parent 2666 2d828f448081
child 2668 1d2c66dc4ee3
topic: makes split keep the topic Refactor split to extract the preparation of the working directory in a separate function. This helps topic wrap this function to save topic before update and restore it after preparing the working directory just before the split.
hgext3rd/evolve/__init__.py
hgext3rd/topic/__init__.py
tests/test-split.t
--- a/hgext3rd/evolve/__init__.py	Tue Jun 27 09:49:35 2017 +0200
+++ b/hgext3rd/evolve/__init__.py	Tue Jun 27 15:21:38 2017 +0200
@@ -2637,6 +2637,12 @@
     finally:
         lockmod.release(tr, lock, wlock)
 
+def presplitupdate(repo, ui, prev, ctx):
+    """prepare the working directory for a split (for topic hooking)
+    """
+    hg.update(repo, prev)
+    commands.revert(ui, repo, rev=ctx.rev(), all=True)
+
 @eh.command(
     '^split',
     [('r', 'rev', [], _("revision to split")),
@@ -2682,9 +2688,9 @@
         if bookactive is not None:
             repo.ui.status(_("(leaving bookmark %s)\n") % repo._activebookmark)
         bookmarksmod.deactivate(repo)
-        hg.update(repo, prev)
-
-        commands.revert(ui, repo, rev=r, all=True)
+
+        # Prepare the working directory
+        presplitupdate(repo, ui, prev, ctx)
 
         def haschanges():
             modified, added, removed, deleted = repo.status()[:4]
--- a/hgext3rd/topic/__init__.py	Tue Jun 27 09:49:35 2017 +0200
+++ b/hgext3rd/topic/__init__.py	Tue Jun 27 15:21:38 2017 +0200
@@ -163,6 +163,13 @@
 
     extensions.wrapfunction(cmdutil, 'buildcommittext', committextwrap)
     extensions.wrapfunction(merge, 'update', mergeupdatewrap)
+
+    try:
+        evolve = extensions.find('evolve')
+        extensions.wrapfunction(evolve, "presplitupdate", presplitupdatetopic)
+    except (KeyError, AttributeError):
+        pass
+
     cmdutil.summaryhooks.add('topic', summaryhook)
 
 
@@ -524,3 +531,18 @@
     cmdutil.extrapreimport.append('topic')
     cmdutil.extrapreimportmap['topic'] = _importtopic
     patch.patchheadermap.append(('EXP-Topic', 'topic'))
+
+## preserve topic during split
+
+def presplitupdatetopic(original, repo, ui, prev, ctx):
+    # Save topic of revision
+    topic = None
+    if util.safehasattr(ctx, 'topic'):
+        topic = ctx.topic()
+
+    # Update the working directory
+    original(repo, ui, prev, ctx)
+
+    # Restore the topic if need
+    if topic:
+        _changecurrenttopic(repo, topic)
--- a/tests/test-split.t	Tue Jun 27 09:49:35 2017 +0200
+++ b/tests/test-split.t	Tue Jun 27 15:21:38 2017 +0200
@@ -385,3 +385,84 @@
   $ hg commit -m "empty"
   $ hg split
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+Check that split keeps the right topic
+
+  $ hg up -r tip
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+Add topic to the hgrc
+
+  $ echo "[extensions]" >> $HGRCPATH
+  $ echo "topic=$(echo $(dirname $TESTDIR))/hgext3rd/topic/" >> $HGRCPATH
+  $ hg topic mytopic
+  $ echo babar > babar
+  $ echo celeste > celeste
+  $ hg add babar celeste
+  $ hg commit -m "Works on mytopic" babar celeste
+  $ hg summary
+  parent: 21:615c369f47f0 tip
+   Works on mytopic
+  branch: new-branch
+  commit: 2 unknown (clean)
+  update: (current)
+  phases: 9 draft
+  topic:  mytopic
+
+Split it
+
+  $ hg split << EOF
+  > Y
+  > Y
+  > N
+  > Y
+  > Y
+  > Y
+  > EOF
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  adding babar
+  adding celeste
+  diff --git a/babar b/babar
+  new file mode 100644
+  examine changes to 'babar'? [Ynesfdaq?] Y
+  
+  @@ -0,0 +1,1 @@
+  +babar
+  record change 1/2 to 'babar'? [Ynesfdaq?] Y
+  
+  diff --git a/celeste b/celeste
+  new file mode 100644
+  examine changes to 'celeste'? [Ynesfdaq?] N
+  
+  Done splitting? [yN] Y
+  diff --git a/celeste b/celeste
+  new file mode 100644
+  examine changes to 'celeste'? [Ynesfdaq?] Y
+  
+  @@ -0,0 +1,1 @@
+  +celeste
+  record this change to 'celeste'? [Ynesfdaq?] Y
+  
+  no more change to split
+
+Check that the topic is still here
+
+  $ hg log -r "tip~1::"
+  changeset:   22:f879ab83f991
+  branch:      new-branch
+  topic:       mytopic
+  parent:      20:89e64a2c68b3
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     split7
+  
+  changeset:   23:db75dbc1a3a6
+  branch:      new-branch
+  tag:         tip
+  topic:       mytopic
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     split8
+  
+  $ hg topic
+   * mytopic