[PATCH] mercurial/crew: Add a new -i/--isodate option to `debugstate'

Giorgos Keramidas keramida at ceid.upatras.gr
Fri Jan 11 15:37:02 CST 2008


# HG changeset patch
# User Giorgos Keramidas <keramida at ceid.upatras.gr>
# Date 1200087056 -7200
# Node ID b9fabc4f8d8f5b4a681e594f72892e759342798e
# Parent  c32d41affb68e3c1c782c1ba7df93f150301323d
Add a new -i/--isodate option to `debugstate'

The localized version of date/time displayed by the '%x %X'
format may vary depending on the current timezone setup.  When
debugstate runs with the new -i/--isodate option, it will always
display the date using '%Y-%m-%d %H:%M:%S' as the strftime format
string.  This makes debugstate output more predictable, and
easier to parse in an automated manner.

An example of the difference, when running with a Greek locale
environment on FreeBSD, is:

  $ hg debugstate | head -3
  n 664        320 01/09/08 19:56:54 .hgignore
  n 664        792 01/09/08 19:56:54 .hgsigs
  n 664        829 01/09/08 19:56:54 .hgtags
  $ hg debugstate -i | head -3
  n 664        320 2008-01-09 19:56:54 .hgignore
  n 664        792 2008-01-09 19:56:54 .hgsigs
  n 664        829 2008-01-09 19:56:54 .hgtags
  $

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -662,18 +662,22 @@ def debugsetparents(ui, repo, rev1, rev2
     finally:
         del wlock
 
-def debugstate(ui, repo):
+def debugstate(ui, repo, **opts):
     """show the contents of the current dirstate"""
+    # The default time format, for backwards compatibility.
+    timeformat = '%x %X'
+    if opts["isodate"]:
+        timeformat = '%Y-%m-%d %H:%M:%S'
     k = repo.dirstate._map.items()
     k.sort()
     for file_, ent in k:
         if ent[3] == -1:
             # Pad or slice to locale representation
-            locale_len = len(time.strftime("%x %X", time.localtime(0)))
+            locale_len = len(time.strftime(timeformat, time.localtime(0)))
             timestr = 'unset'
             timestr = timestr[:locale_len] + ' '*(locale_len - len(timestr))
         else:
-            timestr = time.strftime("%x %X", time.localtime(ent[3]))
+            timestr = time.strftime(timeformat, time.localtime(ent[3]))
         if ent[1] & 020000:
             mode = 'lnk'
         else:
@@ -2832,7 +2836,11 @@ table = {
         (debugsetparents,
          [],
          _('hg debugsetparents REV1 [REV2]')),
-    "debugstate": (debugstate, [], _('hg debugstate')),
+    "debugstate":
+        (debugstate,
+         [('i', 'isodate', None,
+           _('display dates in ISO format')),],
+         _('hg debugstate [-i]')),
     "debugwalk": (debugwalk, walkopts, _('hg debugwalk [OPTION]... [FILE]...')),
     "^diff":
         (diff,



More information about the Mercurial-devel mailing list