1
from bzrlib import errors
2
from bzrlib.branch import Branch
3
from bzrlib.config import extract_email_address
4
from bzrtools import short_committer
5
def branch_history(branch):
6
"""Print history of a branch"""
7
b = Branch.open_containing(branch)[0]
10
b.repository.lock_read()
12
for revno, revision in iter_revisiondata(b):
13
new_descriptor = (revision.committer,
14
revision.properties.get('branch-nick'))
15
if descriptor is None:
16
descriptor = new_descriptor
19
if branch_change(descriptor, new_descriptor):
20
print_info(descriptor, start, revno - 1)
22
descriptor = new_descriptor
23
print_info(descriptor, start, revno)
27
def branch_change(old_descriptor, new_descriptor):
29
old_email = extract_email_address(old_descriptor[0])
30
except errors.NoEmailInUsername:
33
new_email = extract_email_address(new_descriptor[0])
34
except errors.NoEmailInUsername:
36
if old_descriptor == new_descriptor:
38
elif None not in (old_descriptor[1], new_descriptor[1]) and \
39
old_descriptor[1] != new_descriptor[1]:
41
elif short_committer(old_descriptor[0]) ==\
42
short_committer(new_descriptor[0]):
44
elif old_descriptor[0].strip(' ') == new_email:
46
elif new_descriptor[0].strip(' ') == old_email:
51
def iter_revisiondata(branch):
52
"""Iterate through revno, Revision pairs in the revision history"""
53
for no, revision_id in enumerate(branch.revision_history()):
54
yield no+1, branch.repository.get_revision(revision_id)
56
def print_info(descriptor, start, end):
57
"""Print revision history"""
58
descriptor_string = descriptor[0]
59
if descriptor[1] is not None:
60
descriptor_string += " / "+ descriptor[1]
61
print descriptor_string
63
print " %d .. %d" % (start, end)