1
from bzrlib.branch import Branch
2
from bzrlib.config import extract_email_address
3
from bzrtools import short_committer
4
def branch_history(branch):
5
"""Print history of a branch"""
6
b = Branch.open_containing(branch)[0]
9
b.repository.lock_read()
11
for revno, revision in iter_revisiondata(b):
12
new_descriptor = (revision.committer,
13
revision.properties.get('branch-nick'))
14
if descriptor is None:
15
descriptor = new_descriptor
18
if branch_change(descriptor, new_descriptor):
19
print_info(descriptor, start, revno - 1)
21
descriptor = new_descriptor
22
print_info(descriptor, start, revno)
26
def branch_change(old_descriptor, new_descriptor):
27
if old_descriptor == new_descriptor:
29
elif None not in (old_descriptor[1], new_descriptor[1]) and \
30
old_descriptor[1] != new_descriptor[1]:
32
elif short_committer(old_descriptor[0]) ==\
33
short_committer(new_descriptor[0]):
35
elif old_descriptor[0].strip(' ') == \
36
extract_email_address(new_descriptor[0]):
38
elif new_descriptor[0].strip(' ') == \
39
extract_email_address(old_descriptor[0]):
44
def iter_revisiondata(branch):
45
"""Iterate through revno, Revision pairs in the revision history"""
46
for no, revision_id in enumerate(branch.revision_history()):
47
yield no+1, branch.repository.get_revision(revision_id)
49
def print_info(descriptor, start, end):
50
"""Print revision history"""
51
descriptor_string = descriptor[0]
52
if descriptor[1] is not None:
53
descriptor_string += " / "+ descriptor[1]
54
print descriptor_string
56
print " %d .. %d" % (start, end)