commit: add a way to return more information from the chunkselector
authorLaurent Charignon <lcharignon@fb.com>
Mon, 30 Nov 2015 16:35:21 -0800
changeset 27155 8d3c5797a175
parent 27154 3bc7919fb215
child 27156 55fa7c3900ae
commit: add a way to return more information from the chunkselector Before this patch, the chunkselector for record or crecord was used to return the list of hunks that were selected by the user. The goal of this series is to reintroduce the toggle amend feature for crecord. To do so, we need to be able to return more than just the selected hunks from the chunkselector but also the information: is amend mode toggled. This patch adds a new return value for chunkselectors that will be used to implement the toggle amend feature in crecord.
mercurial/cmdutil.py
mercurial/crecord.py
mercurial/patch.py
--- a/mercurial/cmdutil.py	Sat Nov 21 17:40:26 2015 +0200
+++ b/mercurial/cmdutil.py	Mon Nov 30 16:35:21 2015 -0800
@@ -70,11 +70,11 @@
     testfile = ui.config('experimental', 'crecordtest', None)
     oldwrite = setupwrapcolorwrite(ui)
     try:
-        newchunks = filterchunks(ui, originalhunks, usecurses, testfile,
-                                 operation)
+        newchunks, newopts = filterchunks(ui, originalhunks, usecurses,
+                                          testfile, operation)
     finally:
         ui.write = oldwrite
-    return newchunks
+    return newchunks, newopts
 
 def dorecord(ui, repo, commitfunc, cmdsuggest, backupall,
             filterfn, *pats, **opts):
@@ -121,9 +121,10 @@
 
         # 1. filter patch, so we have intending-to apply subset of it
         try:
-            chunks = filterfn(ui, originalchunks)
+            chunks, newopts = filterfn(ui, originalchunks)
         except patch.PatchError as err:
             raise error.Abort(_('error parsing patch: %s') % err)
+        opts.update(newopts)
 
         # We need to keep a backup of files that have been newly added and
         # modified during the recording process because there is a previous
@@ -3201,7 +3202,7 @@
 
         try:
 
-            chunks = recordfilter(repo.ui, originalchunks)
+            chunks, opts = recordfilter(repo.ui, originalchunks)
             if reversehunks:
                 chunks = patch.reversehunks(chunks)
 
--- a/mercurial/crecord.py	Sat Nov 21 17:40:26 2015 +0200
+++ b/mercurial/crecord.py	Mon Nov 30 16:35:21 2015 -0800
@@ -454,7 +454,7 @@
     uiheaders = [uiheader(h) for h in headers]
     # let user choose headers/hunks/lines, and mark their applied flags
     # accordingly
-    chunkselector(ui, uiheaders)
+    ret = chunkselector(ui, uiheaders)
     appliedhunklist = []
     for hdr in uiheaders:
         if (hdr.applied and
@@ -472,7 +472,7 @@
                 else:
                     fixoffset += hnk.removed - hnk.added
 
-    return appliedhunklist
+    return (appliedhunklist, ret)
 
 def gethw():
     """
@@ -501,6 +501,7 @@
         raise error.Abort(chunkselector.initerr)
     # ncurses does not restore signal handler for SIGTSTP
     signal.signal(signal.SIGTSTP, f)
+    return chunkselector.opts
 
 def testdecorator(testfn, f):
     def u(*args, **kwargs):
@@ -521,6 +522,7 @@
         while True:
             if chunkselector.handlekeypressed(testcommands.pop(0), test=True):
                 break
+    return chunkselector.opts
 
 class curseschunkselector(object):
     def __init__(self, headerlist, ui):
@@ -528,6 +530,7 @@
         self.headerlist = patch(headerlist)
 
         self.ui = ui
+        self.opts = {}
 
         self.errorstr = None
         # list of all chunks
--- a/mercurial/patch.py	Sat Nov 21 17:40:26 2015 +0200
+++ b/mercurial/patch.py	Mon Nov 30 16:35:21 2015 -0800
@@ -1106,8 +1106,8 @@
                         applied[newhunk.filename()].append(newhunk)
             else:
                 fixoffset += chunk.removed - chunk.added
-    return sum([h for h in applied.itervalues()
-               if h[0].special() or len(h) > 1], [])
+    return (sum([h for h in applied.itervalues()
+               if h[0].special() or len(h) > 1], []), {})
 class hunk(object):
     def __init__(self, desc, num, lr, context):
         self.number = num