ilist: added --order to sort by date (fixes #82a)
authorDmitriy Morozov <dmitriy@mrzv.org>
Fri, 15 Apr 2011 21:37:16 -0700
changeset 57 6c388fe11dcc
parent 56 bc4b0df08e0d
child 58 f44b6f1f2115
ilist: added --order to sort by date (fixes #82a)
.issues/82aa4838dbeb6254/new/1259359374.M75010P29785Q1.vlan-laptop
.issues/82aa4838dbeb6254/new/1302928546.M969937P4447Q1.vine
README
artemis.py
--- a/.issues/82aa4838dbeb6254/new/1259359374.M75010P29785Q1.vlan-laptop	Tue Apr 05 18:21:38 2011 -0700
+++ b/.issues/82aa4838dbeb6254/new/1259359374.M75010P29785Q1.vlan-laptop	Fri Apr 15 21:37:16 2011 -0700
@@ -1,8 +1,9 @@
 From: Andrey Vlasovskikh <andrey.vlasovskikh@gmail.com>
 Date: Sat, 28 Nov 2009 00:45:23
-State: new
+State: resolved
 Subject: Results of ilist appear to be unsorted
 Message-Id: <82aa4838dbeb6254-0-artemis@vlan-laptop>
+resolution: fixed
 
 I guess the results of `hg ilist` are listed in the same order as issues'
 directory names returned by `glob.glob`.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.issues/82aa4838dbeb6254/new/1302928546.M969937P4447Q1.vine	Fri Apr 15 21:37:16 2011 -0700
@@ -0,0 +1,7 @@
+From: Dmitriy Morozov <dmitriy@mrzv.org>
+Date: Fri, 15 Apr 2011 21:35:46 -0700
+Subject: changed properties (state=resolved, resolution=fixed)
+Message-Id: <82aa4838dbeb6254-9089359c47792ef9-artemis@vine>
+References: <82aa4838dbeb6254-0-artemis@vlan-laptop>
+In-Reply-To: <82aa4838dbeb6254-0-artemis@vlan-laptop>
+
--- a/README	Tue Apr 05 18:21:38 2011 -0700
+++ b/README	Fri Apr 15 21:37:16 2011 -0700
@@ -26,7 +26,7 @@
 -----
 
 In the ``[extensions]`` section of your ``~/.hgrc`` add::
-    
+
     artemis = /path/to/artemis.py
 
 Optionally, provide a section ``[artemis]``, and specify an alternative path for
@@ -43,7 +43,7 @@
 
     # hg iadd
     ... enter some text in an editor ...
-    Added new issue 907ab57e04502afd 
+    Added new issue 907ab57e04502afd
 
     # hg ilist
     907ab57e04502afd (  0) [new]: New issue
@@ -56,18 +56,18 @@
     State: new
 
     Detailed description.
-    
+
     ----------------------------------------------------------------------
 
 Add a comment to the issue::
-    
+
     # hg iadd 907
     ... enter the comment text
     ======================================================================
     From: ...
     [snip]
     Detailed description.
-    
+
     ----------------------------------------------------------------------
     Comments:
       1: [dmitriy] Some comment
@@ -81,7 +81,7 @@
     From: ...
     [snip]
     Detailed description.
-    
+
     ----------------------------------------------------------------------
     Comments:
       1: [dmitriy] Some comment
@@ -95,7 +95,7 @@
     From: ...
     [snip]
     Detailed description.
-    
+
     ----------------------------------------------------------------------
     Comments:
       1: [dmitriy] Some comment
@@ -149,18 +149,22 @@
         list all issues (not just the `new` ones)
 
     `-p`, `--property`
-        list issues with specific property values, e.g. 
+        list issues with specific property values, e.g.
         ``-p state=resolved -p category=documentation``;
         if no property value is provided (e.g. ``-p category``), lists all
         possible values for that property (among the issues that satisfy the
         rest of the criteria)
 
+    `-o`, `--order`
+        order of the issues; choices: "new" (date submitted), "latest" (date of
+        the most recent message)
+
     `-d`, `--date`
         restrict to issues matching the given date, e.g. ``-d ">1/1/2008"``
 
     `-f`, `--filter`
         restrict to a predefined filter, see Filters_ below
-   
+
 
 `ishow` ``[ID] [COMMENT]``
     Show an issue or a comment.
--- a/artemis.py	Tue Apr 05 18:21:38 2011 -0700
+++ b/artemis.py	Fri Apr 15 21:37:16 2011 -0700
@@ -32,6 +32,10 @@
     match_date, date_match = False, lambda x: True
     if opts['date']:
         match_date, date_match = True, util.matchdate(opts['date'])
+    order = 'new'
+    if opts['order']:
+        order = opts['order']
+
 
     # Find issues
     issues_dir = ui.config('artemis', 'issues', default = default_issues_dir)
@@ -57,6 +61,7 @@
     list_properties_dict = {}
     properties += filter(lambda p: len(p) > 1, cmd_properties)
 
+    subjects = []
     for issue in issues:
         mbox = mailbox.Maildir(issue, factory=mailbox.MaildirMessage)
         root = _find_root_key(mbox)
@@ -72,15 +77,20 @@
         if match_date and not date_match(util.parsedate(mbox[root]['date'])[0]): continue
 
         if not list_properties:
-            ui.write("%s (%3d) [%s]: %s\n" % (issue[len(issues_path)+1:], # +1 for trailing /
-                                              len(mbox)-1,                # number of replies (-1 for self)
-                                              _status_msg(mbox[root]),
-                                              mbox[root]['Subject']))
+            subjects.append(("%s (%3d) [%s]: %s\n" % (issue[len(issues_path)+1:], # +1 for trailing /
+                                                      len(mbox)-1,                # number of replies (-1 for self)
+                                                      _status_msg(mbox[root]),
+                                                      mbox[root]['Subject']),
+                             _find_mbox_date(mbox, root, order)))
         else:
             for lp in list_properties:
                 if lp in mbox[root]:    list_properties_dict.setdefault(lp, set()).add(mbox[root][lp])
 
-    if list_properties:
+    if not list_properties:
+        subjects.sort(lambda (s1,d1),(s2,d2): cmp(d2,d1))
+        for s,d in subjects:
+            ui.write(s)
+    else:
         for lp in list_properties_dict.keys():
             ui.write("%s:\n" % lp)
             for value in sorted(list_properties_dict[lp]):
@@ -202,7 +212,7 @@
     issue, id = _find_issue(ui, repo, id)
     if not issue:
         return ui.warn('No such issue\n')
-    
+
     issues_dir = ui.config('artemis', 'issues', default = default_issues_dir)
     _create_missing_dirs(os.path.join(repo.root, issues_dir), issue)
 
@@ -340,6 +350,14 @@
     keys.sort(lambda k1,k2: -(k1 == root) or cmp(util.parsedate(mbox[k1]['date']), util.parsedate(mbox[k2]['date'])))
     return keys
 
+def _find_mbox_date(mbox, root, order):
+    if order == 'latest':
+        keys = _order_keys_date(mbox)
+        msg = mbox[keys[-1]]
+    else:   # new
+        msg = mbox[root]
+    return util.parsedate(msg['date'])
+
 def _random_id():
     return "%x" % random.randint(2**63, 2**64-1)
 
@@ -409,6 +427,7 @@
                    'list all issues (by default only those with state new)'),
                   ('p', 'property', [],
                    'list issues with specific field values (e.g., -p state=fixed); lists all possible values of a property if no = sign'),
+                  ('o', 'order', 'new', 'order of the issues; choices: "new" (date submitted), "latest" (date of the last message)'),
                   ('d', 'date', '', 'restrict to issues matching the date (e.g., -d ">12/28/2007)"'),
                   ('f', 'filter', '', 'restrict to pre-defined filter (in %s/%s*)' % (default_issues_dir, filter_prefix))],
                  _('hg ilist [OPTIONS]')),