/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

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
747
747
            # The destination doesn't exist; create it.
748
748
            # XXX: Refactor the create_prefix/no_create_prefix code into a
749
749
            #      common helper function
 
750
 
 
751
            def make_directory(transport):
 
752
                transport.mkdir('.')
 
753
                return transport
 
754
 
 
755
            def redirected(redirected_transport, e, redirection_notice):
 
756
                return transport.get_transport(e.get_target_url())
 
757
 
750
758
            try:
751
 
                to_transport.mkdir('.')
 
759
                to_transport = transport.do_catching_redirections(
 
760
                    make_directory, to_transport, redirected)
752
761
            except errors.FileExists:
753
762
                if not use_existing_dir:
754
763
                    raise errors.BzrCommandError("Target directory %s"
763
772
                        " leading parent directories."
764
773
                        % location)
765
774
                _create_prefix(to_transport)
 
775
            except errors.TooManyRedirections:
 
776
                raise errors.BzrCommandError("Too many redirections trying "
 
777
                                             "to make %s." % location)
766
778
 
767
779
            # Now the target directory exists, but doesn't have a .bzr
768
780
            # directory. So we need to create it, along with any work to create
1255
1267
        bzr init
1256
1268
        bzr add .
1257
1269
        bzr status
1258
 
        bzr commit -m 'imported project'
 
1270
        bzr commit -m "imported project"
1259
1271
    """
1260
1272
 
1261
1273
    _see_also = ['init-repository', 'branch', 'checkout']
1915
1927
 
1916
1928
        Ignore class files in all directories::
1917
1929
 
1918
 
            bzr ignore '*.class'
1919
 
 
1920
 
        Ignore .o files under the lib directory::
1921
 
 
1922
 
            bzr ignore 'lib/**/*.o'
1923
 
 
1924
 
        Ignore .o files under the lib directory::
1925
 
 
1926
 
            bzr ignore 'RE:lib/.*\.o'
 
1930
            bzr ignore "*.class"
 
1931
 
 
1932
        Ignore .o files under the lib directory::
 
1933
 
 
1934
            bzr ignore "lib/**/*.o"
 
1935
 
 
1936
        Ignore .o files under the lib directory::
 
1937
 
 
1938
            bzr ignore "RE:lib/.*\.o"
1927
1939
    """
1928
1940
 
1929
1941
    _see_also = ['status', 'ignored']
2114
2126
    def run(self, filename, revision=None, name_from_revision=False):
2115
2127
        if revision is not None and len(revision) != 1:
2116
2128
            raise errors.BzrCommandError("bzr cat --revision takes exactly"
2117
 
                                        " one number")
2118
 
 
2119
 
        tree = None
 
2129
                                         " one revision specifier")
 
2130
        tree, branch, relpath = \
 
2131
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
2132
        branch.lock_read()
2120
2133
        try:
2121
 
            tree, b, relpath = \
2122
 
                    bzrdir.BzrDir.open_containing_tree_or_branch(filename)
2123
 
        except errors.NotBranchError:
2124
 
            pass
 
2134
            return self._run(tree, branch, relpath, filename, revision,
 
2135
                             name_from_revision)
 
2136
        finally:
 
2137
            branch.unlock()
2125
2138
 
2126
 
        if revision is not None and revision[0].get_branch() is not None:
2127
 
            b = Branch.open(revision[0].get_branch())
 
2139
    def _run(self, tree, b, relpath, filename, revision, name_from_revision):
2128
2140
        if tree is None:
2129
2141
            tree = b.basis_tree()
2130
2142
        if revision is None:
2437
2449
 
2438
2450
        Set the current user::
2439
2451
 
2440
 
            bzr whoami 'Frank Chu <fchu@example.com>'
 
2452
            bzr whoami "Frank Chu <fchu@example.com>"
