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

  • Committer: Aaron Bentley
  • Date: 2008-02-24 16:42:13 UTC
  • mfrom: (3234 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3235.
  • Revision ID: aaron@aaronbentley.com-20080224164213-eza1lzru5bwuwmmj
Merge with bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
610
610
            else:
611
611
                display_url = urlutils.unescape_for_display(stored_loc,
612
612
                        self.outf.encoding)
613
 
                self.outf.write("Using saved location: %s\n" % display_url)
 
613
                if not is_quiet():
 
614
                    self.outf.write("Using saved location: %s\n" % display_url)
614
615
                location = stored_loc
615
616
                location_transport = transport.get_transport(
616
617
                    location, possible_transports=possible_transports)
962
963
 
963
964
    def run(self, branch_location=None, to_location=None, revision=None,
964
965
            lightweight=False, files_from=None, hardlink=False):
965
 
        if files_from is not None:
966
 
            accelerator_tree = WorkingTree.open(files_from)
967
 
        else:
968
 
            accelerator_tree = None
969
966
        if revision is None:
970
967
            revision = [None]
971
968
        elif len(revision) > 1:
974
971
        if branch_location is None:
975
972
            branch_location = osutils.getcwd()
976
973
            to_location = branch_location
977
 
        source = Branch.open(branch_location)
 
974
        accelerator_tree, source = bzrdir.BzrDir.open_tree_or_branch(
 
975
            branch_location)
 
976
        if files_from is not None:
 
977
            accelerator_tree = WorkingTree.open(files_from)
978
978
        if len(revision) == 1 and revision[0] is not None:
979
979
            revision_id = _mod_revision.ensure_null(
980
980
                revision[0].in_history(source)[1])
1460
1460
 
1461
1461
            bzr diff --prefix old/:new/
1462
1462
    """
1463
 
    # TODO: Option to use external diff command; could be GNU diff, wdiff,
1464
 
    #       or a graphical diff.
1465
 
 
1466
 
    # TODO: Python difflib is not exactly the same as unidiff; should
1467
 
    #       either fix it up or prefer to use an external diff.
1468
 
 
1469
 
    # TODO: Selected-file diff is inefficient and doesn't show you
1470
 
    #       deleted files.
1471
 
 
1472
 
    # TODO: This probably handles non-Unix newlines poorly.
1473
 
 
1474
1463
    _see_also = ['status']
1475
1464
    takes_args = ['file*']
1476
1465
    takes_options = [
1490
1479
            ),
1491
1480
        'revision',
1492
1481
        'change',
 
1482
        Option('using',
 
1483
            help='Use this command to compare files.',
 
1484
            type=unicode,
 
1485
            ),
1493
1486
        ]
1494
1487
    aliases = ['di', 'dif']
1495
1488
    encoding_type = 'exact'
1496
1489
 
1497
1490
    @display_command
1498
1491
    def run(self, revision=None, file_list=None, diff_options=None,
1499
 
            prefix=None, old=None, new=None):
 
1492
            prefix=None, old=None, new=None, using=None):
1500
1493
        from bzrlib.diff import _get_trees_to_diff, show_diff_trees
1501
1494
 
1502
1495
        if (prefix is None) or (prefix == '0'):
1523
1516
                               specific_files=specific_files,
1524
1517
                               external_diff_options=diff_options,
1525
1518
                               old_label=old_label, new_label=new_label,
1526
 
                               extra_trees=extra_trees)
 
1519
                               extra_trees=extra_trees, using=using)
1527
1520
 
1528
1521
 
1529
1522
class cmd_deleted(Command):
2612
2605
                                 ' expression.'),
2613
2606
                     Option('strict', help='Fail on missing dependencies or '
2614
2607
                            'known failures.'),
2615
 
                     Option('coverage', type=str, argname="DIRECTORY",
2616
 
                            help='Generate line coverage report in this '
2617
 
                                 'directory.'),
 
2608
                     Option('load-list', type=str, argname='TESTLISTFILE',
 
2609
                            help='Load a test id list from a text file.'),
2618
2610
                     ]
2619
2611
    encoding_type = 'replace'
2620
2612
 
2622
2614
            transport=None, benchmark=None,
2623
2615
            lsprof_timed=None, cache_dir=None,
2624
2616
            first=False, list_only=False,
2625
 
            randomize=None, exclude=None, strict=False, coverage=None):
 
2617
            randomize=None, exclude=None, strict=False,
 
2618
            load_list=None):
2626
2619
        import bzrlib.ui
2627
2620
        from bzrlib.tests import selftest
2628
2621
        import bzrlib.benchmarks as benchmarks
2664
2657
                              random_seed=randomize,
2665
2658
                              exclude_pattern=exclude,
2666
2659
                              strict=strict,
2667
 
                              coverage_dir=coverage,
 
2660
                              load_list=load_list,
2668
2661
                              )
2669
2662
        finally:
2670
2663
            if benchfile is not None:
2773
2766
            bzr merge -r 81..82 ../bzr.dev
2774
2767
    """
2775
2768
 
 
2769
    encoding_type = 'exact'
2776
2770
    _see_also = ['update', 'remerge', 'status-flags']
2777
2771
    takes_args = ['branch?']
2778
2772
    takes_options = [
2797
2791
               short_name='d',
2798
2792
               type=unicode,
2799
2793
               ),
 
2794
        Option('preview', help='Instead of merging, show a diff of the merge.')
2800
2795
    ]
