# HG changeset patch # User Idan Kamara # Date 1312925041 -10800 # Node ID c2a9b716cd80815f0cccf974cdd0e43aad52882b # Parent 0549d00a617db65ce0e28c1657c0514c8ae6826e client: rewrite branches(), return a list of (branchname, rev, node) diff -r 0549d00a617d -r c2a9b716cd80 hglib/client.py --- a/hglib/client.py Wed Aug 10 00:21:05 2011 +0300 +++ b/hglib/client.py Wed Aug 10 00:24:01 2011 +0300 @@ -156,13 +156,16 @@ # len('reset working directory to branch ') == 34 return out[34:] - def branches(self): - out = self.rawcommand(['branches']) - branches = {} - for line in out.rstrip().split('\n'): - branch, revnode = line.split() - branches[branch] = self.log(revrange=[revnode.split(':')[0]])[0] + def branches(self, active=False, closed=False): + args = cmdbuilder('branches', a=active, c=closed) + out = self.rawcommand(args) + branches = [] + for line in out.rstrip().splitlines(): + name, line = line.split(' ', 1) + rev, node = line.split(':') + node = node.split()[0] # get rid of ' (inactive)' + branches.append((name, int(rev), node)) return branches def cat(self, files, rev=None, output=None): diff -r 0549d00a617d -r c2a9b716cd80 tests/test-branch.py --- a/tests/test-branch.py Wed Aug 10 00:21:05 2011 +0300 +++ b/tests/test-branch.py Wed Aug 10 00:24:01 2011 +0300 @@ -11,7 +11,8 @@ rev = self.client.commit('first', addremove=True) self.assertEquals(rev.branch, 'foo') - self.assertEquals(self.client.branches()[rev.branch], rev) + self.assertEquals(self.client.branches(), + [(rev.branch, int(rev.rev), rev.node[:12])]) def test_reset_with_name(self): self.assertRaises(ValueError, self.client.branch, 'foo', clean=True) diff -r 0549d00a617d -r c2a9b716cd80 tests/test-branches.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-branches.py Wed Aug 10 00:24:01 2011 +0300 @@ -0,0 +1,22 @@ +import common, hglib + +class test_branches(common.basetest): + def test_empty(self): + self.assertEquals(self.client.branches(), []) + + def test_basic(self): + self.append('a', 'a') + rev0 = self.client.commit('first', addremove=True) + self.client.branch('foo') + self.append('a', 'a') + rev1 = self.client.commit('second') + branches = self.client.branches() + + expected = [] + for r in (rev1, rev0): + expected.append((r.branch, int(r.rev), r.node[:12])) + + self.assertEquals(branches, expected) + + def test_active_closed(self): + pass