Patrick Mézard avatar Patrick Mézard committed b816dc9

Display patches in reverse chronological order

Comments (0)

Files changed (1)

   paths = mailbox1_path;mailbox_path2
-import mailbox, os, re
+import email, mailbox, os, re, time
 from mercurial import commands, hg, util, extensions, tempfile
 from mercurial.i18n import gettext, _
     def __hash__(self):
         return hash(
+    def date(self):
+        d = email.utils.parsedate(self.msg['Date'])
+        return time.mktime(d)
 def listmessages(paths):
     for path in paths:
         mbox = mailbox.mbox(path, create=False)
     ui.status(_('%d patches imported\n') % len(imported))
 def makematcher(patterns):
-    """Return a matcher function match(intro, patches) returning True
-    if the patch group matches the set of 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
+        return util.always
     regexps = [re.compile(p, re.I) for p in patterns]
-    def match(intro, patches):
+    def match(group):
+        intro, patches = group
         text = [intro.title]
         text += [p.title for p in patches]
         text = '\n'.join(text)
         raise util.Abort(_('no mailbox path configured'))
     matcher = makematcher(patterns)
-    groups = []
+    selecteds = []
     stop = False
-    for intro, patches in listgroups(paths):
-        if not matcher(intro, patches):
-            continue
+    groups = filter(matcher, listgroups(paths))
+    def cmpgroup(a, b):
+        return -cmp(a[1][0].date(), b[1][0].date())
+    groups.sort(cmpgroup)
+    for intro, patches in groups:
         if intro:
             ui.status('%s\n' % intro.subject)
             for p in patches:
                         ui.write(l.strip(), '\n')
             if r == _('i'):
-                groups.append(patches)
+                selecteds.append(patches)
             elif r == _('d'):
                 stop = True
             elif r == _('q'):
         if stop:
-    importpatches(ui, repo, groups)
+    importpatches(ui, repo, selecteds)
 cmdtable = {}
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
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.