# HG changeset patch # User Idan Kamara # Date 1313092745 -10800 # Node ID 46908f4b87d555d587bdbb9188b3bbb3dbda1041 # Parent b4e5c8745ef3d2418787b809e697422572069e14 client: add bookmarks support to incoming and outgoing diff -r b4e5c8745ef3 -r 46908f4b87d5 hglib/client.py --- a/hglib/client.py Thu Aug 11 22:58:38 2011 +0300 +++ b/hglib/client.py Thu Aug 11 22:59:05 2011 +0300 @@ -308,6 +308,12 @@ def incoming(self, revrange=None, path=None, force=False, newest=False, bundle=None, bookmarks=False, branch=None, limit=None, nomerges=False, subrepos=False): + """ + Return new changesets found in the specified path or the default pull + location. + + When bookmarks=True, return a list of (name, node) of incoming bookmarks. + """ args = cmdbuilder('incoming', path, template=templates.changeset, r=revrange, @@ -322,8 +328,15 @@ if not out: return [] - out = util.eatlines(out, 2).split('\0')[:-1] - return self._parserevs(out) + out = util.eatlines(out, 2) + if bookmarks: + bms = [] + for line in out.splitlines(): + bms.append(tuple(line.split())) + return bms + else: + out = out.split('\0')[:-1] + return self._parserevs(out) def log(self, revrange=None, files=[], follow=False, followfirst=False, date=None, copies=False, keyword=None, removed=False, onlymerges=False, @@ -343,6 +356,13 @@ def outgoing(self, revrange=None, path=None, force=False, newest=False, bookmarks=False, branch=None, limit=None, nomerges=False, subrepos=False): + """ + Return changesets not found in the specified path or the default push + location. + + When bookmarks=True, return a list of (name, node) of bookmarks that will + be pushed. + """ args = cmdbuilder('outgoing', path, template=templates.changeset, r=revrange, @@ -357,8 +377,15 @@ if not out: return [] - out = util.eatlines(out, 2).split('\0')[:-1] - return self._parserevs(out) + out = util.eatlines(out, 2) + if bookmarks: + bms = [] + for line in out.splitlines(): + bms.append(tuple(line.split())) + return bms + else: + out = out.split('\0')[:-1] + return self._parserevs(out) def parents(self, rev=None, file=None): args = cmdbuilder('parents', file, template=templates.changeset, r=rev) diff -r b4e5c8745ef3 -r 46908f4b87d5 tests/test-outgoing-incoming.py --- a/tests/test-outgoing-incoming.py Thu Aug 11 22:58:38 2011 +0300 +++ b/tests/test-outgoing-incoming.py Thu Aug 11 22:59:05 2011 +0300 @@ -32,3 +32,20 @@ self.assertEquals(out[0].node, node) self.assertEquals(out, other.incoming()) + + def test_bookmarks(self): + self.append('a', 'a') + self.client.commit('first', addremove=True) + self.append('a', 'a') + self.client.commit('second') + + self.client.clone(dest='other') + other = hglib.open('other') + + self.client.bookmark('bm1', 1) + + self.assertEquals(other.incoming(bookmarks=True), + [('bm1', self.client.tip().node[:12])]) + + self.assertEquals(self.client.outgoing(path='other', bookmarks=True), + [('bm1', self.client.tip().node[:12])])