2441
2453
    """
2442
2454
    takes_options = [ Option('email',
2443
2455
                             help='Display email address only.'),
2592
2604
                                 ' expression.'),
2593
2605
                     Option('strict', help='Fail on missing dependencies or '
2594
2606
                            'known failures.'),
 
2607
                     Option('coverage', type=str, argname="DIRECTORY",
 
2608
                            help='Generate line coverage report in this'
 
2609
                                 'directory.'),
2595
2610
                     ]
2596
2611
    encoding_type = 'replace'
2597
2612
 
2599
2614
            transport=None, benchmark=None,
2600
2615
            lsprof_timed=None, cache_dir=None,
2601
2616
            first=False, list_only=False,
2602
 
            randomize=None, exclude=None, strict=False):
 
2617
            randomize=None, exclude=None, strict=False, coverage=None):
2603
2618
        import bzrlib.ui
2604
2619
        from bzrlib.tests import selftest
2605
2620
        import bzrlib.benchmarks as benchmarks
2641
2656
                              random_seed=randomize,
2642
2657
                              exclude_pattern=exclude,
2643
2658
                              strict=strict,
 
2659
                              coverage_dir=coverage,
2644
2660
                              )
2645
2661
        finally:
2646
2662
            if benchfile is not None:
2686
2702
        
2687
2703
        branch1 = Branch.open_containing(branch)[0]
2688
2704
        branch2 = Branch.open_containing(other)[0]
2689
 
 
2690
 
        last1 = ensure_null(branch1.last_revision())
2691
 
        last2 = ensure_null(branch2.last_revision())
2692
 
 
2693
 
        graph = branch1.repository.get_graph(branch2.repository)
2694
 
        base_rev_id = graph.find_unique_lca(last1, last2)
2695
 
 
2696
 
        print 'merge base is revision %s' % base_rev_id
 
2705
        branch1.lock_read()
 
2706
        try:
 
2707
            branch2.lock_read()
 
2708
            try:
 
2709
                last1 = ensure_null(branch1.last_revision())
 
2710
                last2 = ensure_null(branch2.last_revision())
 
2711
 
 
2712
                graph = branch1.repository.get_graph(branch2.repository)
 
2713
                base_rev_id = graph.find_unique_lca(last1, last2)
 
2714
 
 
2715
                print 'merge base is revision %s' % base_rev_id
 
2716
            finally:
 
2717
                branch2.unlock()
 
2718
        finally:
 
2719
            branch1.unlock()
2697
2720
 
2698
2721
 
2699
2722
class cmd_merge(Command):
2817
2840
                merger = _mod_merge.Merger.from_uncommitted(tree, other_tree,
2818
2841
                    pb)
2819
2842
                allow_pending = False
 
2843
                if other_path != '':
 
2844
                    merger.interesting_files = [other_path]
2820
2845
 
2821
2846
            if merger is None:
2822
2847
                merger, allow_pending = self._get_merger_from_branch(tree,
3072
3097
    last committed revision is used.
3073
3098
 
3074
3099
    To remove only some changes, without reverting to a prior version, use
3075
 
    merge instead.  For example, "merge . --r-2..-3" will remove the changes
3076
 
    introduced by -2, without affecting the changes introduced by -1.  Or
3077
 
    to remove certain changes on a hunk-by-hunk basis, see the Shelf plugin.
 
3100
    merge instead.  For example, "merge . --revision -2..-3" will remove the
 
3101
    changes introduced by -2, without affecting the changes introduced by -1.
 
3102
    Or to remove certain changes on a hunk-by-hunk basis, see the Shelf plugin.
3078
3103
    
3079
3104
    By default, any files that have been manually changed will be backed up
3080
3105
    first.  (Files changed only by merge are not backed up.)  Backup files have
3422
3447
    takes_options = ['revision']
3423
3448
    
3424
3449
    def run(self, revision_id_list=None, revision=None):
3425
 
        import bzrlib.gpg as gpg
3426
3450
        if revision_id_list is not None and revision is not None:
3427
3451
            raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
3428
3452
        if revision_id_list is None and revision is None:
3429
3453
            raise errors.BzrCommandError('You must supply either --revision or a revision_id')
3430
3454
        b = WorkingTree.open_containing(u'.')[0].branch
 
3455
        b.lock_write()
 
3456
        try:
 
3457
            return self._run(b, revision_id_list, revision)
 
3458
        finally:
 
3459
            b.unlock()
 
3460
 
 
3461
    def _run(self, b, revision_id_list, revision):
 
3462
        import bzrlib.gpg as gpg
3431
3463
        gpg_strategy = gpg.GPGStrategy(b.get_config())
3432
3464
        if revision_id_list is not None:
3433
 
            for revision_id in revision_id_list:
3434
 
                b.repository.sign_revision(revision_id, gpg_strategy)
 
3465
            b.repository.start_write_group()
 
3466
            try:
 
3467
                for revision_id in revision_id_list:
 
3468
                    b.repository.sign_revision(revision_id, gpg_strategy)
 
3469
            except:
 
3470
                b.repository.abort_write_group()
 
3471
                raise
 
3472
            else:
 
3473
                b.repository.commit_write_group()
3435
3474
        elif revision is not None:
3436
3475
            if len(revision) == 1:
3437
3476
                revno, rev_id = revision[0].in_history(b)
3438
 
                b.repository.sign_revision(rev_id, gpg_strategy)
 
3477
                b.repository.start_write_group()
 
3478
                try:
 
3479
                    b.repository.sign_revision(rev_id, gpg_strategy)
 
3480
                except:
 
3481
                    b.repository.abort_write_group()
 
3482
                    raise
 
3483
                else:
 
3484
                    b.repository.commit_write_group()
3439
3485
            elif len(revision) == 2:
3440
3486
                # are they both on rh- if so we can walk between them
3441
3487
                # might be nice to have a range helper for arbitrary
3446
3492
                    to_revno = b.revno()
3447
3493
                if from_revno is None or to_revno is None:
3448
3494
                    raise errors.BzrCommandError('Cannot sign a range of non-revision-history revisions')
3449
 
                for revno in range(from_revno, to_revno + 1):
3450
 
                    b.repository.sign_revision(b.get_rev_id(revno), 
3451
 
                                               gpg_strategy)
 
3495
                b.repository.start_write_group()
 
3496
                try:
 
3497
                    for revno in range(from_revno, to_revno + 1):
 
3498
                        b.repository.sign_revision(b.get_rev_id(revno),
 
3499
                                                   gpg_strategy)
 
3500
                except:
 
3501
                    b.repository.abort_write_group()
 
3502
                    raise
 
3503
                else:
 
3504
                    b.repository.commit_write_group()
3452
3505
            else:
3453
3506
                raise errors.BzrCommandError('Please supply either one revision, or a range.')
3454
3507
 
3530
3583
    def run(self, location=None,
3531
3584
            dry_run=False, verbose=False,
3532
3585
            revision=None, force=False):
3533
 
        from bzrlib.log import log_formatter, show_log
3534
 
        from bzrlib.uncommit import uncommit
3535
 
 
3536
3586
        if location is None:
3537
3587
            location = u'.'
3538
3588
        control, relpath = bzrdir.BzrDir.open_containing(location)
3543
3593
            tree = None
3544
3594
            b = control.open_branch()
3545
3595
 
 
3596
        if tree is not None:
 
3597
            tree.lock_write()
 
3598
        else:
 
3599
            b.lock_write()
 
3600
        try:
 
3601
            return self._run(b, tree, dry_run, verbose, revision, force)
 
3602
        finally:
 
3603
            if tree is not None:
 
3604
                tree.unlock()
 
3605
            else:
 
3606
                b.unlock()
 
3607
 
 
3608
    def _run(self, b, tree, dry_run, verbose, revision, force):
 
3609
        from bzrlib.log import log_formatter, show_log
 
3610
        from bzrlib.uncommit import uncommit
 
3611
 
 
3612
        last_revno, last_rev_id = b.last_revision_info()
 
3613
 
3546
3614
        rev_id = None
3547
3615
        if revision is None:
3548
 
            revno = b.revno()
 
3616
            revno = last_revno
 
3617
            rev_id = last_rev_id
3549
3618
        else:
3550
3619
            # 'bzr uncommit -r 10' actually means uncommit
3551
3620
            # so that the final tree is at revno 10.
3552
3621
            # but bzrlib.uncommit.uncommit() actually uncommits
3553
3622
            # the revisions that are supplied.
3554
3623
            # So we need to offset it by one
3555
 
            revno = revision[0].in_history(b).revno+1
 
3624
            revno = revision[0].in_history(b).revno + 1
 
3625
            if revno <= last_revno:
 
3626
                rev_id = b.get_rev_id(revno)
3556
3627
 
3557
 
        if revno <= b.revno():
3558
 
            rev_id = b.get_rev_id(revno)
3559
3628
        if rev_id is None or _mod_revision.is_null(rev_id):
3560
3629
            self.outf.write('No revisions to uncommit.\n')
3561
3630
            return 1
3569
3638
                 verbose=False,
3570
3639
                 direction='forward',
3571
3640
                 start_revision=revno,
3572
 
                 end_revision=b.revno())
 
3641
                 end_revision=last_revno)
3573
3642
 
3574
3643
        if dry_run:
3575
3644
            print 'Dry-run, pretending to remove the above revisions.'
3584
3653
                    return 0
3585
3654
 
3586
3655
        uncommit(b, tree=tree, dry_run=dry_run, verbose=verbose,
3587
 
                revno=revno)
 
3656
                 revno=revno)
3588
3657
 
3589
3658
 
3590
3659
class cmd_break_lock(Command):
3652
3721
        from bzrlib.smart import medium, server
3653
3722
        from bzrlib.transport import get_transport
3654
3723
        from bzrlib.transport.chroot import ChrootServer
3655
 
        from bzrlib.transport.remote import BZR_DEFAULT_PORT, BZR_DEFAULT_INTERFACE
3656
3724
        if directory is None:
3657
3725
            directory = os.getcwd()
3658
3726
        url = urlutils.local_path_to_url(directory)
3665
3733
            smart_server = medium.SmartServerPipeStreamMedium(
3666
3734
                sys.stdin, sys.stdout, t)
3667
3735
        else:
3668
 
            host = BZR_DEFAULT_INTERFACE
 
3736
            host = medium.BZR_DEFAULT_INTERFACE
3669
3737
            if port is None:
3670
 
                port = BZR_DEFAULT_PORT
 
3738
                port = medium.BZR_DEFAULT_PORT
3671
3739
            else:
3672
3740
                if ':' in port:
3673
3741
                    host, port = port.split(':')
3898
3966
    for that mirror.
3899
3967
 
3900
3968
    Mail is sent using your preferred mail program.  This should be transparent
3901
 
    on Windows (it uses MAPI).  On *nix, it requires the xdg-email utility.  If
3902
 
    the preferred client can't be found (or used), your editor will be used.
 
3969
    on Windows (it uses MAPI).  On Linux, it requires the xdg-email utility.
 
3970
    If the preferred client can't be found (or used), your editor will be used.
3903
3971
    
3904
3972
    To use a specific mail program, set the mail_client configuration option.
3905
3973
    (For Thunderbird 1.5, this works around some bugs.)  Supported values for
3965
4033
            outfile = open(output, 'wb')
3966
4034
        try:
3967
4035
            branch = Branch.open_containing(from_)[0]
 
4036
            # we may need to write data into branch's repository to calculate
 
4037
            # the data to send.
 
4038
            branch.lock_write()
3968
4039
            if output is None:
3969
4040
                config = branch.get_config()
3970
4041
                if mail_to is None:
3971
4042
                    mail_to = config.get_user_option('submit_to')
3972
 
                if mail_to is None:
3973
 
                    raise errors.BzrCommandError('No mail-to address'
3974
 
                                                 ' specified')
3975
4043
                mail_client = config.get_mail_client()
3976
4044
            if remember and submit_branch is None:
3977
4045
                raise errors.BzrCommandError(
4052
4120
        finally:
4053
4121
            if output != '-':
4054
4122
                outfile.close()
 
4123
            branch.unlock()
4055
4124
 
4056
4125
 
4057
4126
class cmd_bundle_revisions(cmd_send):
4187
4256
class cmd_tags(Command):
4188
4257
    """List tags.
