~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Danny van Heumen
  • Date: 2010-03-09 21:42:11 UTC
  • mto: (4634.139.5 2.0)
  • mto: This revision was merged to the branch mainline in revision 5160.
  • Revision ID: danny@dannyvanheumen.nl-20100309214211-iqh42x6qcikgd9p3
Reverted now-useless TODO list.

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:
1167
1176
        help='Hard-link working tree files where possible.'),
1168
1177
        Option('no-tree',
1169
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."),
1170
1182
        Option('stacked',
1171
1183
            help='Create a stacked branch referring to the source branch. '
1172
1184
                'The new branch will depend on the availability of the source '
1183
1195
 
1184
1196
    def run(self, from_location, to_location=None, revision=None,
1185
1197
            hardlink=False, stacked=False, standalone=False, no_tree=False,
1186
 
            use_existing_dir=False):
 
1198
            use_existing_dir=False, switch=False):
 
1199
        from bzrlib import switch as _mod_switch
1187
1200
        from bzrlib.tag import _merge_tags_if_possible
1188
 
 
1189
1201
        accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1190
1202
            from_location)
1191
1203
        if (accelerator_tree is not None and
1245
1257
            except (errors.NotStacked, errors.UnstackableBranchFormat,
1246
1258
                errors.UnstackableRepositoryFormat), e:
1247
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'))
1248
1266
        finally:
1249
1267
            br_from.unlock()
1250
1268
 
1655
1673
                lazy_registry=('bzrlib.bzrdir', 'format_registry'),
1656
1674
                converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
1657
1675
                value_switches=True,
1658
 
                title="Branch Format",
 
1676
                title="Branch format",
1659
1677
                ),
1660
1678
         Option('append-revisions-only',
1661
1679
                help='Never change revnos or the existing log.'
2256
2274
 
2257
2275
        file_ids = []
2258
2276
        filter_by_dir = False
2259
 
        if file_list:
2260
 
            # find the file ids to log and check for directory filtering
2261
 
            b, file_info_list, rev1, rev2 = _get_info_for_log_files(revision,
2262
 
                file_list)
2263
 
            for relpath, file_id, kind in file_info_list:
2264
 
                if file_id is None:
2265
 
                    raise errors.BzrCommandError(
2266
 
                        "Path unknown at end or start of revision range: %s" %
2267
 
                        relpath)
2268
 
                # If the relpath is the top of the tree, we log everything
2269
 
                if relpath == '':
2270
 
                    file_ids = []
2271
 
                    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()
2272
2302
                else:
2273
 
                    file_ids.append(file_id)
2274
 
                filter_by_dir = filter_by_dir or (
2275
 
                    kind in ['directory', 'tree-reference'])
2276
 
        else:
2277
 
            # log everything
2278
 
            # FIXME ? log the current subdir only RBC 20060203
2279
 
            if revision is not None \
2280
 
                    and len(revision) > 0 and revision[0].get_branch():
2281
 
                location = revision[0].get_branch()
2282
 
            else:
2283
 
                location = '.'
2284
 
            dir, relpath = bzrdir.BzrDir.open_containing(location)
2285
 
            b = dir.open_branch()
2286
 
            rev1, rev2 = _get_revision_range(revision, b, self.name())
2287
 
 
2288
 
        # Decide on the type of delta & diff filtering to use
2289
 
        # TODO: add an --all-files option to make this configurable & consistent
2290
 
        if not verbose:
2291
 
            delta_type = None
2292
 
        else:
2293
 
            delta_type = 'full'
2294
 
        if not show_diff:
2295
 
            diff_type = None
2296
 
        elif file_ids:
2297
 
            diff_type = 'partial'
2298
 
        else:
2299
 
            diff_type = 'full'
2300
 
 
2301
 
        b.lock_read()
2302
 
        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
 
2303
2322
            # Build the log formatter
2304
2323
            if log_format is None:
2305
2324
                log_format = log.log_formatter_registry.get_default(b)
2335
2354
                diff_type=diff_type, _match_using_deltas=match_using_deltas)
2336
2355
            Logger(b, rqst).show(lf)
2337
2356
        finally:
2338
 
            b.unlock()
 
2357
            if b is not None:
 
2358
                b.unlock()
2339
2359
 
2340
2360
 
2341
2361
def _get_revision_range(revisionspec_list, branch, command_name):
2405
2425
    @display_command
2406
2426
    def run(self, filename):
2407
2427
        tree, relpath = WorkingTree.open_containing(filename)
 
2428
        file_id = tree.path2id(relpath)
2408
2429
        b = tree.branch
2409
 
        file_id = tree.path2id(relpath)
2410
 
        for revno, revision_id, what in log.find_touching_revisions(b, file_id):
2411
 
            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()
2412
2437
 
2413
2438
 
2414
2439
class cmd_ls(Command):
3020
3045
                raise errors.BzrCommandError("empty commit message specified")
3021
3046
            return my_message
3022
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
3023
3052
        try:
3024
3053
            tree.commit(message_callback=get_message,
3025
3054
                        specific_files=selected_list,
4016
4045
    def run(self, revision=None, no_backup=False, file_list=None,
4017
4046
            forget_merges=None):
4018
4047
        tree, file_list = tree_files(file_list)
4019
 
        tree.lock_write()
 
4048
        tree.lock_tree_write()
4020
4049
        try:
4021
4050
            if forget_merges:
4022
4051
                tree.set_parent_ids(tree.get_parent_ids()[:1])
4380
4409
            branch.lock_read()
4381
4410
        try:
4382
4411
            tree = _get_one_revision_tree('annotate', revision, branch=branch)
4383
 
            if wt is not None:
4384
 
                file_id = wt.path2id(relpath)
4385
 
            else:
4386
 
                file_id = tree.path2id(relpath)
4387
 
            if file_id is None:
4388
 
                raise errors.NotVersionedError(filename)
4389
 
            file_version = tree.inventory[file_id].revision
4390
 
            if wt is not None and revision is None:
4391
 
                # If there is a tree and we're not annotating historical
4392
 
                # versions, annotate the working tree's content.
4393
 
                annotate_file_tree(wt, file_id, self.outf, long, all,
4394
 
                    show_ids=show_ids)
4395
 
            else:
4396
 
                annotate_file(branch, file_version, file_id, long, all, self.outf,
4397
 
                              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()
4398
4431
        finally:
4399
4432
            if wt is not None:
4400
4433
                wt.unlock()
5622
5655
        if writer is None:
5623
5656
            writer = bzrlib.option.diff_writer_registry.get()
5624
5657
        try:
5625
 
            Shelver.from_args(writer(sys.stdout), revision, all, file_list,
5626
 
                              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()
5627
5664
        except errors.UserAbort:
5628
5665
            return 0
5629
5666
 
5668
5705
 
5669
5706
    def run(self, shelf_id=None, action='apply'):
5670
5707
        from bzrlib.shelf_ui import Unshelver
5671
 
        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()
5672
5713
 
5673
5714
 
5674
5715
class cmd_clean_tree(Command):