comparing dates in a mercurial hook

Haszlakiewicz, Eric EHASZLA at
Fri Oct 14 13:57:27 CDT 2011

> -----Original Message-----
> From: Matt Mackall [mailto:mpm at]
> 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([0])):
        ui.write("Skipping check for old rev\n")
        return 0 of hook...

def hook(ui, repo, hooktype, node=None, **kwargs):
    if hooktype == "pretxncommit":
        return myhook(ui, repo, node)
    return False

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 474 bytes
Desc: not available
URL: <>

More information about the Mercurial-devel mailing list