/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: Robert Collins
  • Date: 2007-08-07 22:59:45 UTC
  • mfrom: (2681 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2682.
  • Revision ID: robertc@robertcollins.net-20070807225945-dlxppeb3we4lh897
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
501
501
class cmd_mv(Command):
502
502
    """Move or rename a file.
503
503
 
504
 
    usage:
 
504
    :Usage:
505
505
        bzr mv OLDNAME NEWNAME
 
506
 
506
507
        bzr mv SOURCE... DESTINATION
507
508
 
508
509
    If the last argument is a versioned directory, all the other names
581
582
    def run(self, location=None, remember=False, overwrite=False,
582
583
            revision=None, verbose=False,
583
584
            directory=None):
584
 
        from bzrlib.tag import _merge_tags_if_possible
585
585
        # FIXME: too much stuff is in the command class
586
586
        revision_id = None
587
587
        mergeable = None
594
594
            tree_to = None
595
595
            branch_to = Branch.open_containing(directory)[0]
596
596
 
597
 
        reader = None
598
597
        if location is not None:
599
 
            try:
600
 
                mergeable = bundle.read_mergeable_from_url(
601
 
                    location)
602
 
            except errors.NotABundle:
603
 
                pass # Continue on considering this url a Branch
 
598
            mergeable, location_transport = _get_mergeable_helper(location)
604
599
 
605
600
        stored_loc = branch_to.get_parent()
606
601
        if location is None:
612
607
                        self.outf.encoding)
613
608
                self.outf.write("Using saved location: %s\n" % display_url)
614
609
                location = stored_loc
 
610
                location_transport = transport.get_transport(location)
615
611
 
616
612
        if mergeable is not None:
617
613
            if revision is not None:
622
618
                mergeable.get_merge_request(branch_to.repository)
623
619
            branch_from = branch_to
624
620
        else:
625
 
            branch_from = Branch.open(location)
 
621
            branch_from = Branch.open_from_transport(location_transport)
626
622
 
627
623
            if branch_to.get_parent() is None or remember:
628
624
                branch_to.set_parent(branch_from.base)
885
881
                                             % to_location)
886
882
            try:
887
883
                # preserve whatever source format we have.
888
 
                dir = br_from.bzrdir.sprout(to_transport.base, revision_id)
 
884
                dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
 
885
                                            possible_transports=[to_transport])
889
886
                branch = dir.open_branch()
890
887
            except errors.NoSuchRevision:
891
888
                to_transport.delete_tree('.')
945
942
            to_location = branch_location
946
943
        source = Branch.open(branch_location)
947
944
        if len(revision) == 1 and revision[0] is not None:
948
 
            revision_id = revision[0].in_history(source)[1]
 
945
            revision_id = _mod_revision.ensure_null(
 
946
                revision[0].in_history(source)[1])
949
947
        else:
950
948
            revision_id = None
951
949
        if to_location is None:
958
956
            try:
959
957
                source.bzrdir.open_workingtree()
960
958
            except errors.NoWorkingTree:
961
 
                source.bzrdir.create_workingtree()
 
959
                source.bzrdir.create_workingtree(revision_id)
962
960
                return
963
961
        try:
964
962
            os.mkdir(to_location)
1014
1012
    'bzr revert' instead of 'bzr commit' after the update.
1015
1013
    """
1016
1014
 
1017
 
    _see_also = ['pull', 'working-trees']
 
1015
    _see_also = ['pull', 'working-trees', 'status-flags']
1018
1016
    takes_args = ['dir?']
1019
1017
    aliases = ['up']
1020
1018
 
1031
1029
            if last_rev == _mod_revision.ensure_null(
1032
1030
                tree.branch.last_revision()):
1033
1031
                # may be up to date, check master too.
1034
 
                master = tree.branch.get_master_branch()
1035
1032
                if master is None or last_rev == _mod_revision.ensure_null(
1036
1033
                    master.last_revision()):
1037
1034
                    revno = tree.branch.revision_id_to_revno(last_rev)
1247
1244
    If there is already a branch at the location but it has no working tree,
1248
1245
    the tree can be populated with 'bzr checkout'.
1249
1246
 
1250
 
    Recipe for importing a tree of files:
 
1247
    Recipe for importing a tree of files::
 
1248
 
1251
1249
        cd ~/project
1252
1250
        bzr init
1253
1251
        bzr add .
1299
1297
            _create_prefix(to_transport)
1300
1298
 
1301
1299
        try:
1302
 
            existing_bzrdir = bzrdir.BzrDir.open(location)
 
1300
            existing_bzrdir = bzrdir.BzrDir.open_from_transport(to_transport)
1303
1301
        except errors.NotBranchError:
1304
1302
            # really a NotBzrDir error...
1305
 
            branch = bzrdir.BzrDir.create_branch_convenience(to_transport.base,
1306
 
                                                             format=format)
 
1303
            create_branch = bzrdir.BzrDir.create_branch_convenience
 
1304
            branch = create_branch(to_transport.base, format=format,
 
1305
                                   possible_transports=[to_transport])
1307
1306
        else:
1308
1307
            from bzrlib.transport.local import LocalTransport
1309
1308
            if existing_bzrdir.has_branch():
1331
1330
    If the --no-trees option is used then the branches in the repository
1332
1331
    will not have working trees by default.
1333
1332
 
1334
 
    example:
1335
 
        bzr init-repo --no-trees repo
1336
 
        bzr init repo/trunk
1337
 
        bzr checkout --lightweight repo/trunk trunk-checkout
1338
 
        cd trunk-checkout
1339
 
        (add files here)
1340
 
 
1341
 
    See 'bzr help repositories' for more information.
 
1333
    :Examples:
 
1334
        Create a shared repositories holding just branches::
 
1335
 
 
1336
            bzr init-repo --no-trees repo
 
1337
            bzr init repo/trunk
 
1338
 
 
1339
        Make a lightweight checkout elsewhere::
 
1340
 
 
1341
            bzr checkout --lightweight repo/trunk trunk-checkout
 
1342
            cd trunk-checkout
 
1343
            (add files here)
1342
1344
    """
1343
1345
 
1344
 
    _see_also = ['init', 'branch', 'checkout']
 
1346
    _see_also = ['init', 'branch', 'checkout', 'repositories']
1345
1347
    takes_args = ["location"]
1346
1348
    takes_options = [RegistryOption('format',
1347
1349
                            help='Specify a format for this repository. See'
1379
1381
    "bzr diff -p1" is equivalent to "bzr diff --prefix old/:new/", and
1380
1382
    produces patches suitable for "patch -p1".
1381
1383
 
1382
 
    examples:
1383
 
        bzr diff
1384
 
            Shows the difference in the working tree versus the last commit
1385
 
        bzr diff -r1
1386
 
            Difference between the working tree and revision 1
1387
 
        bzr diff -r1..2
1388
 
            Difference between revision 2 and revision 1
1389
 
        bzr diff --prefix old/:new/
1390
 
            Same as 'bzr diff' but prefix paths with old/ and new/
1391
 
        bzr diff bzr.mine bzr.dev
1392
 
            Show the differences between the two working trees
1393
 
        bzr diff foo.c
1394
 
            Show just the differences for 'foo.c'
 
1384
    :Examples:
 
1385
        Shows the difference in the working tree versus the last commit::
 
1386
 
 
1387
            bzr diff
 
1388
 
 
1389
        Difference between the working tree and revision 1::
 
1390
 
 
1391
            bzr diff -r1
 
1392
 
 
1393
        Difference between revision 2 and revision 1::
 
1394
 
 
1395
            bzr diff -r1..2
 
1396
 
 
1397
        Same as 'bzr diff' but prefix paths with old/ and new/::
 
1398
 
 
1399
            bzr diff --prefix old/:new/
 
1400
 
 
1401
        Show the differences between the two working trees::
 
1402
 
 
1403
            bzr diff bzr.mine bzr.dev
 
1404
 
 
1405
        Show just the differences for 'foo.c'::
 
1406
 
 
1407
            bzr diff foo.c
1395
1408
    """
1396
1409
    # TODO: Option to use external diff command; could be GNU diff, wdiff,
1397
1410
    #       or a graphical diff.
1595
1608
    -r revision requests a specific revision, -r ..end or -r begin.. are
1596
1609
    also valid.
1597
1610
 
1598
 
    examples:
1599
 
        bzr log
1600
 
        bzr log foo.c
1601
 
        bzr log -r -10.. http://server/branch
 
1611
    :Examples:
 
1612
        Log the current branch::
 
1613
 
 
1614
            bzr log
 
1615
 
 
1616
        Log a file::
 
1617
 
 
1618
            bzr log foo.c
 
1619
 
 
1620
        Log the last 10 revisions of a branch::
 
1621
 
 
1622
            bzr log -r -10.. http://server/branch
1602
1623
    """
1603
1624
 
1604
1625
    # TODO: Make --revision support uuid: and hash: [future tag:] notation.
1861
1882
 
1862
1883
    Ignore patterns specifying absolute paths are not allowed.
1863
1884
 
1864
 
    Ignore patterns may include globbing wildcards such as:
 
1885
    Ignore patterns may include globbing wildcards such as::
 
1886
 
1865
1887
      ? - Matches any single character except '/'
1866
1888
      * - Matches 0 or more characters except '/'
1867
1889
      /**/ - Matches 0 or more directories in a path
1875
1897
    Note: ignore patterns containing shell wildcards must be quoted from 
1876
1898
    the shell on Unix.
1877
1899
 
1878
 
    examples:
1879
 
        bzr ignore ./Makefile
1880
 
        bzr ignore '*.class'
1881
 
        bzr ignore 'lib/**/*.o'
1882
 
        bzr ignore 'RE:lib/.*\.o'
 
1900
    :Examples:
 
1901
        Ignore the top level Makefile::
 
1902
 
 
1903
            bzr ignore ./Makefile
 
1904
 
 
1905
        Ignore class files in all directories::
 
1906
 
 
1907
            bzr ignore '*.class'
 
1908
 
 
1909
        Ignore .o files under the lib directory::
 
1910
 
 
1911
            bzr ignore 'lib/**/*.o'
 
1912
 
 
1913
        Ignore .o files under the lib directory::
 
1914
 
 
1915
            bzr ignore 'RE:lib/.*\.o'
1883
1916
    """
1884
1917
 
1885
1918
    _see_also = ['status', 'ignored']
1959
1992
class cmd_lookup_revision(Command):
1960
1993
    """Lookup the revision-id from a revision-number
1961
1994
 
1962
 
    example:
 
1995
    :Examples:
1963
1996
        bzr lookup-revision 33
1964
1997
    """
1965
1998
    hidden = True
1993
2026
 
1994
2027
    Note: Export of tree with non-ASCII filenames to zip is not supported.
1995
2028
 
1996
 
     Supported formats       Autodetected by extension
1997
 
     -----------------       -------------------------
1998
 
         dir                            -
 
2029
      =================       =========================
 
2030
      Supported formats       Autodetected by extension
 
2031
      =================       =========================
 
2032
         dir                         (none)
1999
2033
         tar                          .tar
2000
2034
         tbz2                    .tar.bz2, .tbz2
2001
2035
         tgz                      .tar.gz, .tgz
2002
2036
         zip                          .zip
 
2037
      =================       =========================
2003
2038
    """
2004
2039
    takes_args = ['dest', 'branch?']
2005
2040
    takes_options = [
2315
2350
class cmd_whoami(Command):
2316
2351
    """Show or set bzr user id.
2317
2352
    
2318
 
    examples:
2319
 
        bzr whoami --email
2320
 
        bzr whoami 'Frank Chu <fchu@example.com>'
 
2353
    :Examples:
 
2354
        Show the email of the current user::
 
2355
 
 
2356
            bzr whoami --email
 
2357
 
 
2358
        Set the current user::
 
2359
 
 
2360
            bzr whoami 'Frank Chu <fchu@example.com>'
2321
2361
    """
2322
2362
    takes_options = [ Option('email',
2323
2363
                             help='Display email address only.'),
2412
2452
    Tests that need working space on disk use a common temporary directory, 
2413
2453
    typically inside $TMPDIR or /tmp.
2414
2454
 
2415
 
    examples::
2416
 
        bzr selftest ignore
2417
 
            run only tests relating to 'ignore'
2418
 
        bzr --no-plugins selftest -v
2419
 
            disable plugins and list tests as they're run
 
2455
    :Examples:
 
2456
        Run only tests relating to 'ignore'::
 
2457
 
 
2458
            bzr selftest ignore
 
2459
 
 
2460
        Disable plugins and list tests as they're run::
 
2461
 
 
2462
            bzr --no-plugins selftest -v
2420
2463
    """
2421
2464
    # NB: this is used from the class without creating an instance, which is
2422
2465
    # why it does not have a self parameter.
2594
2637
    The results of the merge are placed into the destination working
2595
2638
    directory, where they can be reviewed (with bzr diff), tested, and then
2596
2639
    committed to record the result of the merge.
2597
 
 
2598
 
    Examples:
2599
 
 
2600
 
    To merge the latest revision from bzr.dev:
2601
 
        bzr merge ../bzr.dev
2602
 
 
2603
 
    To merge changes up to and including revision 82 from bzr.dev:
2604
 
        bzr merge -r 82 ../bzr.dev
2605
 
 
2606
 
    To merge the changes introduced by 82, without previous changes:
2607
 
        bzr merge -r 81..82 ../bzr.dev
2608
2640
    
2609
2641
    merge refuses to run if there are any uncommitted changes, unless
2610
2642
    --force is given.
 
2643
 
 
2644
    :Examples:
 
2645
        To merge the latest revision from bzr.dev::
 
2646
 
 
2647
            bzr merge ../bzr.dev
 
2648
 
 
2649
        To merge changes up to and including revision 82 from bzr.dev::
 
2650
 
 
2651
            bzr merge -r 82 ../bzr.dev
 
2652
 
 
2653
        To merge the changes introduced by 82, without previous changes::
 
2654
 
 
2655
            bzr merge -r 81..82 ../bzr.dev
2611
2656
    """
2612
2657
 
2613
2658
    _see_also = ['update', 'remerge', 'status-flags']
2641
2686
            directory=None,
2642
2687
            ):
2643
2688
        from bzrlib.tag import _merge_tags_if_possible
2644
 
        other_revision_id = None
2645
 
        base_revision_id = None
 
2689
        # This is actually a branch (or merge-directive) *location*.
 
2690
        location = branch
 
2691
        del branch
 
2692
 
2646
2693
        if merge_type is None:
2647
2694
            merge_type = _mod_merge.Merge3Merger
2648
2695
 
2649
2696
        if directory is None: directory = u'.'
2650
 
        # XXX: jam 20070225 WorkingTree should be locked before you extract its
2651
 
        #      inventory. Because merge is a mutating operation, it really
2652
 
        #      should be a lock_write() for the whole cmd_merge operation.
2653
 
        #      However, cmd_merge open's its own tree in _merge_helper, which
2654
 
        #      means if we lock here, the later lock_write() will always block.
2655
 
        #      Either the merge helper code should be updated to take a tree,
2656
 
        #      (What about tree.merge_from_branch?)
 
2697
        possible_transports = []
 
2698
        merger = None
 
2699
        allow_pending = True
 
2700
        verified = 'inapplicable'
2657
2701
        tree = WorkingTree.open_containing(directory)[0]
2658
2702
        change_reporter = delta._ChangeReporter(
2659
2703
            unversioned_filter=tree.is_ignored)
2660
 
 
2661
 
        if branch is not None:
2662
 
            try:
2663
 
                mergeable = bundle.read_mergeable_from_url(
2664
 
                    branch)
2665
 
            except errors.NotABundle:
2666
 
                pass # Continue on considering this url a Branch
2667
 
            else:
2668
 
                if revision is not None:
2669
 
                    raise errors.BzrCommandError(
2670
 
                        'Cannot use -r with merge directives or bundles')
2671
 
                mergeable.install_revisions(tree.branch.repository)
2672
 
                base_revision_id, other_revision_id, verified =\
2673
 
                    mergeable.get_merge_request(tree.branch.repository)
2674
 
                if base_revision_id in tree.branch.repository.get_ancestry(
2675
 
                    tree.branch.last_revision(), topo_sorted=False):
2676
 
                    base_revision_id = None
2677
 
                other_branch = None
2678
 
                path = ''
2679
 
                other = None
2680
 
                base = None
2681
 
 
2682
 
        if other_revision_id is None:
2683
 
            verified = 'inapplicable'
2684
 
            if revision is None \
2685
 
                    or len(revision) < 1 or revision[0].needs_branch():
2686
 
                branch = self._get_remembered_parent(tree, branch,
2687
 
                    'Merging from')
2688
 
 
2689
 
            if revision is None or len(revision) < 1:
2690
 
                if uncommitted:
2691
 
                    base = [branch, -1]
2692
 
                    other = [branch, None]
2693
 
                else:
2694
 
                    base = [None, None]
2695
 
                    other = [branch, -1]
2696
 
                other_branch, path = Branch.open_containing(branch)
2697
 
            else:
2698
 
                if uncommitted:
 
2704
        cleanups = []
 
2705
        try:
 
2706
            pb = ui.ui_factory.nested_progress_bar()
 
2707
            cleanups.append(pb.finished)
 
2708
            tree.lock_write()
 
2709
            cleanups.append(tree.unlock)
 
2710
            if location is not None:
 
2711
                mergeable, other_transport = _get_mergeable_helper(location)
 
2712
                if mergeable:
 
2713
                    if uncommitted:
 
2714
                        raise errors.BzrCommandError('Cannot use --uncommitted'
 
2715
                            ' with bundles or merge directives.')
 
2716
 
 
2717
                    if revision is not None:
 
2718
                        raise errors.BzrCommandError(
 
2719
                            'Cannot use -r with merge directives or bundles')
 
2720
                    merger, verified = _mod_merge.Merger.from_mergeable(tree,
 
2721
                       mergeable, pb)
 
2722
                possible_transports.append(other_transport)
 
2723
 
 
2724
            if merger is None and uncommitted:
 
2725
                if revision is not None and len(revision) > 0:
2699
2726
                    raise errors.BzrCommandError('Cannot use --uncommitted and'
2700
2727
                        ' --revision at the same time.')
2701
 
                branch = revision[0].get_branch() or branch
2702
 
                if len(revision) == 1:
2703
 
                    base = [None, None]
2704
 
                    other_branch, path = Branch.open_containing(branch)
2705
 
                    revno = revision[0].in_history(other_branch).revno
2706
 
                    other = [branch, revno]
2707
 
                else:
2708
 
                    assert len(revision) == 2
2709
 
                    if None in revision:
2710
 
                        raise errors.BzrCommandError(
2711
 
                            "Merge doesn't permit empty revision specifier.")
2712
 
                    base_branch, path = Branch.open_containing(branch)
2713
 
                    branch1 = revision[1].get_branch() or branch
2714
 
                    other_branch, path1 = Branch.open_containing(branch1)
2715
 
                    if revision[0].get_branch() is not None:
2716
 
                        # then path was obtained from it, and is None.
2717
 
                        path = path1
2718
 
 
2719
 
                    base = [branch, revision[0].in_history(base_branch).revno]
2720
 
                    other = [branch1,
2721
 
                             revision[1].in_history(other_branch).revno]
2722
 
 
 
2728
                location = self._select_branch_location(tree, location)[0]
 
2729
                other_tree, other_path = WorkingTree.open_containing(location)
 
2730
                merger = _mod_merge.Merger.from_uncommitted(tree, other_tree,
 
2731
                    pb)
 
2732
                allow_pending = False
 
2733
 
 
2734
            if merger is None:
 
2735
                merger, allow_pending = self._get_merger_from_branch(tree,
 
2736
                    location, revision, remember, possible_transports, pb)
 
2737
 
 
2738
            merger.merge_type = merge_type
 
2739
            merger.reprocess = reprocess
 
2740
            merger.show_base = show_base
 
2741
            merger.change_reporter = change_reporter
 
2742
            self.sanity_check_merger(merger)
 
2743
            if (merger.base_rev_id == merger.other_rev_id and
 
2744
                merger.other_rev_id != None):
 
2745
                note('Nothing to do.')
 
2746
                return 0
 
2747
            if pull:
 
2748
                if merger.interesting_files is not None:
 
2749
                    raise BzrCommandError('Cannot pull individual files')
 
2750
                if (merger.base_rev_id == tree.last_revision()):
 
2751
                    result = tree.pull(merger.other_branch, False,
 
2752
                                       merger.other_rev_id)
 
2753
                    result.report(self.outf)
 
2754
                    return 0
 
2755
            merger.check_basis(not force)
 
2756
            conflict_count = merger.do_merge()
 
2757
            if allow_pending:
 
2758
                merger.set_pending()
 
2759
            if verified == 'failed':
 
2760
                warning('Preview patch does not match changes')
 
2761
            if conflict_count != 0:
 
2762
                return 1
 
2763
            else:
 
2764
                return 0
 
2765
        finally:
 
2766
            for cleanup in reversed(cleanups):
 
2767
                cleanup()
 
2768
 
 
2769
    def sanity_check_merger(self, merger):
 
2770
        if (merger.show_base and
 
2771
            not merger.merge_type is _mod_merge.Merge3Merger):
 
2772
            raise errors.BzrCommandError("Show-base is not supported for this"
 
2773
                                         " merge type. %s" % merger.merge_type)
 
2774
        if merger.reprocess and not merger.merge_type.supports_reprocess:
 
2775
            raise errors.BzrCommandError("Conflict reduction is not supported"
 
2776
                                         " for merge type %s." %
 
2777
                                         merger.merge_type)
 
2778
        if merger.reprocess and merger.show_base:
 
2779
            raise errors.BzrCommandError("Cannot do conflict reduction and"
 
2780
                                         " show base.")
 
2781
 
 
2782
    def _get_merger_from_branch(self, tree, location, revision, remember,
 
2783
                                possible_transports, pb):
 
2784
        """Produce a merger from a location, assuming it refers to a branch."""
 
2785
        from bzrlib.tag import _merge_tags_if_possible
 
2786
        assert revision is None or len(revision) < 3
 
2787
        # find the branch locations
 
2788
        other_loc, location = self._select_branch_location(tree, location,
 
2789
            revision, -1)
 
2790
        if revision is not None and len(revision) == 2:
 
2791
            base_loc, location = self._select_branch_location(tree, location,
 
2792
                                                              revision, 0)
 
2793
        else:
 
2794
            base_loc = other_loc
 
2795
        # Open the branches
 
2796
        other_branch, other_path = Branch.open_containing(other_loc,
 
2797
            possible_transports)
 
2798
        if base_loc == other_loc:
 
2799
            base_branch = other_branch
 
2800
        else:
 
2801
            base_branch, base_path = Branch.open_containing(base_loc,
 
2802
                possible_transports)
 
2803
        # Find the revision ids
 
2804
        if revision is None or len(revision) < 1 or revision[-1] is None:
 
2805
            other_revision_id = _mod_revision.ensure_null(
 
2806
                other_branch.last_revision())
 
2807
        else:
 
2808
            other_revision_id = \
 
2809
                _mod_revision.ensure_null(
 
2810
                    revision[-1].in_history(other_branch).rev_id)
 
2811
        if (revision is not None and len(revision) == 2
 
2812
            and revision[0] is not None):
 
2813
            base_revision_id = \
 
2814
                _mod_revision.ensure_null(
 
2815
                    revision[0].in_history(base_branch).rev_id)
 
2816
        else:
 
2817
            base_revision_id = None
 
2818
        # Remember where we merge from
2723
2819
        if ((tree.branch.get_parent() is None or remember) and
2724
2820
            other_branch is not None):
2725
2821
            tree.branch.set_parent(other_branch.base)
2726
 
 
2727
 
        # pull tags now... it's a bit inconsistent to do it ahead of copying
2728
 
        # the history but that's done inside the merge code
2729
 
        if other_branch is not None:
2730
 
            _merge_tags_if_possible(other_branch, tree.branch)
2731
 
 
2732
 
        if path != "":
2733
 
            interesting_files = [path]
 
2822
        _merge_tags_if_possible(other_branch, tree.branch)
 
2823
        merger = _mod_merge.Merger.from_revision_ids(pb, tree,
 
2824
            other_revision_id, base_revision_id, other_branch, base_branch)
 
2825
        if other_path != '':
 
2826
            allow_pending = False
 
2827
            merger.interesting_files = [other_path]
2734
2828
        else:
2735
 
            interesting_files = None
2736
 
        pb = ui.ui_factory.nested_progress_bar()
2737
 
        try:
2738
 
            try:
2739
 
                conflict_count = _merge_helper(
2740
 
                    other, base, other_rev_id=other_revision_id,
2741
 
                    base_rev_id=base_revision_id,
2742
 
                    check_clean=(not force),
2743
 
                    merge_type=merge_type,
2744
 
                    reprocess=reprocess,
2745
 
                    show_base=show_base,
2746
 
                    pull=pull,
2747
 
                    this_dir=directory,
2748
 
                    pb=pb, file_list=interesting_files,
2749
 
                    change_reporter=change_reporter)
2750
 
            finally:
2751
 
                pb.finished()
2752
 
            if verified == 'failed':
2753
 
                warning('Preview patch does not match changes')
2754
 
            if conflict_count != 0:
2755
 
                return 1
2756
 
            else:
2757
 
                return 0
2758
 
        except errors.AmbiguousBase, e:
2759
 
            m = ("sorry, bzr can't determine the right merge base yet\n"
2760
 
                 "candidates are:\n  "
2761
 
                 + "\n  ".join(e.bases)
2762
 
                 + "\n"
2763
 
                 "please specify an explicit base with -r,\n"
2764
 
                 "and (if you want) report this to the bzr developers\n")
2765
 
            log_error(m)
 
2829
            allow_pending = True
 
2830
        return merger, allow_pending
 
2831
 
 
2832
    def _select_branch_location(self, tree, location, revision=None,
 
2833
                                index=None):
 
2834
        """Select a branch location, according to possible inputs.
 
2835
 
 
2836
        If provided, branches from ``revision`` are preferred.  (Both
 
2837
        ``revision`` and ``index`` must be supplied.)
 
2838
 
 
2839
        Otherwise, the ``location`` parameter is used.  If it is None, then the
 
2840
        ``parent`` location is used, and a note is printed.
 
2841
 
 
2842
        :param tree: The working tree to select a branch for merging into
 
2843
        :param location: The location entered by the user
 
2844
        :param revision: The revision parameter to the command
 
2845
        :param index: The index to use for the revision parameter.  Negative
 
2846
            indices are permitted.
 
2847
        :return: (selected_location, default_location).  The default location
 
2848
            will be the user-entered location, if any, or else the remembered
 
2849
            location.
 
2850
        """
 
2851
        if (revision is not None and index is not None
 
2852
            and revision[index] is not None):
 
2853
            branch = revision[index].get_branch()
 
2854
            if branch is not None:
 
2855
                return branch, location
 
2856
        location = self._get_remembered_parent(tree, location, 'Merging from')
 
2857
        return location, location
2766
2858
 
2767
2859
    # TODO: move up to common parent; this isn't merge-specific anymore. 
2768
2860
    def _get_remembered_parent(self, tree, supplied_location, verb_string):
2776
2868
        mutter("%s", stored_location)
2777
2869
        if stored_location is None:
2778
2870
            raise errors.BzrCommandError("No location specified or remembered")
2779
 
        display_url = urlutils.unescape_for_display(stored_location, self.outf.encoding)
2780
 
        self.outf.write("%s remembered location %s\n" % (verb_string, display_url))
 
2871
        display_url = urlutils.unescape_for_display(stored_location,
 
2872
            self.outf.encoding)
 
2873
        self.outf.write("%s remembered location %s\n" % (verb_string,
 
2874
            display_url))
2781
2875
        return stored_location
2782
2876
 
2783
2877
 
2792
2886
    merge.  The difference is that remerge can (only) be run when there is a
2793
2887
    pending merge, and it lets you specify particular files.
2794
2888
 
2795
 
    Examples:
2796
 
 
2797
 
    $ bzr remerge --show-base
 
2889
    :Examples:
2798
2890
        Re-do the merge of all conflicted files, and show the base text in
2799
 
        conflict regions, in addition to the usual THIS and OTHER texts.
 
2891
        conflict regions, in addition to the usual THIS and OTHER texts::
 
2892
      
 
2893
            bzr remerge --show-base
2800
2894
 
2801
 
    $ bzr remerge --merge-type weave --reprocess foobar
2802
2895
        Re-do the merge of "foobar", using the weave merge algorithm, with
2803
 
        additional processing to reduce the size of conflict regions.
 
2896
        additional processing to reduce the size of conflict regions::
 
2897
      
 
2898
            bzr remerge --merge-type weave --reprocess foobar
2804
2899
    """
2805
2900
    takes_args = ['file*']
2806
2901
    takes_options = [
2857
2952
                    restore(tree.abspath(filename))
2858
2953
                except errors.NotConflicted:
2859
2954
                    pass
2860
 
            conflicts = _mod_merge.merge_inner(
2861
 
                                      tree.branch, other_tree, base_tree,
2862
 
                                      this_tree=tree,
2863
 
                                      interesting_ids=interesting_ids,
2864
 
                                      other_rev_id=parents[1],
2865
 
                                      merge_type=merge_type,
2866
 
                                      show_base=show_base,
2867
 
                                      reprocess=reprocess)
 
2955
            # Disable pending merges, because the file texts we are remerging
 
2956
            # have not had those merges performed.  If we use the wrong parents
 
2957
            # list, we imply that the working tree text has seen and rejected
 
2958
            # all the changes from the other tree, when in fact those changes
 
2959
            # have not yet been seen.
 
2960
            tree.set_parent_ids(parents[:1])
 
2961
            try:
 
2962
                conflicts = _mod_merge.merge_inner(
 
2963
                                          tree.branch, other_tree, base_tree,
 
2964
                                          this_tree=tree,
 
2965
                                          interesting_ids=interesting_ids,
 
2966
                                          other_rev_id=parents[1],
 
2967
                                          merge_type=merge_type,
 
2968
                                          show_base=show_base,
 
2969
                                          reprocess=reprocess)
 
2970
            finally:
 
2971
                tree.set_parent_ids(parents)
2868
2972
        finally:
2869
2973
            tree.unlock()
2870
2974
        if conflicts > 0:
3023
3127
        if other_branch is None:
3024
3128
            other_branch = parent
3025
3129
            if other_branch is None:
3026
 
                raise errors.BzrCommandError("No peer location known or specified.")
 
3130
                raise errors.BzrCommandError("No peer location known"
 
3131
                                             " or specified.")
3027
3132
            display_url = urlutils.unescape_for_display(parent,
3028
3133
                                                        self.outf.encoding)
3029
 
            print "Using last location: " + display_url
 
3134
            self.outf.write("Using last location: " + display_url + "\n")
3030
3135
 
3031
3136
        remote_branch = Branch.open(other_branch)
3032
3137
        if remote_branch.base == local_branch.base:
3035
3140
        try:
3036
3141
            remote_branch.lock_read()
3037
3142
            try:
3038
 
                local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
3039
 
                if (log_format is None):
3040
 
                    log_format = log.log_formatter_registry.get_default(
3041
 
                        local_branch)
 
3143
                local_extra, remote_extra = find_unmerged(local_branch,
 
3144
                                                          remote_branch)
 
3145
                if log_format is None:
 
3146
                    registry = log.log_formatter_registry
 
3147
                    log_format = registry.get_default(local_branch)
3042
3148
                lf = log_format(to_file=self.outf,
3043
3149
                                show_ids=show_ids,
3044
3150
                                show_timezone='original')
3046
3152
                    local_extra.reverse()
3047
3153
                    remote_extra.reverse()
3048
3154
                if local_extra and not theirs_only:
3049
 
                    print "You have %d extra revision(s):" % len(local_extra)
3050
 
                    for revision in iter_log_revisions(local_extra, 
 
3155
                    self.outf.write("You have %d extra revision(s):\n" %
 
3156
                                    len(local_extra))
 
3157
                    for revision in iter_log_revisions(local_extra,
3051
3158
                                        local_branch.repository,
3052
3159
                                        verbose):
3053
3160
                        lf.log_revision(revision)
3056
3163
                    printed_local = False
3057
3164
                if remote_extra and not mine_only:
3058
3165
                    if printed_local is True:
3059
 
                        print "\n\n"
3060
 
                    print "You are missing %d revision(s):" % len(remote_extra)
3061
 
                    for revision in iter_log_revisions(remote_extra, 
3062
 
                                        remote_branch.repository, 
 
3166
                        self.outf.write("\n\n\n")
 
3167
                    self.outf.write("You are missing %d revision(s):\n" %
 
3168
                                    len(remote_extra))
 
3169
                    for revision in iter_log_revisions(remote_extra,
 
3170
                                        remote_branch.repository,
3063
3171
                                        verbose):
3064
3172
                        lf.log_revision(revision)
3065
3173
                if not remote_extra and not local_extra:
3066
3174
                    status_code = 0
3067
 
                    print "Branches are up to date."
 
3175
                    self.outf.write("Branches are up to date.\n")
3068
3176
                else:
3069
3177
                    status_code = 1
3070
3178
            finally:
3389
3497
 
3390
3498
    You can get information on what locks are open via the 'bzr info' command.
3391
3499
    
3392
 
    example:
 
3500
    :Examples:
3393
3501
        bzr break-lock
3394
3502
    """
3395
3503
    takes_args = ['location?']
3665
3773
            s.send_email(message)
3666
3774
 
3667
3775
 
3668
 
class cmd_submit(Command):
 
3776
class cmd_send(Command):
3669
3777
    """Create a merge-directive for submiting changes.
3670
3778
 
3671
3779
    A merge directive provides many things needed for requesting merges:
3672
 
    - A machine-readable description of the merge to perform
3673
 
    - An optional patch that is a preview of the changes requested
3674
 
    - An optional bundle of revision data, so that the changes can be applied
 
3780
 
 
3781
    * A machine-readable description of the merge to perform
 
3782
 
 
3783
    * An optional patch that is a preview of the changes requested
 
3784
 
 
3785
    * An optional bundle of revision data, so that the changes can be applied
3675
3786
      directly from the merge directive, without retrieving data from a
3676
3787
      branch.
3677
3788
 
3696
3807
    _see_also = ['merge']
3697
3808
 
3698
3809
    takes_args = ['submit_branch?', 'public_branch?']
 
3810
 
3699
3811
    takes_options = [
3700
3812
        Option('no-bundle',
3701
3813
               help='Do not include a bundle in the merge directive.'),
3718
3830
            **kwargs):
3719
3831
        from bzrlib.revision import ensure_null, NULL_REVISION
3720
3832
        if output is None:
 
3833
            raise errors.BzrCommandError('File must be specified with'
 
3834
                                         ' --output')
 
3835
        elif output == '-':
3721
3836
            outfile = self.outf
3722
3837
        else:
3723
3838
            outfile = open(output, 'wb')
3755
3870
            base_revision_id = None
3756
3871
            if revision is not None:
3757
3872
                if len(revision) > 2:
3758
 
                    raise errors.BzrCommandError('bzr submit takes '
 
3873
                    raise errors.BzrCommandError('bzr send takes '
3759
3874
                        'at most two one revision identifiers')
3760
3875
                revision_id = revision[-1].in_history(branch).rev_id
3761
3876
                if len(revision) == 2:
3774
3889
                base_revision_id=base_revision_id)
3775
3890
            outfile.writelines(directive.to_lines())
3776
3891
        finally:
3777
 
            if output is not None:
 
3892
            if output != '-':
3778
3893
                outfile.close()
3779
3894
 
 
3895
 
3780
3896
class cmd_tag(Command):
3781
 
    """Create a tag naming a revision.
 
3897
    """Create, remove or modify a tag naming a revision.
3782
3898
    
3783
3899
    Tags give human-meaningful names to revisions.  Commands that take a -r
3784
3900
    (--revision) option can be given -rtag:X, where X is any previously
3861
3977
            self.outf.write('%-20s %s\n' % (tag_name, target))
3862
3978
 
3863
3979
 
3864
 
# command-line interpretation helper for merge-related commands
3865
 
def _merge_helper(other_revision, base_revision,
3866
 
                  check_clean=True, ignore_zero=False,
3867
 
                  this_dir=None, backup_files=False,
3868
 
                  merge_type=None,
3869
 
                  file_list=None, show_base=False, reprocess=False,
3870
 
                  pull=False,
3871
 
                  pb=DummyProgress(),
3872
 
                  change_reporter=None,
3873
 
                  other_rev_id=None, base_rev_id=None):
3874
 
    """Merge changes into a tree.
3875
 
 
3876
 
    base_revision
3877
 
        list(path, revno) Base for three-way merge.  
3878
 
        If [None, None] then a base will be automatically determined.
3879
 
    other_revision
3880
 
        list(path, revno) Other revision for three-way merge.
3881
 
    this_dir
3882
 
        Directory to merge changes into; '.' by default.
3883
 
    check_clean
3884
 
        If true, this_dir must have no uncommitted changes before the
3885
 
        merge begins.
3886
 
    ignore_zero - If true, suppress the "zero conflicts" message when 
3887
 
        there are no conflicts; should be set when doing something we expect
3888
 
        to complete perfectly.
3889
 
    file_list - If supplied, merge only changes to selected files.
3890
 
 
3891
 
    All available ancestors of other_revision and base_revision are
3892
 
    automatically pulled into the branch.
3893
 
 
3894
 
    The revno may be -1 to indicate the last revision on the branch, which is
3895
 
    the typical case.
3896
 
 
3897
 
    This function is intended for use from the command line; programmatic
3898
 
    clients might prefer to call merge.merge_inner(), which has less magic 
3899
 
    behavior.
3900
 
    """
3901
 
    # Loading it late, so that we don't always have to import bzrlib.merge
3902
 
    if merge_type is None:
3903
 
        merge_type = _mod_merge.Merge3Merger
3904
 
    if this_dir is None:
3905
 
        this_dir = u'.'
3906
 
    this_tree = WorkingTree.open_containing(this_dir)[0]
3907
 
    if show_base and not merge_type is _mod_merge.Merge3Merger:
3908
 
        raise errors.BzrCommandError("Show-base is not supported for this merge"
3909
 
                                     " type. %s" % merge_type)
3910
 
    if reprocess and not merge_type.supports_reprocess:
3911
 
        raise errors.BzrCommandError("Conflict reduction is not supported for merge"
3912
 
                                     " type %s." % merge_type)
3913
 
    if reprocess and show_base:
3914
 
        raise errors.BzrCommandError("Cannot do conflict reduction and show base.")
3915
 
    # TODO: jam 20070226 We should really lock these trees earlier. However, we
3916
 
    #       only want to take out a lock_tree_write() if we don't have to pull
3917
 
    #       any ancestry. But merge might fetch ancestry in the middle, in
3918
 
    #       which case we would need a lock_write().
3919
 
    #       Because we cannot upgrade locks, for now we live with the fact that
3920
 
    #       the tree will be locked multiple times during a merge. (Maybe
3921
 
    #       read-only some of the time, but it means things will get read
3922
 
    #       multiple times.)
3923
 
    try:
3924
 
        merger = _mod_merge.Merger(this_tree.branch, this_tree=this_tree,
3925
 
                                   pb=pb, change_reporter=change_reporter)
3926
 
        merger.pp = ProgressPhase("Merge phase", 5, pb)
3927
 
        merger.pp.next_phase()
3928
 
        merger.check_basis(check_clean)
3929
 
        if other_rev_id is not None:
3930
 
            merger.set_other_revision(other_rev_id, this_tree.branch)
3931
 
        else:
3932
 
            merger.set_other(other_revision)
3933
 
        merger.pp.next_phase()
3934
 
        if base_rev_id is not None:
3935
 
            merger.set_base_revision(base_rev_id, this_tree.branch)
3936
 
        elif base_revision is not None:
3937
 
            merger.set_base(base_revision)
3938
 
        else:
3939
 
            merger.find_base()
3940
 
        if merger.base_rev_id == merger.other_rev_id:
3941
 
            note('Nothing to do.')
3942
 
            return 0
3943
 
        if file_list is None:
3944
 
            if pull and merger.base_rev_id == merger.this_rev_id:
3945
 
                # FIXME: deduplicate with pull
3946
 
                result = merger.this_tree.pull(merger.this_branch,
3947
 
                        False, merger.other_rev_id)
3948
 
                if result.old_revid == result.new_revid:
3949
 
                    note('No revisions to pull.')
3950
 
                else:
3951
 
                    note('Now on revision %d.' % result.new_revno)
3952
 
                return 0
3953
 
        merger.backup_files = backup_files
3954
 
        merger.merge_type = merge_type 
3955
 
        merger.set_interesting_files(file_list)
3956
 
        merger.show_base = show_base 
3957
 
        merger.reprocess = reprocess
3958
 
        conflicts = merger.do_merge()
3959
 
        if file_list is None:
3960
 
            merger.set_pending()
3961
 
    finally:
3962
 
        pb.clear()
3963
 
    return conflicts
3964
 
 
3965
 
 
3966
3980
def _create_prefix(cur_transport):
3967
3981
    needed = [cur_transport]
3968
3982
    # Recurse upwards until we can create a directory successfully
3985
3999
        cur_transport.ensure_base()
3986
4000
 
3987
4001
 
3988
 
# Compatibility
3989
 
merge = _merge_helper
 
4002
def _get_mergeable_helper(location):
 
4003
    """Get a merge directive or bundle if 'location' points to one.
 
4004
 
 
4005
    Try try to identify a bundle and returns its mergeable form. If it's not,
 
4006
    we return the tried transport anyway so that it can reused to access the
 
4007
    branch
 
4008
 
 
4009
    :param location: can point to a bundle or a branch.
 
4010
 
 
4011
    :return: mergeable, transport
 
4012
    """
 
4013
    mergeable = None
 
4014
    url = urlutils.normalize_url(location)
 
4015
    url, filename = urlutils.split(url, exclude_trailing_slash=False)
 
4016
    location_transport = transport.get_transport(url)
 
4017
    if filename:
 
4018
        try:
 
4019
            # There may be redirections but we ignore the intermediate
 
4020
            # and final transports used
 
4021
            read = bundle.read_mergeable_from_transport
 
4022
            mergeable, t = read(location_transport, filename)
 
4023
        except errors.NotABundle:
 
4024
            # Continue on considering this url a Branch but adjust the
 
4025
            # location_transport
 
4026
            location_transport = location_transport.clone(filename)
 
4027
    return mergeable, location_transport
3990
4028
 
3991
4029
 
3992
4030
# these get imported and then picked up by the scan for cmd_*