[PATCH 8 of 9 hglib] examples: add an example that commits and pushes

Matt Mackall mpm at selenic.com
Wed Aug 24 16:24:00 CDT 2011


On Tue, 2011-08-23 at 22:04 +0300, Idan Kamara wrote:
> # HG changeset patch
> # User Idan Kamara <idankk86 at gmail.com>
> # Date 1314125860 -10800
> # Node ID 2160696c27f70982d789b237d4292eca9b440c6b
> # Parent  34209b7017b76391fffeb28daef9195f4b019f36
> examples: add an example that commits and pushes

I'm not very excited about these examples: they're more like test cases
than useful code. I think one that was more of a 'utility' and worked on
random repositories would be better. For instance, something that
counted commits per user or found case collisions or the like.

> diff -r 34209b7017b7 -r 2160696c27f7 doc/examples/commitpush.py
> --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
> +++ b/doc/examples/commitpush.py	Tue Aug 23 21:57:40 2011 +0300
> @@ -0,0 +1,28 @@
> +import sys
> +sys.path.append('../..')

Examples should be written with the assumption that hglib is normally
installed.

> +import hglib
> +
> +# clone the repo
> +repo = hglib.init('clone')
> +repo.pull('hellorepo', update=True)
> +
> +# make a change to some file
> +f = open('clone/hello.c', 'a')
> +f.write('\n/* comment */')
> +f.close()
> +
> +rev, node = repo.commit('Added a comment', user='hglib')
> +
> +repo.clone('hellorepo', 'dest')
> +
> +# examine outgoing changes
> +changes = repo.outgoing(path='dest')
> +for cset in changes:
> +    print 'going to push %s' % cset.node[:12]
> +    print
> +    print repo.diff(change=cset.rev)
> +
> +# push
> +repo.push('dest')
> +print hglib.open('dest').tip()

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list