comparing dates in a mercurial hook
Haszlakiewicz, Eric
EHASZLA at transunion.com
Fri Oct 14 18:57:27 UTC 2011
> -----Original Message-----
> From: Matt Mackall [mailto:mpm at selenic.com]
>
> A datetime is presumably a number in seconds since (the local) UNIX
> epoch. Mercurial dates are all of the form:
>
> (seconds since epoch in GMT, seconds offset from GMT)
>
> so this comparison won't work. You should instead use
> util.matchdate("-180").
Here's my final, actual working code to check for old changesets, for anyone else that needs an example:
from mercurial import ui, util
def myhook(ui, repo, rev):
ctx = repo[rev]
""" don't validate really old changesets """
within_six_months = util.matchdate("-180")
if (not within_six_months(ctx.date()[0])):
ui.write("Skipping check for old rev\n")
return 0
...rest of hook...
def hook(ui, repo, hooktype, node=None, **kwargs):
if hooktype == "pretxncommit":
return myhook(ui, repo, node)
return False
eric
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 474 bytes
Desc: not available
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-devel/attachments/20111014/90fdde5f/attachment.sig>
More information about the Mercurial-devel
mailing list