/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
1759.2.1 by Jelmer Vernooij
Fix some types (found using aspell).
17
"""Display what revisions are missing in 'other' from 'this' and vice versa."""
1534.5.15 by Robert Collins
Review fixups
18
2490.1.2 by John Arbash Meinel
Cleanup according to PEP8 and some other small whitespace fixes
19
from bzrlib.log import (
2466.8.1 by Kent Gibson
Reworked LogFormatter API to simplify extending the attributes of the revision being logged. Added support for begin_log() and end_log() hooks in LogFormatters.
20
    LogRevision,
21
    )
22
23
24
def iter_log_revisions(revisions, revision_source, verbose):
1852.5.1 by Robert Collins
Deprecate EmptyTree in favour of using Repository.revision_tree.
25
    last_tree = revision_source.revision_tree(None)
1185.54.19 by Aaron Bentley
All tests pass
26
    last_rev_id = None
27
    for revno, rev_id in revisions:
28
        rev = revision_source.get_revision(rev_id)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
29
        if verbose:
1185.67.1 by Aaron Bentley
Merged the mainline
30
            remote_tree = revision_source.revision_tree(rev_id)
1185.35.30 by Aaron Bentley
Fixed missing --verbose
31
            parent_rev_id = rev.parent_ids[0]
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
32
            if last_rev_id == parent_rev_id:
33
                parent_tree = last_tree
34
            else:
1185.54.19 by Aaron Bentley
All tests pass
35
                parent_tree = revision_source.revision_tree(parent_rev_id)
36
            revision_tree = revision_source.revision_tree(rev_id)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
37
            last_rev_id = rev_id
38
            last_tree = revision_tree
2204.1.1 by John Arbash Meinel
'bzr missing -v' was showing adds as deletes.
39
            delta = revision_tree.changes_from(parent_tree)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
40
        else:
41
            delta = None
2490.1.2 by John Arbash Meinel
Cleanup according to PEP8 and some other small whitespace fixes
42
        yield LogRevision(rev, revno, delta=delta)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
43
1185.54.7 by Aaron Bentley
More refactoring, handled branches with no commits
44
3427.3.2 by John Arbash Meinel
switch find_unmerged to use the new function
45
def find_unmerged(local_branch, remote_branch, restrict='all'):
1185.54.3 by Aaron Bentley
Factored out find_unmerged
46
    local_branch.lock_read()
47
    try:
48
        remote_branch.lock_read()
49
        try:
3427.3.2 by John Arbash Meinel
switch find_unmerged to use the new function
50
            return _find_unmerged(local_branch,
51
                remote_branch, restrict=restrict)
1185.54.3 by Aaron Bentley
Factored out find_unmerged
52
        finally:
53
            remote_branch.unlock()
54
    finally:
55
        local_branch.unlock()
1185.54.4 by Aaron Bentley
Restructured find_unmerged, so it returns lists of (revno, revision) pairs
56
3427.3.1 by John Arbash Meinel
Add bzrlib.missing.find_unmerged_mainline_revisions
57
58
def _enumerate_mainline(ancestry, graph, tip_revno, tip):
59
    """Enumerate the mainline revisions for these revisions.
60
61
    :param ancestry: A set of revisions that we care about
62
    :param graph: A Graph which lets us find the parents for a revision
63
    :param tip_revno: The revision number for the tip revision
64
    :param tip: The tip of mailine
65
    :return: [(revno, revision_id)] for all revisions in ancestry that
66
        left-hand parents from tip
67
    """
68
    if ancestry is None:
69
        return None
70
    if not ancestry: #Empty ancestry, no need to do any work
71
        return []
72
3427.3.2 by John Arbash Meinel
switch find_unmerged to use the new function
73
    # Optionally, we could make 1 call to graph.get_parent_map with all
3427.3.1 by John Arbash Meinel
Add bzrlib.missing.find_unmerged_mainline_revisions
74
    # ancestors. However that will often check many more parents than we
75
    # actually need, and the Graph is likely to already have the parents cached
76
    # anyway.
77
    mainline = []
78
    cur = tip
79
    cur_revno = tip_revno
80
    while cur in ancestry:
81
        parent_map = graph.get_parent_map([cur])
3427.3.2 by John Arbash Meinel
switch find_unmerged to use the new function
82
        parents = parent_map.get(cur)
83
        if not parents:
3427.3.1 by John Arbash Meinel
Add bzrlib.missing.find_unmerged_mainline_revisions
84
            break # Ghost, we are done
85
        mainline.append((cur_revno, cur))
3427.3.2 by John Arbash Meinel
switch find_unmerged to use the new function
86
        cur = parents[0]
3427.3.1 by John Arbash Meinel
Add bzrlib.missing.find_unmerged_mainline_revisions
87
        cur_revno -= 1
88
    mainline.reverse()
89
    return mainline
90
91
3427.3.2 by John Arbash Meinel
switch find_unmerged to use the new function
92
def _find_unmerged(local_branch, remote_branch, restrict):
3427.3.1 by John Arbash Meinel
Add bzrlib.missing.find_unmerged_mainline_revisions
93
    """Find revisions from each side that have not been merged.
94
95
    Both branches should already be locked.
96
97
    :param local_branch: Compare the history of local_branch
98
    :param remote_branch: versus the history of remote_branch, and determine
99
        mainline revisions which have not been merged.
100
    :param restrict: ('all', 'local', 'remote') If 'all', we will return the
101
        unique revisions from both sides. If 'local', we will return None
102
        for the remote revisions, similarly if 'remote' we will return None for
103
        the local revisions.
104
105
    :return: A list of [(revno, revision_id)] for the mainline revisions on
106
        each side.
107
    """
108
    graph = local_branch.repository.get_graph(
109
                remote_branch.repository)
110
    local_revno, local_revision_id = local_branch.last_revision_info()
111
    remote_revno, remote_revision_id = remote_branch.last_revision_info()
112
    if local_revno == remote_revno and local_revision_id == remote_revision_id:
113
        # A simple shortcut when the tips are at the same point
114
        return [], []
115
    if restrict == 'remote':
116
        local_extra = None
117
        remote_extra = graph.find_unique_ancestors(
118
            remote_revision_id, [local_revision_id])
119
    elif restrict == 'local':
120
        remote_extra = None
121
        local_extra = graph.find_unique_ancestors(
122
            local_revision_id, [remote_revision_id])
123
    else:
124
        if restrict != 'all':
125
            raise ValueError('param restrict not one of "all", "local",'
126
                             ' "remote": %r' % (restrict,))
127
        local_extra, remote_extra = graph.find_difference(
128
            local_revision_id, remote_revision_id)
129
    # Now that we have unique ancestors, compute just the mainline, and
130
    # generate revnos for them.
131
    local_mainline = _enumerate_mainline(local_extra, graph, local_revno,
132
                                         local_revision_id)
133
    remote_mainline = _enumerate_mainline(remote_extra, graph, remote_revno,
134
                                          remote_revision_id)
135
    return local_mainline, remote_mainline
136
137
1185.54.4 by Aaron Bentley
Restructured find_unmerged, so it returns lists of (revno, revision) pairs
138
def sorted_revisions(revisions, history_map):
139
    revisions = [(history_map[r],r) for r in revisions]
140
    revisions.sort()
141
    return revisions