~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to branchhistory.py

  • Committer: Max Bowsher
  • Date: 2009-11-13 00:43:08 UTC
  • mto: This revision was merged to the branch mainline in revision 739.
  • Revision ID: maxb@f2s.com-20091113004308-4dcwu1kwt3lhf1kp
Having discovered that bzr-builddeb import_dsc.py is a horrid copy-paste job of bzrtools upstream_import.py, restructure the change to minimize divergence from it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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]
 
8
    descriptor = None
 
9
    start = None
 
10
    b.repository.lock_read()
 
11
    try:
 
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
 
17
            if start is None:
 
18
                start = revno
 
19
            if branch_change(descriptor, new_descriptor):
 
20
                print_info(descriptor, start, revno - 1)
 
21
                start = revno
 
22
            descriptor = new_descriptor
 
23
        print_info(descriptor, start, revno)
 
24
    finally:
 
25
        b.repository.unlock()
 
26
 
 
27
def branch_change(old_descriptor, new_descriptor):
 
28
    try:
 
29
        old_email = extract_email_address(old_descriptor[0])
 
30
    except errors.NoEmailInUsername:
 
31
        old_email = None
 
32
    try:
 
33
        new_email = extract_email_address(new_descriptor[0])
 
34
    except errors.NoEmailInUsername:
 
35
        new_email = None
 
36
    if old_descriptor == new_descriptor:
 
37
        return False
 
38
    elif None not in (old_descriptor[1], new_descriptor[1]) and \
 
39
        old_descriptor[1] != new_descriptor[1]:
 
40
        return True
 
41
    elif short_committer(old_descriptor[0]) ==\
 
42
        short_committer(new_descriptor[0]):
 
43
        return False
 
44
    elif old_descriptor[0].strip(' ') == new_email:
 
45
        return False
 
46
    elif new_descriptor[0].strip(' ') == old_email:
 
47
        return False
 
48
    else:
 
49
        return True
 
50
 
 
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)
 
55
 
 
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
 
62
    if start != end:
 
63
        print "  %d .. %d" % (start, end)
 
64
    else:
 
65
        print "  %d" % start