Mercurial > python-hglib
changeset 12:c2a9b716cd80
client: rewrite branches(), return a list of (branchname, rev, node)
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Wed, 10 Aug 2011 00:24:01 +0300 |
parents | 0549d00a617d |
children | 400cb1520834 |
files | hglib/client.py tests/test-branch.py tests/test-branches.py |
diffstat | 3 files changed, 33 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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):
--- 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)
--- /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