2801
2796
 
2802
2797
    def run(self, branch=None, revision=None, force=False, merge_type=None,
2803
2798
            show_base=False, reprocess=False, remember=False,
2804
2799
            uncommitted=False, pull=False,
2805
2800
            directory=None,
 
2801
            preview=False,
2806
2802
            ):
2807
2803
        # This is actually a branch (or merge-directive) *location*.
2808
2804
        location = branch
2858
2854
            merger.merge_type = merge_type
2859
2855
            merger.reprocess = reprocess
2860
2856
            merger.show_base = show_base
2861
 
            merger.change_reporter = change_reporter
2862
2857
            self.sanity_check_merger(merger)
2863
2858
            if (merger.base_rev_id == merger.other_rev_id and
2864
2859
                merger.other_rev_id != None):
2873
2868
                    result.report(self.outf)
2874
2869
                    return 0
2875
2870
            merger.check_basis(not force)
2876
 
            conflict_count = merger.do_merge()
2877
 
            if allow_pending:
2878
 
                merger.set_pending()
2879
 
            if verified == 'failed':
2880
 
                warning('Preview patch does not match changes')
2881
 
            if conflict_count != 0:
2882
 
                return 1
 
2871
            if preview:
 
2872
                return self._do_preview(merger)
2883
2873
            else:
2884
 
                return 0
 
2874
                return self._do_merge(merger, change_reporter, allow_pending,
 
2875
                                      verified)
2885
2876
        finally:
2886
2877
            for cleanup in reversed(cleanups):
2887
2878
                cleanup()
2888
2879
 
 
2880
    def _do_preview(self, merger):
 
2881
        from bzrlib.diff import show_diff_trees
 
2882
        tree_merger = merger.make_merger()
 
2883
        tt = tree_merger.make_preview_transform()
 
2884
        try:
 
2885
            result_tree = tt.get_preview_tree()
 
2886
            show_diff_trees(merger.this_tree, result_tree, self.outf,
 
2887
                            old_label='', new_label='')
 
2888
        finally:
 
2889
            tt.finalize()
 
2890
 
 
2891
    def _do_merge(self, merger, change_reporter, allow_pending, verified):
 
2892
        merger.change_reporter = change_reporter
 
2893
        conflict_count = merger.do_merge()
 
2894
        if allow_pending:
 
2895
            merger.set_pending()
 
2896
        if verified == 'failed':
 
2897
            warning('Preview patch does not match changes')
 
2898
        if conflict_count != 0:
 
2899
            return 1
 
