changeset 1867:c9cacc62fa17

patch: import topic from patch header If the used Mercurial supports it, we import topic from patch headers.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Thu, 08 Oct 2015 20:43:15 -0700
parents 13fc93fb7fbe
children 5cdd5e0a421c
files src/topic/__init__.py tests/test-topic.t
diffstat 2 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/topic/__init__.py	Thu Oct 08 20:42:26 2015 -0700
+++ b/src/topic/__init__.py	Thu Oct 08 20:43:15 2015 -0700
@@ -22,6 +22,7 @@
 from mercurial import merge
 from mercurial import namespaces
 from mercurial import obsolete
+from mercurial import patch
 from mercurial import phases
 from mercurial import util
 
@@ -219,6 +220,10 @@
         return 'EXP-Topic %s'  % topic
     return None
 
+def _importtopic(repo, patchdata, extra, opts):
+    if 'topic' in patchdata:
+        extra['topic'] = patchdata['topic']
+
 extensions.afterloaded('rebase', _fixrebase)
 
 entry = extensions.wrapcommand(commands.table, 'commit', commitwrap)
@@ -233,3 +238,8 @@
 if util.safehasattr(cmdutil, 'extraexport'):
     cmdutil.extraexport.append('topic')
     cmdutil.extraexportmap['topic'] = _exporttopic
+if util.safehasattr(cmdutil, 'extrapreimport'):
+    cmdutil.extrapreimport.append('topic')
+    cmdutil.extrapreimportmap['topic'] = _importtopic
+if util.safehasattr(patch, 'patchheadermap'):
+    patch.patchheadermap.append(('EXP-Topic', 'topic'))
--- a/tests/test-topic.t	Thu Oct 08 20:42:26 2015 -0700
+++ b/tests/test-topic.t	Thu Oct 08 20:43:15 2015 -0700
@@ -157,6 +157,24 @@
    file alpha
    topic work
   +narf!!!
+
+Import
+
+  $ hg -R pinky export > narf.diff
+  $ hg -R pinky --config extensions.strip= strip .
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  saved backup bundle to $TESTTMP/pinky/.hg/strip-backup/7c34953036d6-1ff3bae2-backup.hg (glob)
+  $ hg -R pinky import narf.diff
+  applying narf.diff
+  $ hg -R pinky log -r .
+  changeset:   6:7c34953036d6
+  tag:         tip
+  topic:       narf
+  parent:      4:fb147b0b417c
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     narf!
+  
 Now that we've pushed to brain, the work done on narf is no longer a
 draft, so we won't see that topic name anymore: