[PATCH 2 of 2] record: ui change for chunk reversal

Laurent Charignon lcharignon at fb.com
Fri Mar 13 19:11:24 CDT 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1426208011 25200
#      Thu Mar 12 17:53:31 2015 -0700
# Node ID 5bb2089e8531955a9a5276783efc531eadbc1318
# Parent  8d7e2655cc37ba5afacff460c3bf4407d3934adc
record: ui change for chunk reversal

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -21,7 +21,7 @@
 def parsealiases(cmd):
     return cmd.lstrip("^").split("|")
 
-def recordfilter(ui, originalhunks):
+def recordfilter(ui, originalhunks, selectionmode):
     curses_record =  ui.configbool('experimental', 'crecord', False)
     if curses_record:
         testmode_fn = ui.config('experimental', 'crecordTestMode', None)
@@ -31,10 +31,11 @@
         else:
             recordfn = crecordmod.chunkselector
 
-        return crecordmod.filterpatch(ui, originalhunks, recordfn)
+        return crecordmod.filterpatch(ui, originalhunks, recordfn,
+                                     selectionmode)
 
     else:
-        return patch.filterpatch(ui, originalhunks)
+        return patch.filterpatch(ui, originalhunks, selectionmode)
 
 def dorecord(ui, repo, commitfunc, cmdsuggest, backupall,
             filterfn, *pats, **opts):
@@ -82,7 +83,11 @@
 
         # 1. filter patch, so we have intending-to apply subset of it
         try:
-            chunks = filterfn(ui, originalchunks)
+            if reverse:
+                selectionmode = "uncommit"
+            else:
+                selectionmode = "record"
+            chunks = filterfn(ui, originalchunks, selectionmode)
         except patch.PatchError, err:
             raise util.Abort(_('error parsing patch: %s') % err)
 
diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -438,7 +438,7 @@
     def __repr__(self):
         return '<hunk %r@%d>' % (self.filename(), self.fromline)
 
-def filterpatch(ui, chunks, chunk_selector):
+def filterpatch(ui, chunks, chunk_selector, selectionmode):
     """interactively filter patch chunks into applied-only chunks"""
 
     chunks = list(chunks)
@@ -452,7 +452,7 @@
     uiheaders = [uiheader(h) for h in headers]
     # let user choose headers/hunks/lines, and mark their applied flags
     # accordingly
-    chunk_selector(ui, uiheaders)
+    chunk_selector(ui, uiheaders, selectionmode)
     appliedhunklist = []
     for hdr in uiheaders:
         if (hdr.applied and
@@ -488,13 +488,13 @@
     return h, w
 
 
-def chunkselector(ui, headerlist):
+def chunkselector(ui, headerlist, selectionmode):
     """
     curses interface to get selection of chunks, and mark the applied flags
     of the chosen chunks.
 
     """
-    chunkselector = curseschunkselector(headerlist, ui)
+    chunkselector = curseschunkselector(headerlist, ui, selectionmode)
     curses.wrapper(chunkselector.main)
 
 def testdecorator(testfn, f):
@@ -502,13 +502,13 @@
         return f(testfn, *args, **kwargs)
     return u
 
-def testchunkselector(testfn, ui, headerlist):
+def testchunkselector(testfn, ui, headerlist, selectionmode):
     """
     test interface to get selection of chunks, and mark the applied flags
     of the chosen chunks.
 
     """
-    chunkselector = curseschunkselector(headerlist, ui)
+    chunkselector = curseschunkselector(headerlist, ui, selectionmode)
     if testfn and os.path.exists(testfn):
         testf = open(testfn)
         testcommands = map(lambda x: x.rstrip('\n'), testf.readlines())
@@ -518,10 +518,10 @@
                 break
 
 class curseschunkselector(object):
-    def __init__(self, headerlist, ui):
+    def __init__(self, headerlist, ui, selectionmode):
         # put the headers into a patch object
         self.headerlist = patch(headerlist)
-
+        self.selectionmode = selectionmode
         self.ui = ui
 
         # list of all chunks
@@ -1005,7 +1005,7 @@
                         pairname="legend")
             printstring(self.statuswin,
                         " (f)old/unfold; (c)ommit applied; (q)uit; (?) help "
-                        "| [X]=hunk applied **=folded",
+                        "| [X]=hunk to %s **=folded" %(self.selectionmode),
                         pairname="legend")
         except curses.error:
             pass
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -924,7 +924,10 @@
     def __repr__(self):
         return '<hunk %r@%d>' % (self.filename(), self.fromline)
 