2900
        else:
 
2901
            return 0
 
2902
 
2889
2903
    def sanity_check_merger(self, merger):
2890
2904
        if (merger.show_base and
2891
2905
            not merger.merge_type is _mod_merge.Merge3Merger):
2905
2919
        from bzrlib.tag import _merge_tags_if_possible
2906
2920
        assert revision is None or len(revision) < 3
2907
2921
        # find the branch locations
2908
 
        other_loc, location = self._select_branch_location(tree, location,
 
2922
        other_loc, user_location = self._select_branch_location(tree, location,
2909
2923
            revision, -1)
2910
2924
        if revision is not None and len(revision) == 2:
2911
 
            base_loc, location = self._select_branch_location(tree, location,
2912
 
                                                              revision, 0)
 
2925
            base_loc, _unused = self._select_branch_location(tree,
 
2926
                location, revision, 0)
2913
2927
        else:
2914
2928
            base_loc = other_loc
2915
2929
        # Open the branches
2936
2950
        else:
2937
2951
            base_revision_id = None
2938
2952
        # Remember where we merge from
2939
 
        if ((tree.branch.get_parent() is None or remember) and
2940
 
            other_branch is not None):
2941
 
            tree.branch.set_parent(other_branch.base)
 
2953
        if ((remember or tree.branch.get_submit_branch() is None) and
 
2954
             user_location is not None):
 
2955
            tree.branch.set_submit_branch(other_branch.base)
2942
2956
        _merge_tags_if_possible(other_branch, tree.branch)
2943
2957
        merger = _mod_merge.Merger.from_revision_ids(pb, tree,
2944
2958
            other_revision_id, base_revision_id, other_branch, base_branch)
2949
2963
            allow_pending = True
2950
2964
        return merger, allow_pending
2951
2965
 
2952
 
    def _select_branch_location(self, tree, location, revision=None,
 
2966
    def _select_branch_location(self, tree, user_location, revision=None,
2953
2967
                                index=None):
2954
2968
        """Select a branch location, according to possible inputs.
2955
2969
 
2957
2971
        ``revision`` and ``index`` must be supplied.)
2958
2972
 
2959
2973
        Otherwise, the ``location`` parameter is used.  If it is None, then the
2960
 
        ``parent`` location is used, and a note is printed.
 
2974
        ``submit`` or ``parent`` location is used, and a note is printed.
2961
2975
 
2962
2976
        :param tree: The working tree to select a branch for merging into
2963
2977
        :param location: The location entered by the user
2964
2978
        :param revision: The revision parameter to the command
2965
2979
        :param index: The index to use for the revision parameter.  Negative
2966
2980
            indices are permitted.
2967
 
        :return: (selected_location, default_location).  The default location
2968
 
            will be the user-entered location, if any, or else the remembered
2969
 
            location.
 
2981
        :return: (selected_location, user_location).  The default location
 
2982
            will be the user-entered location.
2970
2983
        """
2971
2984
        if (revision is not None and index is not None
2972
2985
            and revision[index] is not None):
2973
2986
            branch = revision[index].get_branch()
2974
2987
            if branch is not None:
2975
 
                return branch, location
2976
 
        location = self._get_remembered_parent(tree, location, 'Merging from')
2977
 
        return location, location
 
2988
                return branch, branch
 
2989
        if user_location is None:
 
2990
            location = self._get_remembered(tree, 'Merging from')
 
2991
        else:
 
2992
            location = user_location
 
2993
        return location, user_location
2978
2994
 
2979
 
    # TODO: move up to common parent; this isn't merge-specific anymore. 
2980
 
    def _get_remembered_parent(self, tree, supplied_location, verb_string):
 
2995
    def _get_remembered(self, tree, verb_string):
2981
2996
        """Use tree.branch's parent if none was supplied.
2982
2997
 
2983
2998
        Report if the remembered location was used.
2984
2999
        """
2985
 
        if supplied_location is not None:
2986
 
            return supplied_location
2987
 
        stored_location = tree.branch.get_parent()
 
3000
        stored_location = tree.branch.get_submit_branch()
 
3001
        if stored_location is None:
 
3002
            stored_location = tree.branch.get_parent()
2988
3003
        mutter("%s", stored_location)
2989
3004
        if stored_location is None:
2990
3005
            raise errors.BzrCommandError("No location specified or remembered")
3340
3355
class cmd_plugins(Command):
3341
3356
    """List the installed plugins.
3342
3357
    
3343
 
    This command displays the list of installed plugins including the
3344
 
    path where each one is located and a short description of each.
 
3358
    This command displays the list of installed plugins including
 
3359
    version of plugin and a short description of each.
 
3360
 
 
3361
    --verbose shows the path where each plugin is located.
3345
3362
 
3346
3363
    A plugin is an external component for Bazaar that extends the
3347
3364
    revision control system, by adding or replacing code in Bazaar.
3354
3371
    install them. Instructions are also provided there on how to
3355
3372
    write new plugins using the Python programming language.
3356
3373
    """
 
3374
    takes_options = ['verbose']
3357
3375
 
3358
3376
    @display_command
3359
 
    def run(self):
 
3377
    def run(self, verbose=False):
3360
3378
        import bzrlib.plugin
3361
3379
        from inspect import getdoc
 
3380
        result = []
3362
3381
        for name, plugin in bzrlib.plugin.plugins().items():
3363
 
            print plugin.path(), "[%s]" % plugin.__version__
 
3382
            version = plugin.__version__
 
3383
            if version == 'unknown':
 
3384
                version = ''
 
3385
            name_ver = '%s %s' % (name, version)
3364
3386
            d = getdoc(plugin.module)
3365
3387
            if d:
3366
 
                print '\t', d.split('\n')[0]
 
3388
                doc = d.split('\n')[0]
 
3389
            else:
 
3390
                doc = '(no description)'
 
3391
            result.append((name_ver, doc, plugin.path()))
 
3392
        for name_ver, doc, path in sorted(result):
 
3393
            print name_ver
 
3394
            print '   ', doc
 
3395
            if verbose:
 
3396
                print '   ', path
 
3397
            print
3367
3398
 
3368
3399
 
3369
3400
class cmd_testament(Command):
3422
3453
    def run(self, filename, all=False, long=False, revision=None,
3423
3454
            show_ids=False):
3424
3455
        from bzrlib.annotate import annotate_file
3425
 
        tree, relpath = WorkingTree.open_containing(filename)
3426
 
        branch = tree.branch
3427
 
        branch.lock_read()
 
3456
        wt, branch, relpath = \
 
3457
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
3458
        if wt is not None:
 
3459
            wt.lock_read()
 
3460
        else:
 
3461
            branch.lock_read()
3428
3462
        try:
3429
3463
            if revision is None:
3430
3464
                revision_id = branch.last_revision()
3432
3466
                raise errors.BzrCommandError('bzr annotate --revision takes exactly 1 argument')
3433
3467
            else:
3434
3468
                revision_id = revision[0].in_history(branch).rev_id
3435
 
            file_id = tree.path2id(relpath)
 
3469
            tree = branch.repository.revision_tree(revision_id)
 
3470
            if wt is not None:
 
3471
                file_id = wt.path2id(relpath)
 
3472
            else:
 
3473
                file_id = tree.path2id(relpath)
3436
3474
            if file_id is None:
3437
3475
                raise errors.NotVersionedError(filename)
3438
 
            tree = branch.repository.revision_tree(revision_id)
3439
3476
            file_version = tree.inventory[file_id].revision
3440
3477
            annotate_file(branch, file_version, file_id, long, all, self.outf,
3441
3478
                          show_ids=show_ids)
3442
3479
        finally:
3443
 
            branch.unlock()
 
3480
            if wt is not None:
 
3481
                wt.unlock()
 
3482
            else:
 
3483
                branch.unlock()
3444
3484
 
3445
3485
 
3446
3486
class cmd_re_sign(Command):