~abentley/bzrtools/bzrtools.dev

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
9
    for revno, revision in iter_revisiondata(b):
10
        new_descriptor = (revision.committer, 
11
                          revision.properties.get('branch-nick'))
12
        if descriptor is None:
13
            descriptor = new_descriptor
14
        if start is None:
15
            start = revno
16
        if branch_change(descriptor, new_descriptor):
17
            print_info(descriptor, start, revno - 1)
18
            start = revno
19
        descriptor = new_descriptor
294 by Aaron Bentley
Print the last revision range in branch_history
20
    print_info(descriptor, start, revno)
292 by Aaron Bentley
Introduced branch-history command
21
22
def branch_change(old_descriptor, new_descriptor):
23
    if old_descriptor == new_descriptor:
24
        return False
25
    elif None not in (old_descriptor[1], new_descriptor[1]) and \
26
        old_descriptor[1] != new_descriptor[1]:
27
        return True
28
    elif short_committer(old_descriptor[0]) ==\
29
        short_committer(new_descriptor[0]):
30
        return False
31
    elif old_descriptor[0].strip(' ') == \
32
        extract_email_address(new_descriptor[0]):
33
        return False
34
    elif new_descriptor[0].strip(' ') == \
35
        extract_email_address(old_descriptor[0]):
36
        return False
37
    else:
38
        return True
39
40
def iter_revisiondata(branch):
41
    """Iterate through revno, Revision pairs in the revision history"""
42
    for no, revision_id in enumerate(branch.revision_history()):
308 by Aaron Bentley
got branch-history under test
43
        yield no+1, branch.repository.get_revision(revision_id)
292 by Aaron Bentley
Introduced branch-history command
44
45
def print_info(descriptor, start, end):
46
    """Print revision history"""
47
    descriptor_string = descriptor[0]
48
    if descriptor[1] is not None:
49
        descriptor_string += " / "+ descriptor[1]
50
    print descriptor_string
51
    if start != end:
52
        print "  %d .. %d" % (start, end)
53
    else:
54
        print "  %d" % start