292
by Aaron Bentley
Introduced branch-history command |
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] |
|
7 |
descriptor = None |
|
8 |
start = None |
|
336
by Aaron Bentley
Lock repo for branch-history |
9 |
b.repository.lock_read() |
10 |
try: |
|
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 |
|
16 |
if start is None: |
|
17 |
start = revno |
|
18 |
if branch_change(descriptor, new_descriptor): |
|
19 |
print_info(descriptor, start, revno - 1) |
|
20 |
start = revno |
|
292
by Aaron Bentley
Introduced branch-history command |
21 |
descriptor = new_descriptor |
336
by Aaron Bentley
Lock repo for branch-history |
22 |
print_info(descriptor, start, revno) |
23 |
finally: |
|
24 |
b.repository.unlock() |
|
292
by Aaron Bentley
Introduced branch-history command |
25 |
|
26 |
def branch_change(old_descriptor, new_descriptor): |
|
27 |
if old_descriptor == new_descriptor: |
|
28 |
return False |
|
29 |
elif None not in (old_descriptor[1], new_descriptor[1]) and \ |
|
30 |
old_descriptor[1] != new_descriptor[1]: |
|
31 |
return True |
|
32 |
elif short_committer(old_descriptor[0]) ==\ |
|
33 |
short_committer(new_descriptor[0]): |
|
34 |
return False |
|
35 |
elif old_descriptor[0].strip(' ') == \ |
|
36 |
extract_email_address(new_descriptor[0]): |
|
37 |
return False |
|
38 |
elif new_descriptor[0].strip(' ') == \ |
|
39 |
extract_email_address(old_descriptor[0]): |
|
40 |
return False |
|
41 |
else: |
|
42 |
return True |
|
43 |
||
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()): |
|
308
by Aaron Bentley
got branch-history under test |
47 |
yield no+1, branch.repository.get_revision(revision_id) |
292
by Aaron Bentley
Introduced branch-history command |
48 |
|
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 |
|
55 |
if start != end: |
|
56 |
print " %d .. %d" % (start, end) |
|
57 |
else: |
|
58 |
print " %d" % start |