~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to branchhistory.py

  • Committer: Aaron Bentley
  • Date: 2005-11-29 16:13:44 UTC
  • Revision ID: abentley@panoramicfeedback.com-20051129161344-3997ed0518fbdb2d
Introduced branch-history command

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
20
 
 
21
def branch_change(old_descriptor, new_descriptor):
 
22
    if old_descriptor == new_descriptor:
 
23
        return False
 
24
    elif None not in (old_descriptor[1], new_descriptor[1]) and \
 
25
        old_descriptor[1] != new_descriptor[1]:
 
26
        return True
 
27
    elif short_committer(old_descriptor[0]) ==\
 
28
        short_committer(new_descriptor[0]):
 
29
        return False
 
30
    elif old_descriptor[0].strip(' ') == \
 
31
        extract_email_address(new_descriptor[0]):
 
32
        return False
 
33
    elif new_descriptor[0].strip(' ') == \
 
34
        extract_email_address(old_descriptor[0]):
 
35
        return False
 
36
    else:
 
37
        return True
 
38
 
 
39
def iter_revisiondata(branch):
 
40
    """Iterate through revno, Revision pairs in the revision history"""
 
41
    for no, revision_id in enumerate(branch.revision_history()):
 
42
        yield no+1, branch.get_revision(revision_id)
 
43
 
 
44
def print_info(descriptor, start, end):
 
45
    """Print revision history"""
 
46
    descriptor_string = descriptor[0]
 
47
    if descriptor[1] is not None:
 
48
        descriptor_string += " / "+ descriptor[1]
 
49
    print descriptor_string
 
50
    if start != end:
 
51
        print "  %d .. %d" % (start, end)
 
52
    else:
 
53
        print "  %d" % start