~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Martin Pool
  • Date: 2010-01-12 01:44:13 UTC
  • mto: (4634.119.3 2.0)
  • mto: This revision was merged to the branch mainline in revision 4951.
  • Revision ID: mbp@sourcefrog.net-20100112014413-uw90vrssc3trlzmt
Refuse to build with pyrex 0.9.4*

Show diffs side-by-side

added added

removed removed

Lines of Context:
120
120
 
121
121
 
122
122
def _get_one_revision_tree(command_name, revisions, branch=None, tree=None):
 
123
    """Get a revision tree. Not suitable for commands that change the tree.
 
124
    
 
125
    Specifically, the basis tree in dirstate trees is coupled to the dirstate
 
126
    and doing a commit/uncommit/pull will at best fail due to changing the
 
127
    basis revision data.
 
128
 
 
129
    If tree is passed in, it should be already locked, for lifetime management
 
130
    of the trees internal cached state.
 
131
    """
123
132
    if branch is None:
124
133
        branch = tree.branch
125
134
    if revisions is None:
603
612
    branches that will be merged later (without showing the two different
604
613
    adds as a conflict). It is also useful when merging another project
605
614
    into a subdirectory of this one.
 
615
    
 
616
    Any files matching patterns in the ignore list will not be added
 
617
    unless they are explicitly mentioned.
