[PATCH 1 of 2] commit: add a way to return more information from the chunkselector

Laurent Charignon lcharignon at fb.com
Mon Nov 30 18:52:50 CST 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1448930121 28800
#      Mon Nov 30 16:35:21 2015 -0800
# Node ID 4f7fd866d3a9bbbafef3999a4ead82c177335fe4
# Parent  2ce00de5cc0e88198cc37e31743f2aabd50568e7
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.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -70,11 +70,11 @@ def recordfilter(ui, originalhunks, oper
     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 @@ def dorecord(ui, repo, commitfunc, cmdsu
 
         # 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
@@ -3196,7 +3197,7 @@ def _performrevert(repo, parents, ctx, a
 
         try:
 
-            chunks = recordfilter(repo.ui, originalchunks)
+            chunks, opts = recordfilter(repo.ui, originalchunks)
             if reversehunks:
                 chunks = patch.reversehunks(chunks)
 
diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -454,7 +454,7 @@ def filterpatch(ui, chunks, chunkselecto
     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 @@ def filterpatch(ui, chunks, chunkselecto
                 else:
                     fixoffset += hnk.removed - hnk.added
 
-    return appliedhunklist
+    return (appliedhunklist, ret)
 
 def gethw():
     """
@@ -501,6 +501,7 @@ def chunkselector(ui, headerlist):
         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 @@ def testchunkselector(testfn, ui, header
         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 @@ class curseschunkselector(object):
         self.headerlist = patch(headerlist)
 
         self.ui = ui
+        self.opts = {}
 
         self.errorstr = None
         # list of all chunks
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1106,8 +1106,8 @@ the hunk is left unchanged.
                         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


More information about the Mercurial-devel mailing list