Using the API

Matt Mackall mpm at selenic.com
Tue Nov 4 09:29:01 CST 2008


On Tue, 2008-11-04 at 10:18 -0500, Chris Stromberger wrote:
> I'm trying to get a simple bit of Python working using the hg api.
> Found a few examples online, but have a few questions.  In the wiki,
> it seems to recommend digging into the code and using the cmdutil
> module directly, instead of the commands module.  So, after some
> digging, here is what I have.
> 
> I want to replace these commands with an api equivalent:
> 
> hg -q --config ui.username="user" ci -A -m "msg"
> hg bundle -q -a 'bundlefilename'
> 
> So I have this so far:
> 
> from mercurial import ui, hg, cmdutil, commands
> hgui = ui.ui(quiet = True)
> repo = hg.localrepo.localrepository(hgui, pathToRepo)
> cmdutil.addremove(repo)
> repo.commit(text = "msg", user = "user")
> commands.bundle(hgui, repo, 'bundlefilename', all=True)
> 
> Just wondering if this the right/best way to do this?  I did not see
> any undbundle in cmdutils, so went with the commands function, in
> spite of the wiki recommendation.

The wiki recommendation is rather bogus: commands.py is easily the most
stable part of our API. But the above looks reasonable. For the record,
the normal way to check in as a given user is:

hg ci -u user

-- 
Mathematics is the supreme nostalgia of our time.



More information about the Mercurial mailing list