comparing dates in a mercurial hook

Matt Mackall mpm at
Fri Oct 14 14:03:14 CDT 2011

On Fri, 2011-10-14 at 18:41 +0000, Haszlakiewicz, Eric wrote:
> > -----Original Message-----
> > From: Matt Mackall [mailto:mpm at]
> > 
> > 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.
> I have pre-existing hookthat needs to work on both unix and windows.  
> They do more than just the date check (env variable check, regexp
> check of the description, works for both commit and push, etc...), and
> I thought the best practice for a portable hook was to use python.  

Well it's portable, sure. But definitely not completely documented and
not guaranteed to work from release to release. So.. you can either
write Unix and Windows hooks in shell scripts once or write in Python
and take the hit every time you upgrade, I guess.

Another approach is to treat Python as your 'portable shell' and talk to
Mercurial vs os.system().

You can of course fold the regex checks into the revset expression.

Mathematics is the supreme nostalgia of our time.

More information about the Mercurial-devel mailing list