4189
4258
 
4190
 
    This tag shows a table of tag names and the revisions they reference.
 
4259
    This command shows a table of tag names and the revisions they reference.
4191
4260
    """
4192
4261
 
4193
4262
    _see_also = ['tag']
4256
4325
                     value_switches=True, enum_switch=False,
4257
4326
                     branch='Reconfigure to a branch.',
4258
4327
                     tree='Reconfigure to a tree.',
4259
 
                     checkout='Reconfigure to a checkout.'),
 
4328
                     checkout='Reconfigure to a checkout.',
 
4329
                     lightweight_checkout='Reconfigure to a lightweight'
 
4330
                     ' checkout.'),
4260
4331
                     Option('bind-to', help='Branch to bind checkout to.',
4261
4332
                            type=str),
4262
4333
                     Option('force',
4275
4346
        elif target_type == 'checkout':
4276
4347
            reconfiguration = reconfigure.Reconfigure.to_checkout(directory,
4277
4348
                                                                  bind_to)
 
4349
        elif target_type == 'lightweight-checkout':
 
4350
            reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
 
4351
                directory, bind_to)
4278
4352
        reconfiguration.apply(force)
4279
4353
 
4280
4354
 
 
4355
class cmd_switch(Command):
 
4356
    """Set the branch of a checkout and update.
 
