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

  • Committer: Guilherme Salgado
  • Date: 2009-12-22 16:42:34 UTC
  • mto: This revision was merged to the branch mainline in revision 4955.
  • Revision ID: salgado@canonical.com-20091222164234-0mr9n3x7biorkafg
First round of the new approach, using a new action (--preview) on the unshelve command

Show diffs side-by-side

added added

removed removed

Lines of Context:
390
390
 
391
391
        :param shelf_id: Integer id of the shelf, as a string.
392
392
        :param action: action to perform.  May be 'apply', 'dry-run',
393
 
            'delete'.
 
393
            'delete', 'preview'.
394
394
        :param directory: The directory to unshelve changes into.
395
395
        """
396
396
        tree, path = workingtree.WorkingTree.open_containing(directory)
410
410
            apply_changes = True
411
411
            delete_shelf = True
412
412
            read_shelf = True
 
413
            show_diff = False
413
414
            if action == 'dry-run':
414
415
                apply_changes = False
415
416
                delete_shelf = False
 
417
            elif action == 'preview':
 
418
                apply_changes = False
 
419
                delete_shelf = False
 
420
                show_diff = True
416
421
            elif action == 'delete-only':
417
422
                apply_changes = False
418
423
                read_shelf = False
423
428
            tree.unlock()
424
429
            raise
425
430
        return klass(tree, manager, shelf_id, apply_changes, delete_shelf,
426
 
                     read_shelf)
 
431
                     read_shelf, show_diff)
427
432
 
428
433
    def __init__(self, tree, manager, shelf_id, apply_changes=True,
429
 
                 delete_shelf=True, read_shelf=True):
 
434
                 delete_shelf=True, read_shelf=True, show_diff=False):
430
435
        """Constructor.
431
436
 
432
437
        :param tree: The working tree to unshelve into.
436
441
            working tree.
437
442
        :param delete_shelf: If True, delete the changes from the shelf.
438
443
        :param read_shelf: If True, read the changes from the shelf.
 
444
        :param show_diff: If True, show the diff that would result from
 
445
            unshelving the changes.
439
446
        """
440
447
        self.tree = tree
441
448
        manager = tree.get_shelf_manager()
444
451
        self.apply_changes = apply_changes
445
452
        self.delete_shelf = delete_shelf
446
453
        self.read_shelf = read_shelf
 
454
        self.show_diff = show_diff
447
455
 
448
 
    def run(self):
 
456
    def run(self, diff_output=None):
449
457
        """Perform the unshelving operation."""
450
458
        self.tree.lock_tree_write()
451
459
        cleanups = [self.tree.unlock]
462
470
                    merger.change_reporter = change_reporter
463
471
                    if self.apply_changes:
464
472
                        merger.do_merge()
 
473
                    elif self.show_diff:
 
474
                        self.write_diff(merger, diff_output)
465
475
                    else:
466
476
                        self.show_changes(merger)
467
477
                finally:
472
482
            for cleanup in reversed(cleanups):
473
483
                cleanup()
474
484
 
 
485
    def write_diff(self, merger, diff_output=None):
 
486
        tree_merger = merger.make_merger()
 
487
        # This would implicitly show the changes via the reporter, but we
 
488
        # don't want that, so we silence it.
 
489
        merger.change_reporter.report = lambda *args: None
 
490
        tt = tree_merger.make_preview_transform()
 
491
        # And now we show the diff that would've been applied if this was
 
492
        # for real.
 
493
        new_tree = tt.get_preview_tree()
 
494
        if diff_output is None:
 
495
            diff_output = ui.ui_factory.make_output_stream()
 
496
        diff.show_diff_trees(merger.this_tree, new_tree, diff_output)
 
497
        tt.finalize()
 
498
 
475
499
    def show_changes(self, merger):
476
500
        """Show the changes that this operation specifies."""
477
501
        tree_merger = merger.make_merger()
478
502
        # This implicitly shows the changes via the reporter.
479
503
        tt = tree_merger.make_preview_transform()
480
 
        # And now we show the diff that would've been applied if this was for
481
 
        # real.
482
 
        new_tree = tt.get_preview_tree()
483
 
        diff.show_diff_trees(merger.this_tree, new_tree, sys.stdout)
484
504
        tt.finalize()