/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/log.py

  • Committer: John Arbash Meinel
  • Date: 2007-04-18 21:47:59 UTC
  • mto: This revision was merged to the branch mainline in revision 2456.
  • Revision ID: john@arbash-meinel.com-20070418214759-xmfpvwok0v6ci38l
Refactor the specific revisions for file id into a helper function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
227
227
    view_revs_iter = get_view_revisions(mainline_revs, rev_nos, branch,
228
228
                          direction, include_merges=include_merges)
229
229
    if specific_fileid:
230
 
        # find all the revisions that change the specific file
231
 
        sfw = branch.repository.weave_store.get_weave(specific_fileid,
232
 
                    branch.repository.get_transaction())
233
 
        sfw_revids = set(sfw.versions())
234
 
        # build the ancestry of each revision in the graph
235
 
        # - only listing the ancestors that change the specific file.
236
 
        rev_graph = branch.repository.get_revision_graph(mainline_revs[-1])
237
 
        sorted_rev_list = topo_sort(rev_graph)
238
 
        ancestry = {}
239
 
        for rev in sorted_rev_list:
240
 
            rev_ancestry = set()
241
 
            if rev in sfw_revids:
242
 
                rev_ancestry.add(rev)
243
 
            for parent in rev_graph[rev]:
244
 
                rev_ancestry = rev_ancestry.union(ancestry[parent])
245
 
            ancestry[rev] = rev_ancestry
246
 
 
247
 
        def is_merging_rev():
248
 
            parents = rev_graph[r]
249
 
            if len(parents) > 1:
250
 
                leftparent = parents[0]
251
 
                for rightparent in parents[1:]:
252
 
                    if not ancestry[leftparent].issuperset(
253
 
                            ancestry[rightparent]):
254
 
                        return True
255
 
            return False        
256
 
 
257
 
        # filter from the view the revisions that did not change or merge 
258
 
        # the specific file
259
 
        view_revisions = [(r, n, d) for r, n, d in view_revs_iter if
260
 
                          r in sfw_revids or is_merging_rev()]
 
230
        view_revisions = _get_revisions_touching_file_id(branch,
 
231
                                                         specific_fileid,
 
232
                                                         mainline_revs,
 
233
                                                         view_revs_iter)
261
234
    else:
262
235
        view_revisions = list(view_revs_iter)
263
236
 
302
275
                lf.show_merge_revno(rev, merge_depth, revno)
303
276
 
304
277
 
 
278
def _get_revisions_touching_file_id(branch, file_id, mainline_revisions,
 
279
                                    view_revs_iter):
 
280
    """Return the list of revision ids which touch a given file id.
 
281
 
 
282
    This includes the revisions which directly change the file id,
 
283
    and the revisions which merge these changes. So if the
 
284
    revision graph is::
 
285
        A
 
286
        |\
 
287
        B C
 
288
        |/
 
289
        D
 
290
 
 
291
    And 'C' changes a file, then both C and D will be returned.
 
292
 
 
293
    This will also can be restricted based on a subset of the mainline.
 
294
    """
 
295
    # find all the revisions that change the specific file
 
296
    sfw = branch.repository.weave_store.get_weave(file_id,
 
297
                branch.repository.get_transaction())
 
298
    sfw_revids = set(sfw.versions())
 
299
    # build the ancestry of each revision in the graph
 
300
    # - only listing the ancestors that change the specific file.
 
301
    rev_graph = branch.repository.get_revision_graph(mainline_revisions[-1])
 
302
    sorted_rev_list = topo_sort(rev_graph)
 
303
    ancestry = {}
 
304
    for rev in sorted_rev_list:
 
305
        rev_ancestry = set()
 
306
        if rev in sfw_revids:
 
307
            rev_ancestry.add(rev)
 
308
        for parent in rev_graph[rev]:
 
309
            rev_ancestry = rev_ancestry.union(ancestry[parent])
 
310
        ancestry[rev] = rev_ancestry
 
311
 
 
312
    def is_merging_rev():
 
313
        parents = rev_graph[r]
 
314
        if len(parents) > 1:
 
315
            leftparent = parents[0]
 
316
            for rightparent in parents[1:]:
 
317
                if not ancestry[leftparent].issuperset(
 
318
                        ancestry[rightparent]):
 
319
                    return True
 
320
        return False
 
321
 
 
322
    # filter from the view the revisions that did not change or merge 
 
323
    # the specific file
 
324
    return [(r, n, d) for r, n, d in view_revs_iter
 
325
            if r in sfw_revids or is_merging_rev()]
 
326
 
 
327
 
305
328
def get_view_revisions(mainline_revs, rev_nos, branch, direction,
306
329
                       include_merges=True):
307
330
    """Produce an iterator of revisions to show