/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: 2007-08-14 23:35:48 UTC
  • mfrom: (2698 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2699.
  • Revision ID: aaron.bentley@utoronto.ca-20070814233548-ctlr8sb1lcufb3ny
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
595
595
            branch_to = Branch.open_containing(directory)[0]
596
596
 
597
597
        if location is not None:
598
 
            mergeable, location_transport = _get_bundle_helper(location)
 
598
            mergeable, location_transport = _get_mergeable_helper(location)
599
599
 
600
600
        stored_loc = branch_to.get_parent()
601
601
        if location is None:
1029
1029
            if last_rev == _mod_revision.ensure_null(
1030
1030
                tree.branch.last_revision()):
1031
1031
                # may be up to date, check master too.
1032
 
                master = tree.branch.get_master_branch()
1033
1032
                if master is None or last_rev == _mod_revision.ensure_null(
1034
1033
                    master.last_revision()):
1035
1034
                    revno = tree.branch.revision_id_to_revno(last_rev)
1086
1085
    takes_options = ['verbose',
1087
1086
        Option('new', help='Remove newly-added files.'),
1088
1087
        RegistryOption.from_kwargs('file-deletion-strategy',
1089
 
            'The file deletion mode to be used',
 
1088
            'The file deletion mode to be used.',
1090
1089
            title='Deletion Strategy', value_switches=True, enum_switch=False,
1091
1090
            safe='Only delete files if they can be'
1092
1091
                 ' safely recovered (default).',
1245
1244
    If there is already a branch at the location but it has no working tree,
1246
1245
    the tree can be populated with 'bzr checkout'.
1247
1246
 
1248
 
    Recipe for importing a tree of files:
 
1247
    Recipe for importing a tree of files::
 
1248
 
1249
1249
        cd ~/project
1250
1250
        bzr init
1251
1251
        bzr add .
1253
1253
        bzr commit -m 'imported project'
1254
1254
    """
1255
1255
 
1256
 
    _see_also = ['init-repo', 'branch', 'checkout']
 
1256
    _see_also = ['init-repository', 'branch', 'checkout']
1257
1257
    takes_args = ['location?']
1258
1258
    takes_options = [
1259
1259
        Option('create-prefix',
1330
1330
    If the --no-trees option is used then the branches in the repository
1331
1331
    will not have working trees by default.
1332
1332
 
1333
 
    example:
1334
 
        bzr init-repo --no-trees repo
1335
 
        bzr init repo/trunk
1336
 
        bzr checkout --lightweight repo/trunk trunk-checkout
1337
 
        cd trunk-checkout
1338
 
        (add files here)
1339
 
 
1340
 
    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)
1341
1344
    """
1342
1345
 
1343
 
    _see_also = ['init', 'branch', 'checkout']
 
1346
    _see_also = ['init', 'branch', 'checkout', 'repositories']
1344
1347
    takes_args = ["location"]
1345
1348
    takes_options = [RegistryOption('format',
1346
1349
                            help='Specify a format for this repository. See'
1378
1381
    "bzr diff -p1" is equivalent to "bzr diff --prefix old/:new/", and
1379
1382
    produces patches suitable for "patch -p1".
1380
1383
 
1381
 
    examples:
1382
 
        bzr diff
1383
 
            Shows the difference in the working tree versus the last commit
1384
 
        bzr diff -r1
1385
 
            Difference between the working tree and revision 1
1386
 
        bzr diff -r1..2
1387
 
            Difference between revision 2 and revision 1
1388
 
        bzr diff --prefix old/:new/
1389
 
            Same as 'bzr diff' but prefix paths with old/ and new/
1390
 
        bzr diff bzr.mine bzr.dev
1391
 
            Show the differences between the two working trees
1392
 
        bzr diff foo.c
1393
 
            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
1394
1408
    """
1395
1409
    # TODO: Option to use external diff command; could be GNU diff, wdiff,
1396
1410
    #       or a graphical diff.
1594
1608
    -r revision requests a specific revision, -r ..end or -r begin.. are
1595
1609
    also valid.
1596
1610
 
1597
 
    examples:
1598
 
        bzr log
1599
 
        bzr log foo.c
1600
 
        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
1601
1623
    """
1602
1624
 
1603
1625
    # TODO: Make --revision support uuid: and hash: [future tag:] notation.
1860
1882
 
1861
1883
    Ignore patterns specifying absolute paths are not allowed.
1862
1884
 
1863
 
    Ignore patterns may include globbing wildcards such as:
 
1885
    Ignore patterns may include globbing wildcards such as::
 
1886
 
1864
1887
      ? - Matches any single character except '/'
1865
1888
      * - Matches 0 or more characters except '/'
1866
1889
      /**/ - Matches 0 or more directories in a path
1874
1897
    Note: ignore patterns containing shell wildcards must be quoted from 
1875
1898
    the shell on Unix.
1876
1899
 
1877
 
    examples:
1878
 
        bzr ignore ./Makefile
1879
 
        bzr ignore '*.class'
1880
 
        bzr ignore 'lib/**/*.o'
1881
 
        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'
1882
1916
    """
1883
1917
 
1884
1918
    _see_also = ['status', 'ignored']
1958
1992
class cmd_lookup_revision(Command):
1959
1993
    """Lookup the revision-id from a revision-number
1960
1994
 
1961
 
    example:
 
1995
    :Examples:
1962
1996
        bzr lookup-revision 33
1963
1997
    """
1964
1998
    hidden = True
1992
2026
 
1993
2027
    Note: Export of tree with non-ASCII filenames to zip is not supported.
1994
2028
 
1995
 
     Supported formats       Autodetected by extension
1996
 
     -----------------       -------------------------
1997
 
         dir                            -
 
2029
      =================       =========================
 
2030
      Supported formats       Autodetected by extension
 
2031
      =================       =========================
 
2032
         dir                         (none)
1998
2033
         tar                          .tar
1999
2034
         tbz2                    .tar.bz2, .tbz2
2000
2035
         tgz                      .tar.gz, .tgz
2001
2036
         zip                          .zip
 
2037
      =================       =========================
2002
2038
    """
2003
2039
    takes_args = ['dest', 'branch?']
2004
2040
    takes_options = [
2314
2350
class cmd_whoami(Command):
2315
2351
    """Show or set bzr user id.
2316
2352
    
2317
 
    examples:
2318
 
        bzr whoami --email
2319
 
        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>'
2320
2361
    """
2321
2362
    takes_options = [ Option('email',
2322
2363
                             help='Display email address only.'),
2411
2452
    Tests that need working space on disk use a common temporary directory, 
2412
2453
    typically inside $TMPDIR or /tmp.
2413
2454
 
2414
 
    examples::
2415
 
        bzr selftest ignore
2416
 
            run only tests relating to 'ignore'
2417
 
        bzr --no-plugins selftest -v
2418
 
            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
2419
2463
    """
2420
2464
    # NB: this is used from the class without creating an instance, which is
2421
2465
    # why it does not have a self parameter.
2466
2510
                            short_name='x',
2467
2511
                            help='Exclude tests that match this regular'
2468
2512
                                 ' expression.'),
 
2513
                     Option('strict', help='Fail on missing dependencies or '
 
2514
                            'known failures.'),
2469
2515
                     ]
2470
2516
    encoding_type = 'replace'
2471
2517
 
2473
2519
            transport=None, benchmark=None,
2474
2520
            lsprof_timed=None, cache_dir=None,
2475
2521
            first=False, list_only=False,
2476
 
            randomize=None, exclude=None):
 
2522
            randomize=None, exclude=None, strict=False):
2477
2523
        import bzrlib.ui
2478
2524
        from bzrlib.tests import selftest
2479
2525
        import bzrlib.benchmarks as benchmarks
2511
2557
                              matching_tests_first=first,
2512
2558
                              list_only=list_only,
2513
2559
                              random_seed=randomize,
2514
 
                              exclude_pattern=exclude
 
2560
                              exclude_pattern=exclude,
 
2561
                              strict=strict,
2515
2562
                              )
2516
2563
        finally:
2517
2564
            if benchfile is not None:
2593
2640
    The results of the merge are placed into the destination working
2594
2641
    directory, where they can be reviewed (with bzr diff), tested, and then
2595
2642
    committed to record the result of the merge.
2596
 
 
2597
 
    Examples:
2598
 
 
2599
 
    To merge the latest revision from bzr.dev:
2600
 
        bzr merge ../bzr.dev
2601
 
 
2602
 
    To merge changes up to and including revision 82 from bzr.dev:
2603
 
        bzr merge -r 82 ../bzr.dev
2604
 
 
2605
 
    To merge the changes introduced by 82, without previous changes:
2606
 
        bzr merge -r 81..82 ../bzr.dev
2607
2643
    
2608
2644
    merge refuses to run if there are any uncommitted changes, unless
2609
2645
    --force is given.
 
2646
 
 
2647
    :Examples:
 
2648
        To merge the latest revision from bzr.dev::
 
2649
 
 
2650
            bzr merge ../bzr.dev
 
2651
 
 
2652
        To merge changes up to and including revision 82 from bzr.dev::
 
2653
 
 
2654
            bzr merge -r 82 ../bzr.dev
 
2655
 
 
2656
        To merge the changes introduced by 82, without previous changes::
 
2657
 
 
2658
            bzr merge -r 81..82 ../bzr.dev
2610
2659
    """
2611
2660
 
2612
2661
    _see_also = ['update', 'remerge', 'status-flags']
2640
2689
            directory=None,
2641
2690
            ):
2642
2691
        from bzrlib.tag import _merge_tags_if_possible
 
2692
        # This is actually a branch (or merge-directive) *location*.
 
2693
        location = branch
 
2694
        del branch
 
2695
 
2643
2696
        if merge_type is None:
2644
2697
            merge_type = _mod_merge.Merge3Merger
2645
2698
 
2646
2699
        if directory is None: directory = u'.'
2647
 
        # XXX: jam 20070225 WorkingTree should be locked before you extract its
2648
 
        #      inventory. Because merge is a mutating operation, it really
2649
 
        #      should be a lock_write() for the whole cmd_merge operation.
2650
 
        #      However, cmd_merge open's its own tree in _merge_helper, which
2651
 
        #      means if we lock here, the later lock_write() will always block.
2652
 
        #      Either the merge helper code should be updated to take a tree,
2653
 
        #      (What about tree.merge_from_branch?)
 
2700
        possible_transports = []
 
2701
        merger = None
 
2702
        allow_pending = True
 
2703
        verified = 'inapplicable'
2654
2704
        tree = WorkingTree.open_containing(directory)[0]
2655
2705
        change_reporter = delta._ChangeReporter(
2656
2706
            unversioned_filter=tree.is_ignored)
2657
 
 
2658
 
        other_transport = None
2659
 
        other_revision_id = None
2660
 
        base_revision_id = None
2661
 
        possible_transports = []
2662
 
 
2663
 
        if branch is not None:
2664
 
            mergeable, other_transport = _get_bundle_helper(branch)
2665
 
            if mergeable:
2666
 
                if revision is not None:
2667
 
                    raise errors.BzrCommandError(
2668
 
                        'Cannot use -r with merge directives or bundles')
2669
 
                mergeable.install_revisions(tree.branch.repository)
2670
 
                base_revision_id, other_revision_id, verified =\
2671
 
                    mergeable.get_merge_request(tree.branch.repository)
2672
 
                if base_revision_id in tree.branch.repository.get_ancestry(
2673
 
                    tree.branch.last_revision(), topo_sorted=False):
2674
 
                    base_revision_id = None
2675
 
                other_branch = None
2676
 
                path = ''
2677
 
                other = None
2678
 
                base = None
2679
 
            possible_transports.append(other_transport)
2680
 
 
2681
 
        if other_revision_id is None:
2682
 
            verified = 'inapplicable'
2683
 
            if revision is None \
2684
 
                    or len(revision) < 1 or revision[0].needs_branch():
2685
 
                branch = self._get_remembered_parent(tree, branch,
2686
 
                    'Merging from')
2687
 
 
2688
 
            if revision is None or len(revision) < 1:
2689
 
                if uncommitted:
2690
 
                    base = [branch, -1]
2691
 
                    other = [branch, None]
2692
 
                else:
2693
 
                    base = [None, None]
2694
 
                    other = [branch, -1]
2695
 
                other_branch, path = Branch.open_containing(branch,
2696
 
                                                            possible_transports)
2697
 
            else:
2698
 
                if uncommitted:
 
2707
        cleanups = []
 
2708
        try:
 
2709
            pb = ui.ui_factory.nested_progress_bar()
 
2710
            cleanups.append(pb.finished)
 
2711
            tree.lock_write()
 
2712
            cleanups.append(tree.unlock)
 
2713
            if location is not None:
 
2714
                mergeable, other_transport = _get_mergeable_helper(location)
 
2715
                if mergeable:
 
2716
                    if uncommitted:
 
2717
                        raise errors.BzrCommandError('Cannot use --uncommitted'
 
2718
                            ' with bundles or merge directives.')
 
2719
 
 
2720
                    if revision is not None:
 
2721
                        raise errors.BzrCommandError(
 
2722
                            'Cannot use -r with merge directives or bundles')
 
2723
                    merger, verified = _mod_merge.Merger.from_mergeable(tree,
 
2724
                       mergeable, pb)
 
2725
                possible_transports.append(other_transport)
 
2726
 
 
2727
            if merger is None and uncommitted:
 
2728
                if revision is not None and len(revision) > 0:
2699
2729
                    raise errors.BzrCommandError('Cannot use --uncommitted and'
2700
2730
                        ' --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(
2705
 
                        branch, possible_transports)
2706
 
                    revno = revision[0].in_history(other_branch).revno
2707
 
                    other = [branch, revno]
2708
 
                else:
2709
 
                    assert len(revision) == 2
2710
 
                    if None in revision:
2711
 
                        raise errors.BzrCommandError(
2712
 
                            "Merge doesn't permit empty revision specifier.")
2713
 
                    base_branch, path = Branch.open_containing(
2714
 
                        branch, possible_transports)
2715
 
                    branch1 = revision[1].get_branch() or branch
2716
 
                    other_branch, path1 = Branch.open_containing(
2717
 
                        branch1, possible_transports)
2718
 
                    if revision[0].get_branch() is not None:
2719
 
                        # then path was obtained from it, and is None.
2720
 
                        path = path1
2721
 
 
2722
 
                    base = [branch, revision[0].in_history(base_branch).revno]
2723
 
                    other = [branch1,
2724
 
                             revision[1].in_history(other_branch).revno]
2725
 
 
 
2731
                location = self._select_branch_location(tree, location)[0]
 
2732
                other_tree, other_path = WorkingTree.open_containing(location)
 
2733
                merger = _mod_merge.Merger.from_uncommitted(tree, other_tree,
 
2734
                    pb)
 
2735
                allow_pending = False
 
2736
 
 
2737
            if merger is None:
 
2738
                merger, allow_pending = self._get_merger_from_branch(tree,
 
2739
                    location, revision, remember, possible_transports, pb)
 
2740
 
 
2741
            merger.merge_type = merge_type
 
2742
            merger.reprocess = reprocess
 
2743
            merger.show_base = show_base
 
2744
            merger.change_reporter = change_reporter
 
2745
            self.sanity_check_merger(merger)
 
2746
            if (merger.base_rev_id == merger.other_rev_id and
 
2747
                merger.other_rev_id != None):
 
2748
                note('Nothing to do.')
 
2749
                return 0
 
2750
            if pull:
 
2751
                if merger.interesting_files is not None:
 
2752
                    raise BzrCommandError('Cannot pull individual files')
 
2753
                if (merger.base_rev_id == tree.last_revision()):
 
2754
                    result = tree.pull(merger.other_branch, False,
 
2755
                                       merger.other_rev_id)
 
2756
                    result.report(self.outf)
 
2757
                    return 0
 
2758
            merger.check_basis(not force)
 
2759
            conflict_count = merger.do_merge()
 
2760
            if allow_pending:
 
2761
                merger.set_pending()
 
2762
            if verified == 'failed':
 
2763
                warning('Preview patch does not match changes')
 
2764
            if conflict_count != 0:
 
2765
                return 1
 
2766
            else:
 
2767
                return 0
 
2768
        finally:
 
2769
            for cleanup in reversed(cleanups):
 
2770
                cleanup()
 
2771
 
 
2772
    def sanity_check_merger(self, merger):
 
2773
        if (merger.show_base and
 
2774
            not merger.merge_type is _mod_merge.Merge3Merger):
 
2775
            raise errors.BzrCommandError("Show-base is not supported for this"
 
2776
                                         " merge type. %s" % merger.merge_type)
 
2777
        if merger.reprocess and not merger.merge_type.supports_reprocess:
 
2778
            raise errors.BzrCommandError("Conflict reduction is not supported"
 
2779
                                         " for merge type %s." %
 
2780
                                         merger.merge_type)
 
2781
        if merger.reprocess and merger.show_base:
 
2782
            raise errors.BzrCommandError("Cannot do conflict reduction and"
 
2783
                                         " show base.")
 
2784
 
 
2785
    def _get_merger_from_branch(self, tree, location, revision, remember,
 
2786
                                possible_transports, pb):
 
2787
        """Produce a merger from a location, assuming it refers to a branch."""
 
2788
        from bzrlib.tag import _merge_tags_if_possible
 
2789
        assert revision is None or len(revision) < 3
 
2790
        # find the branch locations
 
2791
        other_loc, location = self._select_branch_location(tree, location,
 
2792
            revision, -1)
 
2793
        if revision is not None and len(revision) == 2:
 
2794
            base_loc, location = self._select_branch_location(tree, location,
 
2795
                                                              revision, 0)
 
2796
        else:
 
2797
            base_loc = other_loc
 
2798
        # Open the branches
 
2799
        other_branch, other_path = Branch.open_containing(other_loc,
 
2800
            possible_transports)
 
2801
        if base_loc == other_loc:
 
2802
            base_branch = other_branch
 
2803
        else:
 
2804
            base_branch, base_path = Branch.open_containing(base_loc,
 
2805
                possible_transports)
 
2806
        # Find the revision ids
 
2807
        if revision is None or len(revision) < 1 or revision[-1] is None:
 
2808
            other_revision_id = _mod_revision.ensure_null(
 
2809
                other_branch.last_revision())
 
2810
        else:
 
2811
            other_revision_id = \
 
2812
                _mod_revision.ensure_null(
 
2813
                    revision[-1].in_history(other_branch).rev_id)
 
2814
        if (revision is not None and len(revision) == 2
 
2815
            and revision[0] is not None):
 
2816
            base_revision_id = \
 
2817
                _mod_revision.ensure_null(
 
2818
                    revision[0].in_history(base_branch).rev_id)
 
2819
        else:
 
2820
            base_revision_id = None
2726
2821
        # Remember where we merge from
2727
2822
        if ((tree.branch.get_parent() is None or remember) and
2728
2823
            other_branch is not None):
2729
2824
            tree.branch.set_parent(other_branch.base)
2730
 
 
2731
 
        # pull tags now... it's a bit inconsistent to do it ahead of copying
2732
 
        # the history but that's done inside the merge code
2733
 
        if other_branch is not None:
2734
 
            _merge_tags_if_possible(other_branch, tree.branch)
2735
 
 
2736
 
        if path != "":
2737
 
            interesting_files = [path]
 
2825
        _merge_tags_if_possible(other_branch, tree.branch)
 
2826
        merger = _mod_merge.Merger.from_revision_ids(pb, tree,
 
2827
            other_revision_id, base_revision_id, other_branch, base_branch)
 
2828
        if other_path != '':
 
2829
            allow_pending = False
 
2830
            merger.interesting_files = [other_path]
2738
2831
        else:
2739
 
            interesting_files = None
2740
 
        pb = ui.ui_factory.nested_progress_bar()
2741
 
        try:
2742
 
            try:
2743
 
                conflict_count = _merge_helper(
2744
 
                    other, base, other_rev_id=other_revision_id,
2745
 
                    base_rev_id=base_revision_id,
2746
 
                    check_clean=(not force),
2747
 
                    merge_type=merge_type,
2748
 
                    reprocess=reprocess,
2749
 
                    show_base=show_base,
2750
 
                    pull=pull,
2751
 
                    this_dir=directory,
2752
 
                    pb=pb, file_list=interesting_files,
2753
 
                    change_reporter=change_reporter,
2754
 
                    possible_transports=possible_transports)
2755
 
            finally:
2756
 
                pb.finished()
2757
 
            if verified == 'failed':
2758
 
                warning('Preview patch does not match changes')
2759
 
            if conflict_count != 0:
2760
 
                return 1
2761
 
            else:
2762
 
                return 0
2763
 
        except errors.AmbiguousBase, e:
2764
 
            m = ("sorry, bzr can't determine the right merge base yet\n"
2765
 
                 "candidates are:\n  "
2766
 
                 + "\n  ".join(e.bases)
2767
 
                 + "\n"
2768
 
                 "please specify an explicit base with -r,\n"
2769
 
                 "and (if you want) report this to the bzr developers\n")
2770
 
            log_error(m)
 
2832
            allow_pending = True
 
2833
        return merger, allow_pending
 
2834
 
 
2835
    def _select_branch_location(self, tree, location, revision=None,
 
2836
                                index=None):
 
2837
        """Select a branch location, according to possible inputs.
 
2838
 
 
2839
        If provided, branches from ``revision`` are preferred.  (Both
 
2840
        ``revision`` and ``index`` must be supplied.)
 
2841
 
 
2842
        Otherwise, the ``location`` parameter is used.  If it is None, then the
 
2843
        ``parent`` location is used, and a note is printed.
 
2844
 
 
2845
        :param tree: The working tree to select a branch for merging into
 
2846
        :param location: The location entered by the user
 
2847
        :param revision: The revision parameter to the command
 
2848
        :param index: The index to use for the revision parameter.  Negative
 
2849
            indices are permitted.
 
2850
        :return: (selected_location, default_location).  The default location
 
2851
            will be the user-entered location, if any, or else the remembered
 
2852
            location.
 
2853
        """
 
2854
        if (revision is not None and index is not None
 
2855
            and revision[index] is not None):
 
2856
            branch = revision[index].get_branch()
 
2857
            if branch is not None:
 
2858
                return branch, location
 
2859
        location = self._get_remembered_parent(tree, location, 'Merging from')
 
2860
        return location, location
2771
2861
 
2772
2862
    # TODO: move up to common parent; this isn't merge-specific anymore. 
2773
2863
    def _get_remembered_parent(self, tree, supplied_location, verb_string):
2781
2871
        mutter("%s", stored_location)
2782
2872
        if stored_location is None:
2783
2873
            raise errors.BzrCommandError("No location specified or remembered")
2784
 
        display_url = urlutils.unescape_for_display(stored_location, self.outf.encoding)
2785
 
        self.outf.write("%s remembered location %s\n" % (verb_string, display_url))
 
2874
        display_url = urlutils.unescape_for_display(stored_location,
 
2875
            self.outf.encoding)
 
2876
        self.outf.write("%s remembered location %s\n" % (verb_string,
 
2877
            display_url))
2786
2878
        return stored_location
2787
2879
 
2788
2880
 
2797
2889
    merge.  The difference is that remerge can (only) be run when there is a
2798
2890
    pending merge, and it lets you specify particular files.
2799
2891
 
2800
 
    Examples:
2801
 
 
2802
 
    $ bzr remerge --show-base
 
2892
    :Examples:
2803
2893
        Re-do the merge of all conflicted files, and show the base text in
2804
 
        conflict regions, in addition to the usual THIS and OTHER texts.
 
2894
        conflict regions, in addition to the usual THIS and OTHER texts::
 
2895
      
 
2896
            bzr remerge --show-base
2805
2897
 
2806
 
    $ bzr remerge --merge-type weave --reprocess foobar
2807
2898
        Re-do the merge of "foobar", using the weave merge algorithm, with
2808
 
        additional processing to reduce the size of conflict regions.
 
2899
        additional processing to reduce the size of conflict regions::
 
2900
      
 
2901
            bzr remerge --merge-type weave --reprocess foobar
2809
2902
    """
2810
2903
    takes_args = ['file*']
2811
2904
    takes_options = [
3407
3500
 
3408
3501
    You can get information on what locks are open via the 'bzr info' command.
3409
3502
    
3410
 
    example:
 
3503
    :Examples:
3411
3504
        bzr break-lock
3412
3505
    """
3413
3506
    takes_args = ['location?']
3604
3697
 
3605
3698
    hidden = True
3606
3699
 
3607
 
    _see_also = ['submit']
 
3700
    _see_also = ['send']
3608
3701
 
3609
3702
    takes_options = [
3610
3703
        RegistryOption.from_kwargs('patch-type',
3611
 
            'The type of patch to include in the directive',
 
3704
            'The type of patch to include in the directive.',
3612
3705
            title='Patch type',
3613
3706
            value_switches=True,
3614
3707
            enum_switch=False,
3683
3776
            s.send_email(message)
3684
3777
 
3685
3778
 
3686
 
class cmd_submit(Command):
 
3779
class cmd_send(Command):
3687
3780
    """Create a merge-directive for submiting changes.
3688
3781
 
3689
3782
    A merge directive provides many things needed for requesting merges:
3690
 
    - A machine-readable description of the merge to perform
3691
 
    - An optional patch that is a preview of the changes requested
3692
 
    - An optional bundle of revision data, so that the changes can be applied
 
3783
 
 
3784
    * A machine-readable description of the merge to perform
 
3785
 
 
3786
    * An optional patch that is a preview of the changes requested
 
3787
 
 
3788
    * An optional bundle of revision data, so that the changes can be applied
3693
3789
      directly from the merge directive, without retrieving data from a
3694
3790
      branch.
3695
3791
 
3705
3801
    branch is used in the merge instructions.  This means that a local mirror
3706
3802
    can be used as your actual submit branch, once you have set public_branch
3707
3803
    for that mirror.
 
3804
 
 
3805
    Two formats are currently supported: "4" uses revision bundle format 4 and
 
3806
    merge directive format 2.  It is significantly faster and smaller than
 
3807
    older formats.  It is compatible with Bazaar 0.19 and later.  It is the
 
3808
    default.  "0.9" uses revision bundle format 0.9 and merge directive
 
3809
    format 1.  It is compatible with Bazaar 0.12 - 0.18.
3708
3810
    """
3709
3811
 
3710
3812
    encoding_type = 'exact'
3711
3813
 
3712
 
    aliases = ['bundle', 'bundle-revisions']
3713
 
 
3714
3814
    _see_also = ['merge']
3715
3815
 
3716
3816
    takes_args = ['submit_branch?', 'public_branch?']
 
3817
 
3717
3818
    takes_options = [
3718
3819
        Option('no-bundle',
3719
3820
               help='Do not include a bundle in the merge directive.'),
3729
3830
        Option('output', short_name='o', help='Write directive to this file.',
3730
3831
               type=unicode),
3731
3832
        'revision',
 
3833
        RegistryOption.from_kwargs('format',
 
3834
        'Use the specified output format.',
 
3835
        **{'4': 'Bundle format 4, Merge Directive 2 (default)',
 
3836
           '0.9': 'Bundle format 0.9, Merge Directive 1',})
3732
3837
        ]
3733
3838
 
3734
3839
    def run(self, submit_branch=None, public_branch=None, no_bundle=False,
3735
3840
            no_patch=False, revision=None, remember=False, output=None,
3736
 
            **kwargs):
 
3841
            format='4', **kwargs):
 
3842
        if output is None:
 
3843
            raise errors.BzrCommandError('File must be specified with'
 
3844
                                         ' --output')
 
3845
        return self._run(submit_branch, revision, public_branch, remember,
 
3846
                         format, no_bundle, no_patch, output,
 
3847
                         kwargs.get('from', '.'))
 
3848
 
 
3849
    def _run(self, submit_branch, revision, public_branch, remember, format,
 
3850
             no_bundle, no_patch, output, from_,):
3737
3851
        from bzrlib.revision import ensure_null, NULL_REVISION
3738
 
        if output is None:
 
3852
        if output == '-':
3739
3853
            outfile = self.outf
3740
3854
        else:
3741
3855
            outfile = open(output, 'wb')
3742
3856
        try:
3743
 
            from_ = kwargs.get('from', '.')
3744
3857
            branch = Branch.open_containing(from_)[0]
3745
3858
            if remember and submit_branch is None:
3746
3859
                raise errors.BzrCommandError(
3773
3886
            base_revision_id = None
3774
3887
            if revision is not None:
3775
3888
                if len(revision) > 2:
3776
 
                    raise errors.BzrCommandError('bzr submit takes '
 
3889
                    raise errors.BzrCommandError('bzr send takes '
3777
3890
                        'at most two one revision identifiers')
3778
3891
                revision_id = revision[-1].in_history(branch).rev_id
3779
3892
                if len(revision) == 2:
3784
3897
            revision_id = ensure_null(revision_id)
3785
3898
            if revision_id == NULL_REVISION:
3786
3899
                raise errors.BzrCommandError('No revisions to submit.')
3787
 
            directive = merge_directive.MergeDirective2.from_objects(
3788
 
                branch.repository, revision_id, time.time(),
3789
 
                osutils.local_time_offset(), submit_branch,
3790
 
                public_branch=public_branch, include_patch=not no_patch,
3791
 
                include_bundle=not no_bundle, message=None,
3792
 
                base_revision_id=base_revision_id)
 
3900
            if format == '4':
 
3901
                directive = merge_directive.MergeDirective2.from_objects(
 
3902
                    branch.repository, revision_id, time.time(),
 
3903
                    osutils.local_time_offset(), submit_branch,
 
3904
                    public_branch=public_branch, include_patch=not no_patch,
 
3905
                    include_bundle=not no_bundle, message=None,
 
3906
                    base_revision_id=base_revision_id)
 
3907
            elif format == '0.9':
 
3908
                if not no_bundle:
 
3909
                    if not no_patch:
 
3910
                        patch_type = 'bundle'
 
3911
                    else:
 
3912
                        raise errors.BzrCommandError('Format 0.9 does not'
 
3913
                            ' permit bundle with no patch')
 
3914
                else:
 
3915
                    if not no_patch:
 
3916
                        patch_type = 'diff'
 
3917
                    else:
 
3918
                        patch_type = None
 
3919
                directive = merge_directive.MergeDirective.from_objects(
 
3920
                    branch.repository, revision_id, time.time(),
 
3921
                    osutils.local_time_offset(), submit_branch,
 
3922
                    public_branch=public_branch, patch_type=patch_type,
 
3923
                    message=None)
 
3924
 
3793
3925
            outfile.writelines(directive.to_lines())
3794
3926
        finally:
3795
 
            if output is not None:
 
3927
            if output != '-':
3796
3928
                outfile.close()
3797
3929
 
 
3930
 
 
3931
class cmd_bundle_revisions(cmd_send):
 
3932
 
 
3933
    """Create a merge-directive for submiting changes.
 
3934
 
 
3935
    A merge directive provides many things needed for requesting merges:
 
3936
 
 
3937
    * A machine-readable description of the merge to perform
 
3938
 
 
3939
    * An optional patch that is a preview of the changes requested
 
3940
 
 
3941
    * An optional bundle of revision data, so that the changes can be applied
 
3942
      directly from the merge directive, without retrieving data from a
 
3943
      branch.
 
3944
 
 
3945
    If --no-bundle is specified, then public_branch is needed (and must be
 
3946
    up-to-date), so that the receiver can perform the merge using the
 
3947
    public_branch.  The public_branch is always included if known, so that
 
3948
    people can check it later.
 
3949
 
 
3950
    The submit branch defaults to the parent, but can be overridden.  Both
 
3951
    submit branch and public branch will be remembered if supplied.
 
3952
 
 
3953
    If a public_branch is known for the submit_branch, that public submit
 
3954
    branch is used in the merge instructions.  This means that a local mirror
 
3955
    can be used as your actual submit branch, once you have set public_branch
 
3956
    for that mirror.
 
3957
 
 
3958
    Two formats are currently supported: "4" uses revision bundle format 4 and
 
3959
    merge directive format 2.  It is significantly faster and smaller than
 
3960
    older formats.  It is compatible with Bazaar 0.19 and later.  It is the
 
3961
    default.  "0.9" uses revision bundle format 0.9 and merge directive
 
3962
    format 1.  It is compatible with Bazaar 0.12 - 0.18.
 
3963
    """
 
3964
 
 
3965
    aliases = ['bundle']
 
3966
 
 
3967
    _see_also = ['send', 'merge']
 
3968
 
 
3969
    hidden = True
 
3970
 
 
3971
    def run(self, submit_branch=None, public_branch=None, no_bundle=False,
 
3972
            no_patch=False, revision=None, remember=False, output=None,
 
3973
            format='4', **kwargs):
 
3974
        if output is None:
 
3975
            output = '-'
 
3976
        return self._run(submit_branch, revision, public_branch, remember,
 
3977
                         format, no_bundle, no_patch, output,
 
3978
                         kwargs.get('from', '.'))
 
3979
 
 
3980
 
3798
3981
class cmd_tag(Command):
3799
 
    """Create a tag naming a revision.
 
3982
    """Create, remove or modify a tag naming a revision.
3800
3983
    
3801
3984
    Tags give human-meaningful names to revisions.  Commands that take a -r
3802
3985
    (--revision) option can be given -rtag:X, where X is any previously
3879
4062
            self.outf.write('%-20s %s\n' % (tag_name, target))
3880
4063
 
3881
4064
 
3882
 
# command-line interpretation helper for merge-related commands
3883
 
def _merge_helper(other_revision, base_revision,
3884
 
                  check_clean=True, ignore_zero=False,
3885
 
                  this_dir=None, backup_files=False,
3886
 
                  merge_type=None,
3887
 
                  file_list=None, show_base=False, reprocess=False,
3888
 
                  pull=False,
3889
 
                  pb=DummyProgress(),
3890
 
                  change_reporter=None,
3891
 
                  other_rev_id=None, base_rev_id=None,
3892
 
                  possible_transports=None):
3893
 
    """Merge changes into a tree.
3894
 
 
3895
 
    base_revision
3896
 
        list(path, revno) Base for three-way merge.  
3897
 
        If [None, None] then a base will be automatically determined.
3898
 
    other_revision
3899
 
        list(path, revno) Other revision for three-way merge.
3900
 
    this_dir
3901
 
        Directory to merge changes into; '.' by default.
3902
 
    check_clean
3903
 
        If true, this_dir must have no uncommitted changes before the
3904
 
        merge begins.
3905
 
    ignore_zero - If true, suppress the "zero conflicts" message when 
3906
 
        there are no conflicts; should be set when doing something we expect
3907
 
        to complete perfectly.
3908
 
    file_list - If supplied, merge only changes to selected files.
3909
 
 
3910
 
    All available ancestors of other_revision and base_revision are
3911
 
    automatically pulled into the branch.
3912
 
 
3913
 
    The revno may be -1 to indicate the last revision on the branch, which is
3914
 
    the typical case.
3915
 
 
3916
 
    This function is intended for use from the command line; programmatic
3917
 
    clients might prefer to call merge.merge_inner(), which has less magic 
3918
 
    behavior.
3919
 
    """
3920
 
    # Loading it late, so that we don't always have to import bzrlib.merge
3921
 
    if merge_type is None:
3922
 
        merge_type = _mod_merge.Merge3Merger
3923
 
    if this_dir is None:
3924
 
        this_dir = u'.'
3925
 
    this_tree = WorkingTree.open_containing(this_dir)[0]
3926
 
    if show_base and not merge_type is _mod_merge.Merge3Merger:
3927
 
        raise errors.BzrCommandError("Show-base is not supported for this merge"
3928
 
                                     " type. %s" % merge_type)
3929
 
    if reprocess and not merge_type.supports_reprocess:
3930
 
        raise errors.BzrCommandError("Conflict reduction is not supported for merge"
3931
 
                                     " type %s." % merge_type)
3932
 
    if reprocess and show_base:
3933
 
        raise errors.BzrCommandError("Cannot do conflict reduction and show base.")
3934
 
    # TODO: jam 20070226 We should really lock these trees earlier. However, we
3935
 
    #       only want to take out a lock_tree_write() if we don't have to pull
3936
 
    #       any ancestry. But merge might fetch ancestry in the middle, in
3937
 
    #       which case we would need a lock_write().
3938
 
    #       Because we cannot upgrade locks, for now we live with the fact that
3939
 
    #       the tree will be locked multiple times during a merge. (Maybe
3940
 
    #       read-only some of the time, but it means things will get read
3941
 
    #       multiple times.)
3942
 
    try:
3943
 
        merger = _mod_merge.Merger(this_tree.branch, this_tree=this_tree,
3944
 
                                   pb=pb, change_reporter=change_reporter)
3945
 
        merger.pp = ProgressPhase("Merge phase", 5, pb)
3946
 
        merger.pp.next_phase()
3947
 
        merger.check_basis(check_clean)
3948
 
        if other_rev_id is not None:
3949
 
            merger.set_other_revision(other_rev_id, this_tree.branch)
3950
 
        else:
3951
 
            merger.set_other(other_revision, possible_transports)
3952
 
        merger.pp.next_phase()
3953
 
        if base_rev_id is not None:
3954
 
            merger.set_base_revision(base_rev_id, this_tree.branch)
3955
 
        elif base_revision is not None:
3956
 
            merger.set_base(base_revision)
3957
 
        else:
3958
 
            merger.find_base()
3959
 
        if merger.base_rev_id == merger.other_rev_id:
3960
 
            note('Nothing to do.')
3961
 
            return 0
3962
 
        if file_list is None:
3963
 
            if pull and merger.base_rev_id == merger.this_rev_id:
3964
 
                # FIXME: deduplicate with pull
3965
 
                result = merger.this_tree.pull(merger.this_branch,
3966
 
                        False, merger.other_rev_id)
3967
 
                if result.old_revid == result.new_revid:
3968
 
                    note('No revisions to pull.')
3969
 
                else:
3970
 
                    note('Now on revision %d.' % result.new_revno)
3971
 
                return 0
3972
 
        merger.backup_files = backup_files
3973
 
        merger.merge_type = merge_type 
3974
 
        merger.set_interesting_files(file_list)
3975
 
        merger.show_base = show_base 
3976
 
        merger.reprocess = reprocess
3977
 
        conflicts = merger.do_merge()
3978
 
        if file_list is None:
3979
 
            merger.set_pending()
3980
 
    finally:
3981
 
        pb.clear()
3982
 
    return conflicts
3983
 
 
3984
 
 
3985
4065
def _create_prefix(cur_transport):
3986
4066
    needed = [cur_transport]
3987
4067
    # Recurse upwards until we can create a directory successfully
4004
4084
        cur_transport.ensure_base()
4005
4085
 
4006
4086
 
4007
 
def _get_bundle_helper(location):
4008
 
    """Get a bundle if 'location' points to one.
 
4087
def _get_mergeable_helper(location):
 
4088
    """Get a merge directive or bundle if 'location' points to one.
4009
4089
 
4010
4090
    Try try to identify a bundle and returns its mergeable form. If it's not,
4011
4091
    we return the tried transport anyway so that it can reused to access the
4032
4112
    return mergeable, location_transport
4033
4113
 
4034
4114
 
4035
 
# Compatibility
4036
 
merge = _merge_helper
4037
 
 
4038
 
 
4039
4115
# these get imported and then picked up by the scan for cmd_*
4040
4116
# TODO: Some more consistent way to split command definitions across files;
4041
4117
# we do need to load at least some information about them to know of