[PATCH 1 of 4] prompt: kill matchflags

Kirill Smelkov kirr at mns.spb.ru
Thu Dec 27 07:48:36 CST 2007


# HG changeset patch
# User Kirill Smelkov <kirr at mns.spb.ru>
# Date 1198762398 -10800
# Node ID a1395546023ce2c1f4efa28e19c6348ee0b8efc8
# Parent  6ba5ecc27d3360af22f9f0540a22cd461b4411a5
prompt: kill matchflags

rationale: Python already lets one to embed RE flags directly in a regex, which
rationale: is a much nicer way to do things:

(?iLmsux)
        (One or more letters from the set "i", "L", "m", "s", "u", "x".)
        ...

matchflags was introduced in 67afecb8d6cc, and the record extension is the only
user. I've killed matchflag, and adjusted record code appropriately.

spot-by: Matt Mackall <mpm at selenic.com>

diff --git a/hgext/record.py b/hgext/record.py
--- a/hgext/record.py
+++ b/hgext/record.py
@@ -247,8 +247,8 @@ def filterpatch(ui, chunks):
         if resp_file[0] is not None:
             return resp_file[0]
         while True:
-            r = (ui.prompt(query + _(' [Ynsfdaq?] '), '[Ynsfdaq?]?$',
-                           matchflags=re.I) or 'y').lower()
+            r = (ui.prompt(query + _(' [Ynsfdaq?] '), '(?i)[Ynsfdaq?]?$')
+                 or 'y').lower()
             if r == '?':
                 c = record.__doc__.find('y - record this change')
                 for l in record.__doc__[c:].splitlines():
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -410,12 +410,16 @@ class ui(object):
             line = line[:-1]
         return line
 
-    def prompt(self, msg, pat=None, default="y", matchflags=0):
+    def prompt(self, msg, pat=None, default="y"):
+        """Prompt user with msg, read his answer, and ensure it matches pat
+
+        If not interactive -- the default is returned
+        """
         if not self.interactive: return default
         while True:
             try:
                 r = self._readline(msg + ' ')
-                if not pat or re.match(pat, r, matchflags):
+                if not pat or re.match(pat, r):
                     return r
                 else:
                     self.write(_("unrecognized response\n"))


More information about the Mercurial-devel mailing list