changeset 13767:0f9282dc87f8

debugstate: add new --datesort option sorts the output lines by mtime, then by filename
author Adrian Buehlmann <adrian@cadifra.com>
date Sat, 26 Mar 2011 10:59:33 +0100
parents 627e50e9e316
children 10aea25fb519
files mercurial/commands.py tests/test-debugcomplete.t
diffstat 2 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Sat Mar 26 13:05:17 2011 +0100
+++ b/mercurial/commands.py	Sat Mar 26 10:59:33 2011 +0100
@@ -1340,11 +1340,15 @@
     finally:
         wlock.release()
 
-def debugstate(ui, repo, nodates=None):
+def debugstate(ui, repo, nodates=None, datesort=None):
     """show the contents of the current dirstate"""
     timestr = ""
     showdate = not nodates
-    for file_, ent in sorted(repo.dirstate._map.iteritems()):
+    if datesort:
+        keyfunc = lambda x: (x[1][3], x[0]) # sort by mtime, then by filename
+    else:
+        keyfunc = None # sort by filename
+    for file_, ent in sorted(repo.dirstate._map.iteritems(), key=keyfunc):
         if showdate:
             if ent[3] == -1:
                 # Pad or slice to locale representation
@@ -4512,7 +4516,8 @@
         (debugsetparents, [], _('REV1 [REV2]')),
     "debugstate":
         (debugstate,
-         [('', 'nodates', None, _('do not display the saved mtime'))],
+         [('', 'nodates', None, _('do not display the saved mtime')),
+          ('', 'datesort', None, _('sort by saved mtime'))],
          _('[OPTION]...')),
     "debugsub":
         (debugsub,
--- a/tests/test-debugcomplete.t	Sat Mar 26 13:05:17 2011 +0100
+++ b/tests/test-debugcomplete.t	Sat Mar 26 10:59:33 2011 +0100
@@ -231,7 +231,7 @@
   debugrename: rev
   debugrevspec: 
   debugsetparents: 
-  debugstate: nodates
+  debugstate: nodates, datesort
   debugsub: rev
   debugwalk: include, exclude
   debugwireargs: three, four, ssh, remotecmd, insecure