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

  • Committer: Andrew Bennetts
  • Date: 2010-04-13 02:41:22 UTC
  • mto: This revision was merged to the branch mainline in revision 5152.
  • Revision ID: andrew.bennetts@canonical.com-20100413024122-goo80m3k6smzh658
Avoid 6 branch/repo relocks in cmd_diff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
290
290
 
291
291
 
292
292
def get_trees_and_branches_to_diff(path_list, revision_specs, old_url, new_url,
293
 
                                   apply_view=True):
 
293
                                   add_cleanup, apply_view=True):
294
294
    """Get the trees and specific files to diff given a list of paths.
295
295
 
296
296
    This method works out the trees to be diff'ed and the files of
307
307
    :param new_url:
308
308
        The url of the new branch or tree. If None, the tree to use is
309
309
        taken from the first path, if any, or the current working tree.
 
310
    :param add_cleanup:
 
311
        a callable like Command.add_cleanup.  get_trees_and_branches_to_diff
 
312
        will register cleanups that must be run to unlock the trees, etc.
310
313
    :param apply_view:
311
314
        if True and a view is set, apply the view or check that the paths
312
315
        are within it
313
316
    :returns:
314
317
        a tuple of (old_tree, new_tree, old_branch, new_branch,
315
318
        specific_files, extra_trees) where extra_trees is a sequence of
316
 
        additional trees to search in for file-ids.
 
319
        additional trees to search in for file-ids.  The trees and branches
 
320
        will be read-locked until the cleanups registered via the add_cleanup
 
321
        param are run.
317
322
    """
318
323
    # Get the old and new revision specs
319
324
    old_revision_spec = None
342
347
        default_location = path_list[0]
343
348
        other_paths = path_list[1:]
344
349
 
 
350
    def lock_tree_or_branch(wt, br):
 
351
        if wt is not None:
 
352
            wt.lock_read()
 
353
            add_cleanup(wt.unlock)
 
354
        elif br is not None:
 
355
            br.lock_read()
 
356
            add_cleanup(br.unlock)
 
357
 
345
358
    # Get the old location
346
359
    specific_files = []
347
360
    if old_url is None:
348
361
        old_url = default_location
349
362
    working_tree, branch, relpath = \
350
363
        bzrdir.BzrDir.open_containing_tree_or_branch(old_url)
 
364
    lock_tree_or_branch(working_tree, branch)
351
365
    if consider_relpath and relpath != '':
352
366
        if working_tree is not None and apply_view:
353
367
            views.check_path_in_view(working_tree, relpath)
361
375
    if new_url != old_url:
362
376
        working_tree, branch, relpath = \
363
377
            bzrdir.BzrDir.open_containing_tree_or_branch(new_url)
 
378
        lock_tree_or_branch(working_tree, branch)
364
379
        if consider_relpath and relpath != '':
365
380
            if working_tree is not None and apply_view:
366
381
                views.check_path_in_view(working_tree, relpath)