4357
    
 
4358
    For lightweight checkouts, this changes the branch being referenced.
 
4359
    For heavyweight checkouts, this checks that there are no local commits
 
4360
    versus the current bound branch, then it makes the local branch a mirror
 
4361
    of the new location and binds to it.
 
4362
    
 
4363
    In both cases, the working tree is updated and uncommitted changes
 
4364
    are merged. The user can commit or revert these as they desire.
 
4365
 
 
4366
    Pending merges need to be committed or reverted before using switch.
 
4367
    """
 
4368
 
 
4369
    takes_args = ['to_location']
 
4370
    takes_options = [Option('force',
 
4371
                        help='Switch even if local commits will be lost.')
 
4372
                     ]
 
4373
 
 
4374
    def run(self, to_location, force=False):
 
4375
        from bzrlib import switch
 
4376
        to_branch = Branch.open(to_location)
 
4377
        tree_location = '.'
 
4378
        control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
 
4379
        switch.switch(control_dir, to_branch, force)
 
4380
        note('Switched to branch: %s',
 
4381
            urlutils.unescape_for_display(to_branch.base, 'utf-8'))
 
4382
 
 
4383
 
4281
4384
def _create_prefix(cur_transport):
4282
4385
    needed = [cur_transport]
4283
4386
    # Recurse upwards until we can create a directory successfully