comparing dates in a mercurial hook
Matt Mackall
mpm at selenic.com
Fri Oct 14 13:25:51 CDT 2011
On Fri, 2011-10-14 at 18:05 +0000, Haszlakiewicz, Eric wrote:
> I'm trying to write a hook that doesn't apply to changesets older than
> 6 months, but I'm having trouble actually performing the date
> comparison. I can't figure out what the date() function is returning,
> or how to work with it. Can someone point me at an example that does
> stuff with the dates?
Why does everyone want to write hooks in Python?
On the command line, you can do this with something like:
hg id -r "$SOMENODE and not date('-180')"
and get a non-zero return code if the set is empty.
> Here's a snippet of the code I have:
>
> def myhook(ui, repo, rev):
> ctx = repo[rev]
> """ don't validate really old changesets """
> sixmonthsback = datetime.today() - timedelta(days=180)
> if (ctx.date() < sixmonthsback):
> return 0
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").
--
Mathematics is the supreme nostalgia of our time.
More information about the Mercurial-devel
mailing list