# HG changeset patch # User Idan Kamara # Date 1313772371 -10800 # Node ID 18f72b2555536ec71fef0e370866eb56da7a4909 # Parent c52383a550fbf0ab08224ae07723d56bf57d76d7 client: add annotate command diff -r c52383a550fb -r 18f72b255553 hglib/client.py --- a/hglib/client.py Thu Aug 18 16:23:43 2011 +0300 +++ b/hglib/client.py Fri Aug 19 19:46:11 2011 +0300 @@ -173,6 +173,26 @@ return bool(eh) + def annotate(self, files, rev=None, nofollow=False, text=False, user=False, + file=False, date=False, number=False, changeset=False, + line=False, verbose=False, include=None, exclude=None): + """ + Show changeset information by line for each file in files. + + yields a (info, contents) tuple for each line in a file + """ + if not isinstance(files, list): + files = [files] + + args = cmdbuilder('annotate', *files, r=rev, no_follow=nofollow, a=text, + u=user, f=file, d=date, n=number, c=changeset, l=line, + v=verbose, I=include, X=exclude) + + out = self.rawcommand(args) + + for line in out.splitlines(): + yield tuple(line.split(': ', 1)) + def backout(self, rev, merge=False, parent=None, tool=None, message=None, logfile=None, date=None, user=None): if message and logfile: diff -r c52383a550fb -r 18f72b255553 tests/test-annotate.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-annotate.py Fri Aug 19 19:46:11 2011 +0300 @@ -0,0 +1,27 @@ +import common + +class test_annotate(common.basetest): + def test_basic(self): + self.append('a', 'a\n') + rev, node0 = self.client.commit('first', addremove=True) + self.append('a', 'a\n') + rev, node1 = self.client.commit('second') + + self.assertEquals(list(self.client.annotate('a')), [('0', 'a'), ('1', 'a')]) + self.assertEquals(list(self.client.annotate('a', user=True, file=True, + number=True, changeset=True, line=True, verbose=True)), + [('test 0 %s a:1' % node0[:12], 'a'), + ('test 1 %s a:2' % node1[:12], 'a')]) + + def test_files(self): + self.append('a', 'a\n') + rev, node0 = self.client.commit('first', addremove=True) + self.append('b', 'b\n') + rev, node1 = self.client.commit('second', addremove=True) + self.assertEquals(list(self.client.annotate(['a', 'b'])), + [('0', 'a'), ('1', 'b')]) + + def test_two_colons(self): + self.append('a', 'a: b\n') + self.client.commit('first', addremove=True) + self.assertEquals(list(self.client.annotate('a')), [('0', 'a: b')])