-def filterpatch(ui, headers):
+# selectionmode is used to inform users of what they are doing, it is one of:
+#   - record
+#   - uncommit
+def filterpatch(ui, headers, selectionmode="record"):
     """Interactively filter patch chunks into applied-only chunks"""
 
     def prompt(skipfile, skipall, query, chunk):
@@ -1054,11 +1057,12 @@
             if skipfile is None and skipall is None:
                 chunk.pretty(ui)
             if total == 1:
-                msg = _("record this change to '%s'?") % chunk.filename()
+                msg = _("%s this change to '%s'?") % (selectionmode,
+                                                     chunk.filename())
             else:
                 idx = pos - len(h.hunks) + i
-                msg = _("record change %d/%d to '%s'?") % (idx, total,
-                                                           chunk.filename())
+                msg = _("%s change %d/%d to '%s'?") % (selectionmode, idx,
+                                                      total, chunk.filename())
             r, skipfile, skipall, newpatches = prompt(skipfile,
                     skipall, msg, chunk)
             if r:
diff --git a/tests/test-commit-interactive.t b/tests/test-commit-interactive.t
--- a/tests/test-commit-interactive.t
+++ b/tests/test-commit-interactive.t
@@ -1460,7 +1460,7 @@
   +3
   +4
   +5
-  record this change to 'newfile2'? [Ynesfdaq?] y
+  uncommit this change to 'newfile2'? [Ynesfdaq?] y
   
   no changes to record
   $ hg tip
@@ -1485,7 +1485,7 @@
   +3
   +4
   +5
-  record this change to 'newfile2'? [Ynesfdaq?] n
+  uncommit this change to 'newfile2'? [Ynesfdaq?] n
   
   $ hg tip
   changeset:   31:9089f22108a3
@@ -1551,7 +1551,7 @@
    3
    4
    5
-  record change 1/2 to 'newfile2'? [Ynesfdaq?] n
+  uncommit change 1/2 to 'newfile2'? [Ynesfdaq?] n
   
   @@ -1,5 +2,6 @@
    1
@@ -1560,7 +1560,7 @@
    4
    5
   +secondline
-  record change 2/2 to 'newfile2'? [Ynesfdaq?] y
+  uncommit change 2/2 to 'newfile2'? [Ynesfdaq?] y
   
   $ hg cat -r tip newfile2
   firstline
@@ -1606,7 +1606,7 @@
    4
    5
   +secondline
-  record change 1/3 to 'newfile2'? [Ynesfdaq?] n
+  uncommit change 1/3 to 'newfile2'? [Ynesfdaq?] n
   
   diff --git a/newfile3 b/newfile3
   2 hunks, 2 lines changed
@@ -1619,7 +1619,7 @@
    3
    4
    5
-  record change 2/3 to 'newfile3'? [Ynesfdaq?] n
+  uncommit change 2/3 to 'newfile3'? [Ynesfdaq?] n
   
   @@ -1,5 +2,6 @@
    1
@@ -1628,7 +1628,7 @@
    4
    5
   +secondline
-  record change 3/3 to 'newfile3'? [Ynesfdaq?] y
+  uncommit change 3/3 to 'newfile3'? [Ynesfdaq?] y
   
   $ hg tip
   changeset:   34:35f3773303b6
@@ -1685,7 +1685,7 @@
    5
    secondline
   +lastline
-  record change 1/2 to 'newfile2'? [Ynesfdaq?] y
+  uncommit change 1/2 to 'newfile2'? [Ynesfdaq?] y
   
   diff --git a/newfile3 b/newfile3
   1 hunks, 1 lines changed


More information about the Mercurial-devel mailing list