Make annotae/grep print short dates with -q/--quiet.
authorThomas Arendsen Hein <thomas@intevation.de>
Sat, 16 Feb 2008 13:33:38 +0100
changeset 6134 7b937b26adf7
parent 6133 779f2309d67a
child 6135 be91a77b7f18
Make annotae/grep print short dates with -q/--quiet. Move shortdate() from templatefilters to util to avoid code duplication.
mercurial/commands.py
mercurial/templatefilters.py
mercurial/util.py
--- a/mercurial/commands.py	Sat Feb 16 13:01:27 2008 +0100
+++ b/mercurial/commands.py	Sat Feb 16 13:33:38 2008 +0100
@@ -78,7 +78,8 @@
     detects as binary. With -a, annotate will generate an annotation
     anyway, probably with undesirable results.
     """
-    getdate = util.cachefunc(lambda x: util.datestr(x[0].date()))
+    datefunc = ui.quiet and util.shortdate or util.datestr
+    getdate = util.cachefunc(lambda x: datefunc(x[0].date()))
 
     if not pats:
         raise util.Abort(_('at least one file name or pattern required'))
@@ -1028,6 +1029,7 @@
 
     prev = {}
     def display(fn, rev, states, prevstates):
+        datefunc = ui.quiet and util.shortdate or util.datestr
         found = False
         filerevmatches = {}
         r = prev.get(fn, -1)
@@ -1044,7 +1046,7 @@
             if opts['user']:
                 cols.append(ui.shortuser(get(r)[1]))
             if opts.get('date'):
-                cols.append(util.datestr(get(r)[2]))
+                cols.append(datefunc(get(r)[2]))
             if opts['files_with_matches']:
                 c = (fn, r)
                 if c in filerevmatches:
@@ -2742,8 +2744,8 @@
          [('r', 'rev', '', _('annotate the specified revision')),
           ('f', 'follow', None, _('follow file copies and renames')),
           ('a', 'text', None, _('treat all files as text')),
-          ('u', 'user', None, _('list the author')),
-          ('d', 'date', None, _('list the date')),
+          ('u', 'user', None, _('list the author (long with -v)')),
+          ('d', 'date', None, _('list the date (short with -q)')),
           ('n', 'number', None, _('list the revision number (default)')),
           ('c', 'changeset', None, _('list the changeset')),
           ('l', 'line-number', None,
@@ -2896,8 +2898,8 @@
            _('print only filenames and revs that match')),
           ('n', 'line-number', None, _('print matching line numbers')),
           ('r', 'rev', [], _('search in given revision range')),
-          ('u', 'user', None, _('print user who committed change')),
-          ('d', 'date', None, _('list the date')),
+          ('u', 'user', None, _('list the author (long with -v)')),
+          ('d', 'date', None, _('list the date (short with -q)')),
          ] + walkopts,
          _('hg grep [OPTION]... PATTERN [FILE]...')),
     "heads":
--- a/mercurial/templatefilters.py	Sat Feb 16 13:01:27 2008 +0100
+++ b/mercurial/templatefilters.py	Sat Feb 16 13:33:38 2008 +0100
@@ -100,10 +100,6 @@
     if f == -1: return util.shortuser(author)
     return author[:f].rstrip()
 
-def shortdate(date):
-    '''turn (timestamp, tzoff) tuple into iso 8631 date.'''
-    return util.datestr(date, format='%Y-%m-%d', timezone=False)
-
 def indent(text, prefix):
     '''indent each non-empty line of text after first with prefix.'''
     lines = text.splitlines()
@@ -145,7 +141,7 @@
     "rfc822date": lambda x: util.datestr(x, "%a, %d %b %Y %H:%M:%S"),
     "rfc3339date": lambda x: util.datestr(x, "%Y-%m-%dT%H:%M:%S", True, "%+03d:%02d"),
     "short": lambda x: x[:12],
-    "shortdate": shortdate,
+    "shortdate": util.shortdate,
     "stringify": templater.stringify,
     "strip": lambda x: x.strip(),
     "urlescape": lambda x: urllib.quote(x),
--- a/mercurial/util.py	Sat Feb 16 13:01:27 2008 +0100
+++ b/mercurial/util.py	Sat Feb 16 13:33:38 2008 +0100
@@ -1533,6 +1533,10 @@
         s += timezone_format % (-tz / 3600, ((-tz % 3600) / 60))
     return s
 
+def shortdate(date=None):
+    """turn (timestamp, tzoff) tuple into iso 8631 date."""
+    return datestr(date, format='%Y-%m-%d', timezone=False)
+
 def strdate(string, format, defaults=[]):
     """parse a localized time string and return a (unixtime, offset) tuple.
     if the string cannot be parsed, ValueError is raised."""