Commits

Patrick Mézard committed 3ef05fe

Let patch groups be filtered by regular expressions

Comments (0)

Files changed (1)

             imported.append(name)
     ui.status(_('%d patches imported\n') % len(imported))
 
-def mimport(ui, repo, **opts):
+def makematcher(patterns):
+    """Return a matcher function match(intro, patches) returning True
+    if the patch group matches the set of patterns.
+    """
+    if not patterns:
+        return lambda intro, patches: True
+
+    regexps = [re.compile(p, re.I) for p in patterns]
+    
+    def match(intro, patches):
+        text = [intro.title]
+        text += [p.title for p in patches]
+        text = '\n'.join(text)
+        for r in regexps:
+            if not r.search(text):
+                return False
+        return True
+
+    return match
+
+def mimport(ui, repo, *patterns, **opts):
     """qimport patches from mailboxes
 
-    You will be prompted for whether to qimport items from every patch group.
-    For each query, the following responses are possible:
+    You will be prompted for whether to qimport items from every patch
+    group found in configured mailboxes (see [mbox] section for
+    details). If patterns are passed they will be used to filter out
+    patch groups not matching either of them. For each query, the
+    following responses are possible:
 
     y - skip this patch group
     i - qimport this patch group
     if not paths:
         raise util.Abort(_('no mailbox path configured'))
 
+    matcher = makematcher(patterns)
     groups = []
     stop = False
     for intro, patches in listgroups(paths):
+        if not matcher(intro, patches):
+            continue
         if intro:
             ui.status('%s\n' % intro.subject)
             for p in patches:
     except KeyError:
         return
 
-    cmdtable['mimport'] = (mimport, [], _('hg mimport'))
+    cmdtable['mimport'] = (mimport, [], _('hg mimport PATTERN...'))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.