/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
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
 
        tree = None
2119
 
        try:
2120
 
            tree, b, relpath = \
2121
 
                    bzrdir.BzrDir.open_containing_tree_or_branch(filename)
2122
 
        except errors.NotBranchError:
2123
 
            pass
2124
 
 
2125
 
        if revision is not None and revision[0].get_branch() is not None:
2126
 
            b = Branch.open(revision[0].get_branch())
2127
 
        b.lock_read()
2128
 
        try:
2129
 
            return self._run(tree, b, relpath, filename, revision,
2130
 
                name_from_revision)
 
2129
                                         " one revision specifier")
 
2130
        tree, branch, relpath = \
 
2131
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
2132
        branch.lock_read()
 
2133
        try:
 
2134
            return self._run(tree, branch, relpath, filename, revision,
 
2135
                             name_from_revision)
2131
2136
        finally:
2132
 
            b.unlock()
 
2137
            branch.unlock()
2133
2138
 
2134
2139
    def _run(self, tree, b, relpath, filename, revision, name_from_revision):
2135
2140
        if tree is None:
2599
2604
                                 ' expression.'),
2600
2605
                     Option('strict', help='Fail on missing dependencies or '
2601
2606
                            'known failures.'),
 
2607
                     Option('coverage', type=str, argname="DIRECTORY",
 
2608
                            help='Generate line coverage report in this'
 
2609
                                 'directory.'),
2602
2610
                     ]
2603
2611
    encoding_type = 'replace'
2604
2612
 
2606
2614
            transport=None, benchmark=None,
2607
2615
            lsprof_timed=None, cache_dir=None,
2608
2616
            first=False, list_only=False,
2609
 
            randomize=None, exclude=None, strict=False):
 
2617
            randomize=None, exclude=None, strict=False, coverage=None):
2610
2618
        import bzrlib.ui
2611
2619
        from bzrlib.tests import selftest
2612
2620
        import bzrlib.benchmarks as benchmarks
2648
2656
                              random_seed=randomize,
2649
2657
                              exclude_pattern=exclude,
2650
2658
                              strict=strict,
 
2659
                              coverage_dir=coverage,
2651
2660
                              )
2652
2661
        finally:
2653
2662
            if benchfile is not None:
3574
3583
    def run(self, location=None,
3575
3584
            dry_run=False, verbose=False,
3576
3585
            revision=None, force=False):
3577
 
        from bzrlib.log import log_formatter, show_log
3578
 
        from bzrlib.uncommit import uncommit
3579
 
 
3580
3586
        if location is None:
3581
3587
            location = u'.'
3582
3588
        control, relpath = bzrdir.BzrDir.open_containing(location)
3587
3593
            tree = None
3588
3594
            b = control.open_branch()
3589
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
 
3590
3614
        rev_id = None
3591
3615
        if revision is None:
3592
 
            revno = b.revno()
 
3616
            revno = last_revno
 
3617
            rev_id = last_rev_id
3593
3618
        else:
3594
3619
            # 'bzr uncommit -r 10' actually means uncommit
3595
3620
            # so that the final tree is at revno 10.
3596
3621
            # but bzrlib.uncommit.uncommit() actually uncommits
3597
3622
            # the revisions that are supplied.
3598
3623
            # So we need to offset it by one
3599
 
            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)
3600
3627
 
3601
 
        if revno <= b.revno():
3602
 
            rev_id = b.get_rev_id(revno)
3603
3628
        if rev_id is None or _mod_revision.is_null(rev_id):
3604
3629
            self.outf.write('No revisions to uncommit.\n')
3605
3630
            return 1
3613
3638
                 verbose=False,
3614
3639
                 direction='forward',
3615
3640
                 start_revision=revno,
3616
 
                 end_revision=b.revno())
 
3641
                 end_revision=last_revno)
3617
3642
 
3618
3643
        if dry_run:
3619
3644
            print 'Dry-run, pretending to remove the above revisions.'
3628
3653
                    return 0
3629
3654
 
3630
3655
        uncommit(b, tree=tree, dry_run=dry_run, verbose=verbose,
3631
 
                revno=revno)
 
3656
                 revno=revno)
3632
3657
 
3633
3658
 
3634
3659
class cmd_break_lock(Command):
3941
3966
    for that mirror.
3942
3967
 
3943
3968
    Mail is sent using your preferred mail program.  This should be transparent
3944
 
    on Windows (it uses MAPI).  On *nix, it requires the xdg-email utility.  If
3945
 
    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.
3946
3971
    
3947
3972
    To use a specific mail program, set the mail_client configuration option.
3948
3973
    (For Thunderbird 1.5, this works around some bugs.)  Supported values for
4328
4353
 
4329
4354
 
4330
4355
class cmd_switch(Command):
4331
 
    """Set the branch of a lightweight checkout and update."""
 
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
    """
4332
4368
 
4333
4369
    takes_args = ['to_location']
 
4370
    takes_options = [Option('force',
 
4371
                        help='Switch even if local commits will be lost.')
 
4372
                     ]
4334
4373
 
4335
 
    def run(self, to_location):
 
4374
    def run(self, to_location, force=False):
4336
4375
        from bzrlib import switch
4337
4376
        to_branch = Branch.open(to_location)
4338
4377
        tree_location = '.'
4339
4378
        control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
4340
 
        switch.switch(control_dir, to_branch)
 
4379
        switch.switch(control_dir, to_branch, force)
4341
4380
        note('Switched to branch: %s',
4342
4381
            urlutils.unescape_for_display(to_branch.base, 'utf-8'))
4343
4382