/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: Andrew Bennetts
  • Date: 2008-04-02 00:14:00 UTC
  • mfrom: (3324 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3756.
  • Revision ID: andrew.bennetts@canonical.com-20080402001400-r1pqse38i03dl97w
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
534
534
        if len(names_list) < 2:
535
535
            raise errors.BzrCommandError("missing file argument")
536
536
        tree, rel_names = tree_files(names_list)
 
537
        tree.lock_write()
 
538
        try:
 
539
            self._run(tree, names_list, rel_names, after)
 
540
        finally:
 
541
            tree.unlock()
537
542
 
538
 
        dest = names_list[-1]
539
 
        isdir = os.path.isdir(dest)
540
 
        if (isdir and not tree.case_sensitive and len(rel_names) == 2
541
 
            and rel_names[0].lower() == rel_names[1].lower()):
542
 
                isdir = False
543
 
        if isdir:
 
543
    def _run(self, tree, names_list, rel_names, after):
 
544
        into_existing = osutils.isdir(names_list[-1])
 
545
        if into_existing and len(names_list) == 2:
 
546
            # special cases:
 
547
            # a. case-insensitive filesystem and change case of dir
 
548
            # b. move directory after the fact (if the source used to be
 
549
            #    a directory, but now doesn't exist in the working tree
 
550
            #    and the target is an existing directory, just rename it)
 
551
            if (not tree.case_sensitive
 
552
                and rel_names[0].lower() == rel_names[1].lower()):
 
553
                into_existing = False
 
554
            else:
 
555
                inv = tree.inventory
 
556
                from_id = tree.path2id(rel_names[0])
 
557
                if (not osutils.lexists(names_list[0]) and
 
558
                    from_id and inv.get_file_kind(from_id) == "directory"):
 
559
                    into_existing = False
 
560
        # move/rename
 
561
        if into_existing:
544
562
            # move into existing directory
545
563
            for pair in tree.move(rel_names[:-1], rel_names[-1], after=after):
546
564
                self.outf.write("%s => %s\n" % pair)
571
589
    that, you can omit the location to use the default.  To change the
572
590
    default, use --remember. The value will only be saved if the remote
573
591
    location can be accessed.
 
592
 
 
593
    Note: The location can be specified either in the form of a branch,
 
594
    or in the form of a path to a file containing a merge directive generated
 
595
    with bzr send.
574
596
    """
575
597
 
576
598
    _see_also = ['push', 'update', 'status-flags']
604
626
 
605
627
        possible_transports = []
606
628
        if location is not None:
607
 
            mergeable, location_transport = _get_mergeable_helper(location)
608
 
            possible_transports.append(location_transport)
 
629
            try:
 
630
                mergeable = bundle.read_mergeable_from_url(location,
 
631
                    possible_transports=possible_transports)
 
632
            except errors.NotABundle:
 
633
                mergeable = None
609
634
 
610
635
        stored_loc = branch_to.get_parent()
611
636
        if location is None:
618
643
                if not is_quiet():
619
644
                    self.outf.write("Using saved location: %s\n" % display_url)
620
645
                location = stored_loc
621
 
                location_transport = transport.get_transport(
622
 
                    location, possible_transports=possible_transports)
623
646
 
624
647
        if mergeable is not None:
625
648
            if revision is not None:
630
653
                mergeable.get_merge_request(branch_to.repository)
631
654
            branch_from = branch_to
632
655
        else:
633
 
            branch_from = Branch.open_from_transport(location_transport)
 
656
            branch_from = Branch.open(location,
 
657
                possible_transports=possible_transports)
634
658
 
635
659
            if branch_to.get_parent() is None or remember:
636
660
                branch_to.set_parent(branch_from.base)
2648
2672
            print '   %s (%s python%s)' % (
2649
2673
                    bzrlib.__path__[0],
2650
2674
                    bzrlib.version_string,
2651
 
                    '.'.join(map(str, sys.version_info)),
 
2675
                    bzrlib._format_version_tuple(sys.version_info),
2652
2676
                    )
2653
2677
        print
2654
2678
        if testspecs_list is not None:
2743
2767
class cmd_merge(Command):
2744
2768
    """Perform a three-way merge.
2745
2769
    
2746
 
    The branch is the branch you will merge from.  By default, it will merge
2747
 
    the latest revision.  If you specify a revision, that revision will be
2748
 
    merged.  If you specify two revisions, the first will be used as a BASE,
2749
 
    and the second one as OTHER.  Revision numbers are always relative to the
2750
 
    specified branch.
 
2770
    The source of the merge can be specified either in the form of a branch,
 
2771
    or in the form of a path to a file containing a merge directive generated
 
2772
    with bzr send. If neither is specified, the default is the upstream branch
 
2773
    or the branch most recently merged using --remember.
 
2774
 
 
2775
    When merging a branch, by default the tip will be merged. To pick a different
 
2776
    revision, pass --revision. If you specify two values, the first will be used as
 
2777
    BASE and the second one as OTHER. Merging individual revisions, or a subset of
 
2778
    available revisions, like this is commonly referred to as "cherrypicking".
 
2779
 
 
2780
    Revision numbers are always relative to the branch being merged.
2751
2781
 
2752
2782
    By default, bzr will try to merge in all new work from the other
2753
2783
    branch, automatically determining an appropriate base.  If this
2784
2814
        To merge the changes introduced by 82, without previous changes::
2785
2815
 
2786
2816
            bzr merge -r 81..82 ../bzr.dev
 
2817
 
 
2818
        To apply a merge directive contained in in /tmp/merge:
 
2819
 
 
2820
            bzr merge /tmp/merge
2787
2821
    """
2788
2822
 
2789
2823
    encoding_type = 'exact'
2790
2824
    _see_also = ['update', 'remerge', 'status-flags']
2791
 
    takes_args = ['branch?']
 
2825
    takes_args = ['location?']
2792
2826
    takes_options = [
2793
2827
        'change',
2794
2828
        'revision',
2814
2848
        Option('preview', help='Instead of merging, show a diff of the merge.')
2815
2849
    ]
2816
2850
 
2817
 
    def run(self, branch=None, revision=None, force=False, merge_type=None,
2818
 
            show_base=False, reprocess=False, remember=False,
 
2851
    def run(self, location=None, revision=None, force=False,
 
2852
            merge_type=None, show_base=False, reprocess=False, remember=False,
2819
2853
            uncommitted=False, pull=False,
2820
2854
            directory=None,
2821
2855
            preview=False,
2822
2856
            ):
2823
 
        # This is actually a branch (or merge-directive) *location*.
2824
 
        location = branch
2825
 
        del branch
2826
 
 
2827
2857
        if merge_type is None:
2828
2858
            merge_type = _mod_merge.Merge3Merger
2829
2859
 
2842
2872
            tree.lock_write()
2843
2873
            cleanups.append(tree.unlock)
2844
2874
            if location is not None:
2845
 
                mergeable, other_transport = _get_mergeable_helper(location)
2846
 
                if mergeable:
 
2875
                try:
 
2876
                    mergeable = bundle.read_mergeable_from_url(location,
 
2877
                        possible_transports=possible_transports)
 
2878
                except errors.NotABundle:
 
2879
                    mergeable = None
 
2880
                else:
2847
2881
                    if uncommitted:
2848
2882
                        raise errors.BzrCommandError('Cannot use --uncommitted'
2849
2883
                            ' with bundles or merge directives.')
2853
2887
                            'Cannot use -r with merge directives or bundles')
2854
2888
                    merger, verified = _mod_merge.Merger.from_mergeable(tree,
2855
2889
                       mergeable, pb)
2856
 
                possible_transports.append(other_transport)
2857
2890
 
2858
2891
            if merger is None and uncommitted:
2859
2892
                if revision is not None and len(revision) > 0:
3639
3672
    _see_also = ['commit']
3640
3673
    takes_options = ['verbose', 'revision',
3641
3674
                    Option('dry-run', help='Don\'t actually make changes.'),
3642
 
                    Option('force', help='Say yes to all questions.')]
 
3675
                    Option('force', help='Say yes to all questions.'),
 
3676
                    Option('local',
 
3677
                           help="Only remove the commits from the local branch"
 
3678
                                " when in a checkout."
 
3679
                           ),
 
3680
                    ]
3643
3681
    takes_args = ['location?']
3644
3682
    aliases = []
3645
3683
    encoding_type = 'replace'
3646
3684
 
3647
3685
    def run(self, location=None,
3648
3686
            dry_run=False, verbose=False,
3649
 
            revision=None, force=False):
 
3687
            revision=None, force=False, local=False):
3650
3688
        if location is None:
3651
3689
            location = u'.'
3652
3690
        control, relpath = bzrdir.BzrDir.open_containing(location)
3662
3700
        else:
3663
3701
            b.lock_write()
3664
3702
        try:
3665
 
            return self._run(b, tree, dry_run, verbose, revision, force)
 
3703
            return self._run(b, tree, dry_run, verbose, revision, force,
 
3704
                             local=local)
3666
3705
        finally:
3667
3706
            if tree is not None:
3668
3707
                tree.unlock()
3669
3708
            else:
3670
3709
                b.unlock()
3671
3710
 
3672
 
    def _run(self, b, tree, dry_run, verbose, revision, force):
 
3711
    def _run(self, b, tree, dry_run, verbose, revision, force, local=False):
3673
3712
        from bzrlib.log import log_formatter, show_log
3674
3713
        from bzrlib.uncommit import uncommit
3675
3714
 
3717
3756
                    return 0
3718
3757
 
3719
3758
        uncommit(b, tree=tree, dry_run=dry_run, verbose=verbose,
3720
 
                 revno=revno)
 
3759
                 revno=revno, local=local)
3721
3760
 
3722
3761
 
3723
3762
class cmd_break_lock(Command):
4049
4088
    older formats.  It is compatible with Bazaar 0.19 and later.  It is the
4050
4089
    default.  "0.9" uses revision bundle format 0.9 and merge directive
4051
4090
    format 1.  It is compatible with Bazaar 0.12 - 0.18.
 
4091
    
 
4092
    Merge directives are applied using the merge command or the pull command.
4052
4093
    """
4053
4094
 
4054
4095
    encoding_type = 'exact'
4055
4096
 
4056
 
    _see_also = ['merge']
 
4097
    _see_also = ['merge', 'pull']
4057
4098
 
4058
4099
    takes_args = ['submit_branch?', 'public_branch?']
4059
4100
 
4496
4537
        cur_transport.ensure_base()
4497
4538
 
4498
4539
 
4499
 
def _get_mergeable_helper(location):
4500
 
    """Get a merge directive or bundle if 'location' points to one.
4501
 
 
4502
 
    Try try to identify a bundle and returns its mergeable form. If it's not,
4503
 
    we return the tried transport anyway so that it can reused to access the
4504
 
    branch
4505
 
 
4506
 
    :param location: can point to a bundle or a branch.
4507
 
 
4508
 
    :return: mergeable, transport
4509
 
    """
4510
 
    mergeable = None
4511
 
    url = urlutils.normalize_url(location)
4512
 
    url, filename = urlutils.split(url, exclude_trailing_slash=False)
4513
 
    location_transport = transport.get_transport(url)
4514
 
    if filename:
4515
 
        try:
4516
 
            # There may be redirections but we ignore the intermediate
4517
 
            # and final transports used
4518
 
            read = bundle.read_mergeable_from_transport
4519
 
            mergeable, t = read(location_transport, filename)
4520
 
        except errors.NotABundle:
4521
 
            # Continue on considering this url a Branch but adjust the
4522
 
            # location_transport
4523
 
            location_transport = location_transport.clone(filename)
4524
 
    return mergeable, location_transport
4525
 
 
4526
 
 
4527
4540
# these get imported and then picked up by the scan for cmd_*
4528
4541
# TODO: Some more consistent way to split command definitions across files;
4529
4542
# we do need to load at least some information about them to know of