I thought I would say something about how to modify hg's behavior, for
anyone out there that's interested...
I've been finding a lot about Mercurial recently and it's a pretty
cool program.There are 3 ways to modify it: writing "hooks" in a
user's (or system-wide) hgrc file, writing and "extension" for hg and
finally modifying hg itself. I will cover those briefly below.
On 2/8/07, William Stein <[EMAIL PROTECTED]> wrote:
> >> One other change I might like is that when you do "hg ci" it should
> >> force you by default to view the output of "hg diff" to make sure
> >> you really know what you are checking in.
You could write a "hook" for that. A hook is an action that gets
executed before or after a command is issued. To force "hg diff"
before committing, you could write it as a "precommit" hook:
{{{
[hooks]
# Before we commit, make sure we know what we are committing
precommit = hg diff|less
}}}
In this case, "precommit" says when to perform the action and "hg
diff|less" says what to do.
> For example, hg_sage.apply('patchname') could automate the merge and
> update steps, instead of requiring you to do them.
You could insert the following hook:
{{{
[hooks]
# Execute hg merge and hg update after pull-ing
incoming = hg merge && hg update
}}}
Hooks have to be written in a file called hgrc located
$INSTALL_ROOT/etc/mercurial/ . You can have multiple hgrc files and
they all get loaded by hg. The man page for hgrc has more info if
you'd like to tweak yours more:
http://www.selenic.com/mercurial/hgrc.5.html
Printing out more user-friendly error messages is requires somewhat
modifying the behavior of hg and that's what extensions try to do.
Extension are written in python and they are used to add new commands
or modify/override existing ones. For example, here's an easy one that
I've written that prints out a warning when committing fails:
{{{
def docommit(ui, repo, *pats, **opts):
i = repo.commit(None)
if None == i:
print 'WARNING: Your changes have NOT been recorded!'
print 'You must enter a message in order to record them.'
}}}
One limitation of extensions is that you depend on what functions
provided by hg return. For example, the commit() function from above
returns None for one other kind of failure, but I have no way of
knowing what kind of failure it is.
Find more about writing your own extensions here:
http://www.selenic.com/mercurial/wiki/index.cgi/WritingExtensions?action=show&redirect=ExtensionHowto
Modifying the source is not that hard either. In particular,
$MERCURIAL/mercurial/commands.py is where you'll find all the
operations (add, commit, etc) along with the sometimes cryptic error
messages they output. It also helps to look at localrepos.py, if
you're not sure what a command is doing.
All and all, I'm very impressed by the different you can bend hg to
make it work for you.
I have a mercurial spkg that has all the tweaks mentioned above here,
along with some improved error messages and verbosity:
http://sage.math.washington.edu/home/dfdeshom/custom/hg-sage/mercurial-20070209.spkg
didier
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---