[PATCH 1 of 3] record: add an operation arguments to customize recording ui

Laurent Charignon lcharignon at fb.com
Wed May 27 18:43:41 CDT 2015

# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1432766964 25200
#      Wed May 27 15:49:24 2015 -0700
# Node ID 99386da5b5499f7480f59d898ce46363bf9d6342
# Parent  6ac860f700b5cfeda232d5305963047696b869ca
record: add an operation arguments to customize recording ui

This patch is part of a series of patches to change the recording ui to reflect
the operation currently running (commit, shelve, revert ...).
This patch adds a new argument to the recording function to reflect in the UI
what operation we are running.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -45,7 +45,7 @@
     setattr(ui, 'write', wrap)
     return oldwrite
-def filterchunks(ui, originalhunks, usecurses, testfile):
+def filterchunks(ui, originalhunks, usecurses, testfile, operation=None):
     if usecurses:
         if testfile:
             recordfn = crecordmod.testdecorator(testfile,
@@ -53,17 +53,23 @@
             recordfn = crecordmod.chunkselector
-        return crecordmod.filterpatch(ui, originalhunks, recordfn)
+        return crecordmod.filterpatch(ui, originalhunks, recordfn, operation)
-        return patch.filterpatch(ui, originalhunks)
-def recordfilter(ui, originalhunks):
+        return patch.filterpatch(ui, originalhunks, operation)
+def recordfilter(ui, originalhunks, operation=None):
+    """ Prompts the user to filter the originalhunks and return a list of
+    selected hunks.
+    *operation* is used for ui purposes to indicate the user
+    what kind of filtering they are doing: reverting, commiting, shelving, etc.
+    """
     usecurses =  ui.configbool('experimental', 'crecord', False)
     testfile = ui.config('experimental', 'crecordtest', None)
     oldwrite = setupwrapcolorwrite(ui)
-        newchunks = filterchunks(ui, originalhunks, usecurses, testfile)
+        newchunks = filterchunks(ui, originalhunks, usecurses, testfile,
+                                 operation)
         ui.write = oldwrite
     return newchunks
diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -425,7 +425,7 @@
     def __repr__(self):
         return '<hunk %r@%d>' % (self.filename(), self.fromline)
-def filterpatch(ui, chunks, chunkselector):
+def filterpatch(ui, chunks, chunkselector, operation=None):
     """interactively filter patch chunks into applied-only chunks"""
     chunks = list(chunks)
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -948,7 +948,7 @@
     def __repr__(self):
         return '<hunk %r@%d>' % (self.filename(), self.fromline)
-def filterpatch(ui, headers):
+def filterpatch(ui, headers, operation=None):
     """Interactively filter patch chunks into applied-only chunks"""
     def prompt(skipfile, skipall, query, chunk):

More information about the Mercurial-devel mailing list