/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/missing.py

  • Committer: Marius Kruger
  • Date: 2009-01-01 21:46:06 UTC
  • mto: (3969.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3970.
  • Revision ID: amanic@gmail.com-20090101214606-lak9wejufcjehpm6
extract graph.is_between from builtins.cmd_tags.run, and test it

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Display what revisions are missing in 'other' from 'this' and vice versa."""
18
18
 
19
19
from bzrlib import (
20
20
    log,
 
21
    repository as _mod_repository,
 
22
    tsort,
21
23
    )
22
24
import bzrlib.revision as _mod_revision
23
25
 
35
37
            revno, rev_id, merge_depth = rev
36
38
        rev = revision_source.get_revision(rev_id)
37
39
        if verbose:
38
 
            delta = revision_source.get_revision_delta(rev_id)
 
40
            remote_tree = revision_source.revision_tree(rev_id)
 
41
            parent_rev_id = rev.parent_ids[0]
 
42
            if last_rev_id == parent_rev_id:
 
43
                parent_tree = last_tree
 
44
            else:
 
45
                parent_tree = revision_source.revision_tree(parent_rev_id)
 
46
            revision_tree = revision_source.revision_tree(rev_id)
 
47
            last_rev_id = rev_id
 
48
            last_tree = revision_tree
 
49
            delta = revision_tree.changes_from(parent_tree)
39
50
        else:
40
51
            delta = None
41
52
        yield log.LogRevision(rev, revno, merge_depth, delta=delta)
56
67
    :param include_merges: Show mainline revisions only if False,
57
68
        all revisions otherwise.
58
69
    :param backward: Show oldest versions first when True, newest versions
59
 
        first when False.
60
 
    :param local_revid_range: Revision-id range for filtering local_branch
61
 
        revisions (lower bound, upper bound)
62
 
    :param remote_revid_range: Revision-id range for filtering remote_branch
63
 
        revisions (lower bound, upper bound)
 
70
        first when False. 
64
71
 
65
72
    :return: A list of [(revno, revision_id)] for the mainline revisions on
66
73
        each side.
73
80
                local_branch, remote_branch, restrict=restrict,
74
81
                include_merges=include_merges, backward=backward,
75
82
                local_revid_range=local_revid_range,
76
 
                remote_revid_range=remote_revid_range)
 
83
                remote_revid_range= remote_revid_range)
77
84
        finally:
78
85
            remote_branch.unlock()
79
86
    finally:
88
95
    :param tip_revno: The revision number for the tip revision
89
96
    :param tip: The tip of mainline
90
97
    :param backward: Show oldest versions first when True, newest versions
91
 
        first when False.
 
98
        first when False. 
92
99
    :return: [(revno, revision_id)] for all revisions in ancestry that
93
100
        are left-hand parents from tip, or None if ancestry is None.
94
101
    """
127
134
    :param tip_revno: The revision number for the tip revision
128
135
    :param tip: The tip of the ancsetry
129
136
    :param backward: Show oldest versions first when True, newest versions
130
 
        first when False.
 
137
        first when False. 
131
138
    :return: [(revno, revision_id)] for all revisions in ancestry that
132
139
        are parents from tip, or None if ancestry is None.
133
140
    """
136
143
    if not ancestry: #Empty ancestry, no need to do any work
137
144
        return []
138
145
 
139
 
    merge_sorted_revisions = branch.iter_merge_sorted_revisions()
 
146
    mainline_revs, rev_nos, start_rev_id, end_rev_id = log._get_mainline_revs(
 
147
        branch, None, tip_revno)
 
148
    if not mainline_revs:
 
149
        return []
 
150
 
 
151
    # This asks for all mainline revisions, which is size-of-history and
 
152
    # should be addressed (but currently the only way to get correct
 
153
    # revnos).
 
154
 
 
155
    # mainline_revisions always includes an extra revision at the
 
156
    # beginning, so don't request it.
 
157
    parent_map = dict(((key, value) for key, value
 
158
                       in graph.iter_ancestry(mainline_revs[1:])
 
159
                       if value is not None))
 
160
    # filter out ghosts; merge_sort errors on ghosts. 
 
161
    # XXX: is this needed here ? -- vila080910
 
162
    rev_graph = _mod_repository._strip_NULL_ghosts(parent_map)
 
163
    # XXX: what if rev_graph is empty now ? -- vila080910
 
164
    merge_sorted_revisions = tsort.merge_sort(rev_graph, tip,
 
165
                                              mainline_revs,
 
166
                                              generate_revno=True)
140
167
    # Now that we got the correct revnos, keep only the relevant
141
168
    # revisions.
142
169
    merge_sorted_revisions = [
143
 
        # log.reverse_by_depth expects seq_num to be present, but it is
144
 
        # stripped by iter_merge_sorted_revisions()
145
 
        (0, revid, n, d, e) for revid, n, d, e in merge_sorted_revisions
 
170
        (s, revid, n, d, e) for s, revid, n, d, e in merge_sorted_revisions
146
171
        if revid in ancestry]
147
172
    if not backward:
148
173
        merge_sorted_revisions = log.reverse_by_depth(merge_sorted_revisions)
152
177
    return revline
153
178
 
154
179
 
155
 
def _filter_revs(graph, revs, revid_range):
156
 
    if revid_range is None or revs is None:
157
 
        return revs
158
 
    return [rev for rev in revs
159
 
        if graph.is_between(rev[1], revid_range[0], revid_range[1])]
 
180
def _get_revid_in_range(branch, graph, revid_range, revision_id):
 
181
    """Force revision_id inside bounds"""
 
182
    if revid_range is not None:
 
183
        revid1, revid2 = revid_range
 
184
    else:
 
185
        revid1 = revid2 = None
 
186
    print branch.nick, revid_range, branch.revision_id_to_revno(revision_id), revision_id 
 
187
    # check if older than lower bound
 
188
    if (revid1 is not None and graph.is_ancestor(revision_id, revid1)
 
189
        and revid1 in branch.revision_history()):
 
190
        # is there a cheaper way to check if a revid is present in a branch?
 
191
        revision_id = revid1
 
192
    # check if younger than upper bound
 
193
    if (revid2 is not None and graph.is_ancestor(revid2, revision_id)
 
194
        and revid2 in branch.revision_history()):
 
195
        revision_id = revid2
 
196
    print "--> ", branch.revision_id_to_revno(revision_id), revision_id 
 
197
    return branch.revision_id_to_revno(revision_id), revision_id
160
198
 
161
199
 
162
200
def _find_unmerged(local_branch, remote_branch, restrict,
172
210
        # A simple shortcut when the tips are at the same point
173
211
        return [], []
174
212
    graph = local_branch.repository.get_graph(remote_branch.repository)
 
213
 
 
214
    local_revno, local_revision_id = _get_revid_in_range(local_branch,
 
215
        graph, local_revid_range, local_revision_id)
 
216
    remote_revno, remote_revision_id = _get_revid_in_range(remote_branch,
 
217
        graph, remote_revid_range, remote_revision_id)
175
218
    if restrict == 'remote':
176
219
        local_extra = None
177
220
        remote_extra = graph.find_unique_ancestors(remote_revision_id,
186
229
                             ' "remote": %r' % (restrict,))
187
230
        local_extra, remote_extra = graph.find_difference(local_revision_id,
188
231
                                                          remote_revision_id)
 
232
    #Todo: filter extra revisions to be in the range  
189
233
    if include_merges:
190
234
        locals = _enumerate_with_merges(local_branch, local_extra,
191
235
                                        graph, local_revno,
200
244
                                     local_revision_id, backward)
201
245
        remotes = _enumerate_mainline(remote_extra, graph, remote_revno,
202
246
                                      remote_revision_id, backward)
203
 
    return _filter_revs(graph, locals, local_revid_range), _filter_revs(graph,
204
 
        remotes, remote_revid_range)
 
247
    return locals, remotes
205
248
 
206
249
 
207
250
def sorted_revisions(revisions, history_map):