python to api vs. command line (was RE: comparing dates in a mercurial hook)

Arne Babenhauserheide arne_bab at web.de
Sat Oct 15 03:22:57 CDT 2011


Am Freitag, 14. Oktober 2011, 15:58:07 schrieb Joel B. Mohler:
> So, is there a sensible way to get a dump of user, date, full commit 
> description, files in the commit, etc through std-in/out?  Here "sensible" 
> should be understood to mean that I don't feel like spending an hour
> parsing  text (and likely finding that I didn't cover all the corner
> cases).

I recently discovered 

	ui.pushbuffer()
	mercurial.commands.<command>(ui, …)
	result = ui.popbuffer()

That provides what I needed. 

> In pleasant contrast to using std-in/out, the mercurial api exposes lots of 
> these goodies using great pythonic idioms with lots of pleasant iterations
> over list(like) objects.  To me, that's a pretty big advantage over the
> command line.

For me, too. Also stuff like repo.lock() to make several commits in a row run 
faster: 

l = repo.lock()
for i in stuff: 
	dostuff()
l.release()

The speedup is significant (about factor 2!): See the last plot in my 
git-vs-hg-for-a-server comparision: 

http://draketo.de/proj/hg-vs-git-server/test-results.html

Best wishes, 
Arne
-- 
Ein Mann wird auf der Straße mit einem Messer bedroht. 
Zwei Polizisten sind sofort da und halten ein Transparent davor. 

	"Illegale Szene. Niemand darf das sehen."

Der Mann wird ausgeraubt, erstochen und verblutet, 
denn die Polizisten haben beide Hände voll zu tun. 

Willkommen in Deutschland. Zensur ist schön. 
      ( http://draketo.de/stichwort/zensur )

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 316 bytes
Desc: This is a digitally signed message part.
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20111015/385b740b/attachment.pgp>


More information about the Mercurial-devel mailing list