How to format UTC revision date
Lawrence Stewart
lstewart at room52.net
Sun May 3 03:23:11 UTC 2015
Hi all,
I want to do this:
> hg log -r . --template "{date(date,'%Y%m%d%H%M%S')}\n"
20150503030535
but want to apply the format to the revision's date in UTC rather than
timezone in which the commit was made, and I can't nut out if there's a
way to do it with templates. I found a hacky way which does work:
> date -ur `hg log -r . --template '{date(date, "%s")}\n'` '+%Y%m%d%H%M%S'
20150502170535
The templates-only ideas I tried playing around with failed, I guess
because the inbuilt date() doesn't know how to ingest already formatted
date strings e.g.:
> hg log -r . --template "{date(utcdate(date),'%Y%m%d%H%M%S')}\n"
** unknown exception encountered, please report by visiting
** http://mercurial.selenic.com/wiki/BugTracker
** Python 2.7.9 (default, Mar 11 2015, 01:53:48) [GCC 4.2.1 Compatible
FreeBSD Clang 3.5.1 (tags/RELEASE_351/final 225668)]
** Mercurial Distributed SCM (version 3.3.2)
** Extensions loaded: keyword, rebase, histedit, record, strip, mq,
convert, patchbomb, share
Traceback (most recent call last):
File "/usr/local/bin/hg", line 43, in <module>
mercurial.dispatch.run()
File "/usr/local/lib/python2.7/site-packages/mercurial/dispatch.py",
line 28, in run
sys.exit((dispatch(request(sys.argv[1:])) or 0) & 255)
File "/usr/local/lib/python2.7/site-packages/mercurial/dispatch.py",
line 71, in dispatch
ret = _runcatch(req)
File "/usr/local/lib/python2.7/site-packages/mercurial/dispatch.py",
line 140, in _runcatch
return _dispatch(req)
File "/usr/local/lib/python2.7/site-packages/mercurial/dispatch.py",
line 863, in _dispatch
cmdpats, cmdoptions)
File "/usr/local/lib/python2.7/site-packages/mercurial/dispatch.py",
line 624, in runcommand
ret = _runcommand(ui, options, cmd, d)
File "/usr/local/lib/python2.7/site-packages/mercurial/dispatch.py",
line 954, in _runcommand
return checkargs()
File "/usr/local/lib/python2.7/site-packages/mercurial/dispatch.py",
line 925, in checkargs
return cmdfunc()
File "/usr/local/lib/python2.7/site-packages/mercurial/dispatch.py",
line 860, in <lambda>
d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
File "/usr/local/lib/python2.7/site-packages/mercurial/util.py", line
711, in check
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/mercurial/extensions.py",
line 149, in wrap
util.checksignature(origfn), *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/mercurial/util.py", line
711, in check
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/hgext/mq.py", line 3483,
in mqcommand
return orig(ui, repo, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/mercurial/util.py", line
711, in check
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/mercurial/commands.py",
line 4507, in log
displayer.show(ctx, copies=copies, matchfn=revmatchfn)
File "/usr/local/lib/python2.7/site-packages/mercurial/cmdutil.py",
line 878, in show
self._show(ctx, copies, matchfn, props)
File "/usr/local/lib/python2.7/site-packages/mercurial/cmdutil.py",
line 1205, in _show
self.ui.write(templater.stringify(self.t(key, **props)))
File
"/usr/local/lib/python2.7/site-packages/mercurial/templatefilters.py",
line 324, in stringify
return "".join([stringify(t) for t in thing if t is not None])
File "/usr/local/lib/python2.7/site-packages/mercurial/util.py", line
532, in increasingchunks
for chunk in source:
File "/usr/local/lib/python2.7/site-packages/mercurial/templater.py",
line 571, in _flatten
for i in thing:
File "/usr/local/lib/python2.7/site-packages/mercurial/templater.py",
line 182, in runtemplate
yield func(context, mapping, data)
File "/usr/local/lib/python2.7/site-packages/mercurial/templater.py",
line 224, in date
return util.datestr(date, fmt)
File "/usr/local/lib/python2.7/site-packages/mercurial/util.py", line
1264, in datestr
t, tz = date or makedate()
ValueError: too many values to unpack
Any clue appreciated.
Cheers,
Lawrence
More information about the Mercurial
mailing list