606
618
    """
607
619
    takes_args = ['file*']
608
620
    takes_options = [
616
628
               help='Lookup file ids from this tree.'),
617
629
        ]
618
630
    encoding_type = 'replace'
619
 
    _see_also = ['remove']
 
631
    _see_also = ['remove', 'ignore']
620
632
 
621
633
    def run(self, file_list, no_recurse=False, dry_run=False, verbose=False,
622
634
            file_ids_from=None):
654
666
                    for path in ignored[glob]:
655
667
                        self.outf.write("ignored %s matching \"%s\"\n"
656
668
                                        % (path, glob))
657
 
            else:
658
 
                match_len = 0
659
 
                for glob, paths in ignored.items():
660
 
                    match_len += len(paths)
661
 
                self.outf.write("ignored %d file(s).\n" % match_len)
662
 
            self.outf.write("If you wish to add ignored files, "
663
 
                            "please add them explicitly by name. "
664
 
                            "(\"bzr ignored\" gives a list)\n")
665
669
 
666
670
 
667
671
class cmd_mkdir(Command):
1172
1176
        help='Hard-link working tree files where possible.'),
1173
1177
        Option('no-tree',
1174
1178
            help="Create a branch without a working-tree."),
 
1179
        Option('switch',
 
1180
            help="Switch the checkout in the current directory "
 
1181
                 "to the new branch."),
1175
1182
        Option('stacked',
1176
1183
            help='Create a stacked branch referring to the source branch. '
1177
1184
                'The new branch will depend on the availability of the source '
1188
1195
 
1189
1196
    def run(self, from_location, to_location=None, revision=None,
1190
1197
            hardlink=False, stacked=False, standalone=False, no_tree=False,
1191
 
            use_existing_dir=False):
 
1198
            use_existing_dir=False, switch=False):
 
1199
        from bzrlib import switch as _mod_switch
1192
1200
        from bzrlib.tag import _merge_tags_if_possible
1193
 
 
1194
1201
        accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1195
1202
            from_location)
1196
1203
        if (accelerator_tree is not None and
1250
1257
            except (errors.NotStacked, errors.UnstackableBranchFormat,
1251
1258
                errors.UnstackableRepositoryFormat), e:
1252
1259
                note('Branched %d revision(s).' % branch.revno())
 
1260
            if switch:
 
1261
                # Switch to the new branch
 
1262
                wt, _ = WorkingTree.open_containing('.')
 
1263
                _mod_switch.switch(wt.bzrdir, branch)
 
1264
                note('Switched to branch: %s',
 
1265
                    urlutils.unescape_for_display(branch.base, 'utf-8'))
1253
1266
        finally:
1254
1267
            br_from.unlock()
1255
1268
 
1472
1485
            title='Deletion Strategy', value_switches=True, enum_switch=False,
1473
1486
            safe='Only delete files if they can be'
1474
1487
                 ' safely recovered (default).',
1475
 
            keep="Don't delete any files.",
 
1488
            keep='Delete from bzr but leave the working copy.',
1476
1489
            force='Delete all the specified files, even if they can not be '
1477
1490
                'recovered and even if they are non-empty directories.')]
1478
1491
    aliases = ['rm', 'del']
1660
1673
                lazy_registry=('bzrlib.bzrdir', 'format_registry'),
1661
1674
                converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
1662
1675
                value_switches=True,
1663
 
                title="Branch Format",
 
1676
                title="Branch format",
1664
1677
                ),
1665
1678
         Option('append-revisions-only',
1666
1679
                help='Never change revnos or the existing log.'
2261
2274
 
2262
2275
        file_ids = []
2263
2276
        filter_by_dir = False
2264
 
        if file_list:
2265
 
            # find the file ids to log and check for directory filtering
2266
 
            b, file_info_list, rev1, rev2 = _get_info_for_log_files(revision,
2267
 
                file_list)
2268
 
            for relpath, file_id, kind in file_info_list:
2269
 
                if file_id is None:
2270
 
                    raise errors.BzrCommandError(
2271
 
                        "Path unknown at end or start of revision range: %s" %
2272
 
                        relpath)
2273
 
                # If the relpath is the top of the tree, we log everything
2274
 
                if relpath == '':
2275
 
                    file_ids = []
2276
 
                    break
 
2277
        b = None
 
2278
        try:
 
2279
            if file_list:
 
2280
                # find the file ids to log and check for directory filtering
 
2281
                b, file_info_list, rev1, rev2 = _get_info_for_log_files(
 
2282
                    revision, file_list)
 
2283
                for relpath, file_id, kind in file_info_list:
 
2284
                    if file_id is None:
 
2285
                        raise errors.BzrCommandError(
 
2286
                            "Path unknown at end or start of revision range: %s" %
 
2287
                            relpath)
 
2288
                    # If the relpath is the top of the tree, we log everything
 
2289
                    if relpath == '':
 
2290
                        file_ids = []
 
2291
                        break
 
2292
                    else:
 
2293
                        file_ids.append(file_id)
 
2294
                    filter_by_dir = filter_by_dir or (
 
2295
                        kind in ['directory', 'tree-reference'])
 
2296
            else:
 
2297
                # log everything
 
2298
                # FIXME ? log the current subdir only RBC 20060203
 
2299
                if revision is not None \
 
2300
                        and len(revision) > 0 and revision[0].get_branch():
 
2301
                    location = revision[0].get_branch()
2277
2302
                else:
2278
 
                    file_ids.append(file_id)
2279
 
                filter_by_dir = filter_by_dir or (
2280
 
                    kind in ['directory', 'tree-reference'])
2281
 
        else:
2282
 
            # log everything
2283
 
            # FIXME ? log the current subdir only RBC 20060203
2284
 
            if revision is not None \
2285
 
                    and len(revision) > 0 and revision[0].get_branch():
2286
 
                location = revision[0].get_branch()
2287
 
            else:
2288
 
                location = '.'
2289
 
            dir, relpath = bzrdir.BzrDir.open_containing(location)
2290
 
            b = dir.open_branch()
2291
 
            rev1, rev2 = _get_revision_range(revision, b, self.name())
2292
 
 
2293
 
        # Decide on the type of delta & diff filtering to use
2294
 
        # TODO: add an --all-files option to make this configurable & consistent
2295
 
        if not verbose:
2296
 
            delta_type = None
2297
 
        else:
2298
 
            delta_type = 'full'
2299
 
        if not show_diff:
2300
 
            diff_type = None
2301
 
        elif file_ids:
2302
 
            diff_type = 'partial'
2303
 
        else:
2304
 
            diff_type = 'full'
2305
 
 
2306
 
        b.lock_read()
2307
 
        try:
 
2303
                    location = '.'
 
2304
                dir, relpath = bzrdir.BzrDir.open_containing(location)
 
2305
                b = dir.open_branch()
 
2306
                b.lock_read()
 
2307
                rev1, rev2 = _get_revision_range(revision, b, self.name())
 
2308
 
 
2309
            # Decide on the type of delta & diff filtering to use
 
2310
            # TODO: add an --all-files option to make this configurable & consistent
 
2311
            if not verbose:
 
2312
                delta_type = None
 
2313
            else:
 
2314
                delta_type = 'full'
 
2315
            if not show_diff:
 
2316
                diff_type = None
 
2317
            elif file_ids:
 
2318
                diff_type = 'partial'
 
2319
            else:
 
2320
                diff_type = 'full'
 
2321
 
2308
2322
            # Build the log formatter
2309
2323
            if log_format is None:
2310
2324
                log_format = log.log_formatter_registry.get_default(b)
2340
2354
                diff_type=diff_type, _match_using_deltas=match_using_deltas)
2341
2355
            Logger(b, rqst).show(lf)
2342
2356
        finally:
2343
 
            b.unlock()
 
2357
            if b is not None:
 
2358
                b.unlock()
2344
2359
 
2345
2360
 
2346
2361
def _get_revision_range(revisionspec_list, branch, command_name):
2410
2425
    @display_command
2411
2426
    def run(self, filename):
2412
2427
        tree, relpath = WorkingTree.open_containing(filename)
 
2428
        file_id = tree.path2id(relpath)
2413
2429
        b = tree.branch
2414
 
        file_id = tree.path2id(relpath)
2415
 
        for revno, revision_id, what in log.find_touching_revisions(b, file_id):
2416
 
            self.outf.write("%6d %s\n" % (revno, what))
 
2430
        b.lock_read()
 
2431
        try:
 
2432
            touching_revs = log.find_touching_revisions(b, file_id)
 
2433
            for revno, revision_id, what in touching_revs:
 
2434
                self.outf.write("%6d %s\n" % (revno, what))
 
2435
        finally:
 
2436
            b.unlock()
2417
2437
 
2418
2438
 
2419
2439
class cmd_ls(Command):
3025
3045
                raise errors.BzrCommandError("empty commit message specified")
3026
3046
            return my_message
3027
3047
 
 
3048
        # The API permits a commit with a filter of [] to mean 'select nothing'
 
3049
        # but the command line should not do that.
 
3050
        if not selected_list:
 
3051
            selected_list = None
3028
3052
        try:
3029
3053
            tree.commit(message_callback=get_message,
3030
3054
                        specific_files=selected_list,
4385
4409
            branch.lock_read()
4386
4410
        try:
4387
4411
            tree = _get_one_revision_tree('annotate', revision, branch=branch)
4388
 
            if wt is not None:
4389
 
                file_id = wt.path2id(relpath)
4390
 
            else:
4391
 
                file_id = tree.path2id(relpath)
4392
 
            if file_id is None:
4393
 
                raise errors.NotVersionedError(filename)
4394
 
            file_version = tree.inventory[file_id].revision
4395
 
            if wt is not None and revision is None:
4396
 
                # If there is a tree and we're not annotating historical
4397
 
                # versions, annotate the working tree's content.
4398
 
                annotate_file_tree(wt, file_id, self.outf, long, all,
4399
 
                    show_ids=show_ids)
4400
 
            else:
4401
 
                annotate_file(branch, file_version, file_id, long, all, self.outf,
4402
 
                              show_ids=show_ids)
 
4412
            tree.lock_read()
 
4413
            try:
 
4414
                if wt is not None:
 
4415
                    file_id = wt.path2id(relpath)
 
4416
                else:
 
4417
                    file_id = tree.path2id(relpath)
 
4418
                if file_id is None:
 
4419
                    raise errors.NotVersionedError(filename)
 
4420
                file_version = tree.inventory[file_id].revision
 
4421
                if wt is not None and revision is None:
 
4422
                    # If there is a tree and we're not annotating historical
 
4423
                    # versions, annotate the working tree's content.
 
4424
                    annotate_file_tree(wt, file_id, self.outf, long, all,
 
4425
                        show_ids=show_ids)
 
4426
                else:
 
4427
                    annotate_file(branch, file_version, file_id, long, all,
 
4428
                        self.outf, show_ids=show_ids)
 
4429
            finally:
 
4430
                tree.unlock()
4403
4431
        finally:
4404
4432
            if wt is not None:
4405
4433
                wt.unlock()
5259
5287
            ),
5260
5288
        Option('bind-to', help='Branch to bind checkout to.', type=str),
5261
5289
        Option('force',
5262
 
               help='Perform reconfiguration even if local changes'
5263
 
               ' will be lost.')
 
5290
            help='Perform reconfiguration even if local changes'
 
5291
            ' will be lost.'),
 
5292
        Option('stacked-on',
 
5293
            help='Reconfigure a branch to be stacked on another branch.',
 
5294
            type=unicode,
 
5295
            ),
 
5296
        Option('unstacked',
 
5297
            help='Reconfigure a branch to be unstacked.  This '
 
5298
                'may require copying substantial data into it.',
 
5299
            ),
5264
5300
        ]
5265
5301
 
5266
 
    def run(self, location=None, target_type=None, bind_to=None, force=False):
 
5302
    def run(self, location=None, target_type=None, bind_to=None, force=False,
 
5303
            stacked_on=None,
 
5304
            unstacked=None):
5267
5305
        directory = bzrdir.BzrDir.open(location)
 
5306
        if stacked_on and unstacked:
 
5307
            raise BzrCommandError("Can't use both --stacked-on and --unstacked")
 
5308
        elif stacked_on is not None:
 
5309
            reconfigure.ReconfigureStackedOn().apply(directory, stacked_on)
 
5310
        elif unstacked:
 
5311
            reconfigure.ReconfigureUnstacked().apply(directory)
 
5312
        # At the moment you can use --stacked-on and a different
 
5313
        # reconfiguration shape at the same time; there seems no good reason
 
5314
        # to ban it.
5268
5315
        if target_type is None:
5269
 
            raise errors.BzrCommandError('No target configuration specified')
 
5316
            if stacked_on or unstacked:
 
5317
                return
 
5318
            else:
 
5319
                raise errors.BzrCommandError('No target configuration '
 
5320
                    'specified')
5270
5321
        elif target_type == 'branch':
5271
5322
            reconfiguration = reconfigure.Reconfigure.to_branch(directory)
5272
5323
        elif target_type == 'tree':
5604
5655
        if writer is None:
5605
5656
            writer = bzrlib.option.diff_writer_registry.get()
5606
5657
        try:
5607
 
            Shelver.from_args(writer(sys.stdout), revision, all, file_list,
5608
 
                              message, destroy=destroy).run()
 
5658
            shelver = Shelver.from_args(writer(sys.stdout), revision, all,
 
5659
                file_list, message, destroy=destroy)
 
5660
            try:
 
5661
                shelver.run()
 
5662
            finally:
 
5663
                shelver.work_tree.unlock()
5609
5664
        except errors.UserAbort:
5610
5665
            return 0
5611
5666
 
5650
5705
 
5651
5706
    def run(self, shelf_id=None, action='apply'):
5652
5707
        from bzrlib.shelf_ui import Unshelver
5653
 
        Unshelver.from_args(shelf_id, action).run()
 
5708
        unshelver = Unshelver.from_args(shelf_id, action)
 
5709
        try:
 
5710
            unshelver.run()
 
5711
        finally:
 
5712
            unshelver.tree.unlock()
5654
5713
 
5655
5714
 
5656
5715
class cmd_clean_tree(Command):