# HG changeset patch # User Idan Kamara # Date 1313773693 -10800 # Node ID 2657fd6fef049c3e59852a989263f7fd11c0c890 # Parent 9bd819da245aa135591d29426f000af997fc5010 client: add heads command diff -r 9bd819da245a -r 2657fd6fef04 hglib/client.py --- a/hglib/client.py Fri Aug 19 20:08:13 2011 +0300 +++ b/hglib/client.py Fri Aug 19 20:08:13 2011 +0300 @@ -434,6 +434,24 @@ return util.grouper(fieldcount, out) + def heads(self, rev=[], startrev=[], topological=False, closed=False): + """ + Return a list of current repository heads or branch heads + """ + if not isinstance(rev, list): + rev = [rev] + + args = cmdbuilder('heads', *rev, r=startrev, t=topological, c=closed, + template=templates.changeset) + + def eh(ret, out, err): + if ret != 1: + raise error.CommandError(args, ret, out, err) + return '' + + out = self.rawcommand(args, eh=eh).split('\0')[:-1] + return self._parserevs(out) + def diff(self, files=[], revs=[], change=None, text=False, git=False, nodates=False, showfunction=False, reverse=False, ignoreallspace=False, ignorespacechange=False, ignoreblanklines=False, diff -r 9bd819da245a -r 2657fd6fef04 tests/test-heads.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-heads.py Fri Aug 19 20:08:13 2011 +0300 @@ -0,0 +1,16 @@ +import common + +class test_heads(common.basetest): + def test_empty(self): + self.assertEquals(self.client.heads(), []) + + def test_basic(self): + self.append('a', 'a') + rev, node0 = self.client.commit('first', addremove=True) + self.assertEquals(self.client.heads(), [self.client.tip()]) + + self.client.branch('foo') + self.append('a', 'a') + rev, node1 = self.client.commit('second') + + self.assertEquals(self.client.heads(node0, topological=True), [])