/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-02-16 07:02:19 UTC
  • mfrom: (2292 +trunk)
  • mto: (2255.6.1 dirstate)
  • mto: This revision was merged to the branch mainline in revision 2322.
  • Revision ID: aaron.bentley@utoronto.ca-20070216070219-b22k0gwnisnxawnk
Merged bzr.dev (17 tests failing)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2004, 2005, 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
237
237
    this will refuse to run against one.
238
238
    """
239
239
 
240
 
    hidden = True
241
 
 
242
240
    takes_args = ['location?']
243
241
 
244
242
    def run(self, location='.'):
416
414
 
417
415
    It is also possible to restrict the list of files to a specific
418
416
    set. For example: bzr inventory --show-ids this/file
 
417
 
 
418
    See also: bzr ls
419
419
    """
420
420
 
 
421
    hidden = True
 
422
 
421
423
    takes_options = ['revision', 'show-ids', 'kind']
 
424
 
422
425
    takes_args = ['file*']
423
426
 
424
427
    @display_command
532
535
    location can be accessed.
533
536
    """
534
537
 
535
 
    takes_options = ['remember', 'overwrite', 'revision', 'verbose']
 
538
    takes_options = ['remember', 'overwrite', 'revision', 'verbose',
 
539
        Option('directory',
 
540
            help='branch to pull into, '
 
541
                 'rather than the one containing the working directory',
 
542
            short_name='d',
 
543
            type=unicode,
 
544
            ),
 
545
        ]
536
546
    takes_args = ['location?']
537
547
    encoding_type = 'replace'
538
548
 
539
 
    def run(self, location=None, remember=False, overwrite=False, revision=None, verbose=False):
 
549
    def run(self, location=None, remember=False, overwrite=False,
 
550
            revision=None, verbose=False,
 
551
            directory=None):
540
552
        # FIXME: too much stuff is in the command class
 
553
        if directory is None:
 
554
            directory = u'.'
541
555
        try:
542
 
            tree_to = WorkingTree.open_containing(u'.')[0]
 
556
            tree_to = WorkingTree.open_containing(directory)[0]
543
557
            branch_to = tree_to.branch
544
558
        except errors.NoWorkingTree:
545
559
            tree_to = None
546
 
            branch_to = Branch.open_containing(u'.')[0]
 
560
            branch_to = Branch.open_containing(directory)[0]
547
561
 
548
562
        reader = None
549
563
        if location is not None:
563
577
                self.outf.write("Using saved location: %s\n" % display_url)
564
578
                location = stored_loc
565
579
 
566
 
 
567
580
        if reader is not None:
568
581
            install_bundle(branch_to.repository, reader)
569
582
            branch_from = branch_to
584
597
 
585
598
        old_rh = branch_to.revision_history()
586
599
        if tree_to is not None:
587
 
            count = tree_to.pull(branch_from, overwrite, rev_id)
 
600
            count = tree_to.pull(branch_from, overwrite, rev_id,
 
601
                delta.ChangeReporter(tree_to.inventory))
588
602
        else:
589
603
            count = branch_to.pull(branch_from, overwrite, rev_id)
590
604
        note('%d revision(s) pulled.' % (count,))
625
639
    """
626
640
 
627
641
    takes_options = ['remember', 'overwrite', 'verbose',
628
 
                     Option('create-prefix',
629
 
                            help='Create the path leading up to the branch '
630
 
                                 'if it does not already exist'),
631
 
                     Option('use-existing-dir',
632
 
                            help='By default push will fail if the target'
633
 
                                 ' directory exists, but does not already'
634
 
                                 ' have a control directory. This flag will'
635
 
                                 ' allow push to proceed.'),
636
 
                     ]
 
642
        Option('create-prefix',
 
643
               help='Create the path leading up to the branch '
 
644
                    'if it does not already exist'),
 
645
        Option('directory',
 
646
            help='branch to push from, '
 
647
                 'rather than the one containing the working directory',
 
648
            short_name='d',
 
649
            type=unicode,
 
650
            ),
 
651
        Option('use-existing-dir',
 
652
               help='By default push will fail if the target'
 
653
                    ' directory exists, but does not already'
 
654
                    ' have a control directory. This flag will'
 
655
                    ' allow push to proceed.'),
 
656
        ]
637
657
    takes_args = ['location?']
638
658
    encoding_type = 'replace'
639
659
 
640
660
    def run(self, location=None, remember=False, overwrite=False,
641
 
            create_prefix=False, verbose=False, use_existing_dir=False):
 
661
            create_prefix=False, verbose=False,
 
662
            use_existing_dir=False,
 
663
            directory=None):
642
664
        # FIXME: Way too big!  Put this into a function called from the
643
665
        # command.
644
 
        
645
 
        br_from = Branch.open_containing('.')[0]
 
666
        if directory is None:
 
667
            directory = '.'
 
668
        br_from = Branch.open_containing(directory)[0]
646
669
        stored_loc = br_from.get_push_location()
647
670
        if location is None:
648
671
            if stored_loc is None:
808
831
        elif len(revision) > 1:
809
832
            raise errors.BzrCommandError(
810
833
                'bzr branch --revision takes exactly 1 revision value')
811
 
        try:
812
 
            br_from = Branch.open(from_location)
813
 
        except OSError, e:
814
 
            if e.errno == errno.ENOENT:
815
 
                raise errors.BzrCommandError('Source location "%s" does not'
816
 
                                             ' exist.' % to_location)
817
 
            else:
818
 
                raise
 
834
 
 
835
        br_from = Branch.open(from_location)
819
836
        br_from.lock_read()
820
837
        try:
821
838
            if basis is not None:
883
900
    --basis is to speed up checking out from remote branches.  When specified, it
884
901
    uses the inventory and file contents from the basis branch in preference to the
885
902
    branch being checked out.
 
903
 
 
904
    See "help checkouts" for more information on checkouts.
886
905
    """
887
906
    takes_args = ['branch_location?', 'to_location?']
888
907
    takes_options = ['revision', # , 'basis']
1179
1198
    """
1180
1199
    takes_args = ['location?']
1181
1200
    takes_options = [
1182
 
                     RegistryOption('format',
1183
 
                            help='Specify a format for this branch. See "bzr '
1184
 
                            'help formats" for details',
1185
 
                            converter=bzrdir.format_registry.make_bzrdir,
1186
 
                            registry=bzrdir.format_registry,
1187
 
                            value_switches=True, title="Branch Format"),
1188
 
                     ]
1189
 
    def run(self, location=None, format=None):
 
1201
         RegistryOption('format',
 
1202
                help='Specify a format for this branch. '
 
1203
                'See "help formats".',
 
1204
                registry=bzrdir.format_registry,
 
1205
                converter=bzrdir.format_registry.make_bzrdir,
 
1206
                value_switches=True,
 
1207
                title="Branch Format",
 
1208
                ),
 
1209
         Option('append-revisions-only',
 
1210
                help='Never change revnos or the existing log.'
 
1211
                '  Append revisions to it only.')
 
1212
         ]
 
1213
    def run(self, location=None, format=None, append_revisions_only=False):
1190
1214
        if format is None:
1191
1215
            format = bzrdir.format_registry.make_bzrdir('default')
1192
1216
        if location is None:
1209
1233
            existing_bzrdir = bzrdir.BzrDir.open(location)
1210
1234
        except errors.NotBranchError:
1211
1235
            # really a NotBzrDir error...
1212
 
            bzrdir.BzrDir.create_branch_convenience(location, format=format)
 
1236
            branch = bzrdir.BzrDir.create_branch_convenience(location,
 
1237
                                                             format=format)
1213
1238
        else:
1214
1239
            from bzrlib.transport.local import LocalTransport
1215
1240
            if existing_bzrdir.has_branch():
1218
1243
                        raise errors.BranchExistsWithoutWorkingTree(location)
1219
1244
                raise errors.AlreadyBranchError(location)
1220
1245
            else:
1221
 
                existing_bzrdir.create_branch()
 
1246
                branch = existing_bzrdir.create_branch()
1222
1247
                existing_bzrdir.create_workingtree()
 
1248
        if append_revisions_only:
 
1249
            try:
 
1250
                branch.set_append_revisions_only(True)
 
1251
            except errors.UpgradeRequired:
 
1252
                raise errors.BzrCommandError('This branch format cannot be set'
 
1253
                    ' to append-revisions-only.  Try --experimental-branch6')
1223
1254
 
1224
1255
 
1225
1256
class cmd_init_repository(Command):
1236
1267
        cd trunk-checkout
1237
1268
        (add files here)
1238
1269
    """
1239
 
    takes_args = ["location"] 
 
1270
    takes_args = ["location"]
1240
1271
    takes_options = [RegistryOption('format',
1241
1272
                            help='Specify a format for this repository. See'
1242
1273
                                 ' "bzr help formats" for details',
1399
1430
 
1400
1431
 
1401
1432
class cmd_modified(Command):
1402
 
    """List files modified in working tree."""
 
1433
    """List files modified in working tree.
 
1434
 
 
1435
    See also: "bzr status".
 
1436
    """
 
1437
 
1403
1438
    hidden = True
 
1439
 
1404
1440
    @display_command
1405
1441
    def run(self):
1406
1442
        tree = WorkingTree.open_containing(u'.')[0]
1410
1446
 
1411
1447
 
1412
1448
class cmd_added(Command):
1413
 
    """List files added in working tree."""
 
1449
    """List files added in working tree.
 
1450
 
 
1451
    See also: "bzr status".
 
1452
    """
 
1453
 
1414
1454
    hidden = True
 
1455
 
1415
1456
    @display_command
1416
1457
    def run(self):
1417
1458
        wt = WorkingTree.open_containing(u'.')[0]
1492
1533
        if location:
1493
1534
            # find the file id to log:
1494
1535
 
1495
 
            dir, fp = bzrdir.BzrDir.open_containing(location)
1496
 
            b = dir.open_branch()
 
1536
            tree, b, fp = bzrdir.BzrDir.open_containing_tree_or_branch(
 
1537
                location)
1497
1538
            if fp != '':
1498
 
                try:
1499
 
                    # might be a tree:
1500
 
                    inv = dir.open_workingtree().inventory
1501
 
                except (errors.NotBranchError, errors.NotLocalUrl):
1502
 
                    # either no tree, or is remote.
1503
 
                    inv = b.basis_tree().inventory
 
1539
                if tree is None:
 
1540
                    tree = b.basis_tree()
 
1541
                inv = tree.inventory
1504
1542
                file_id = inv.path2id(fp)
1505
1543
                if file_id is None:
1506
1544
                    raise errors.BzrCommandError(
1517
1555
            dir, relpath = bzrdir.BzrDir.open_containing(location)
1518
1556
            b = dir.open_branch()
1519
1557
 
1520
 
        if revision is None:
1521
 
            rev1 = None
1522
 
            rev2 = None
1523
 
        elif len(revision) == 1:
1524
 
            rev1 = rev2 = revision[0].in_history(b).revno
1525
 
        elif len(revision) == 2:
1526
 
            if revision[1].get_branch() != revision[0].get_branch():
1527
 
                # b is taken from revision[0].get_branch(), and
1528
 
                # show_log will use its revision_history. Having
1529
 
                # different branches will lead to weird behaviors.
 
1558
        b.lock_read()
 
1559
        try:
 
1560
            if revision is None:
 
1561
                rev1 = None
 
1562
                rev2 = None
 
1563
            elif len(revision) == 1:
 
1564
                rev1 = rev2 = revision[0].in_history(b).revno
 
1565
            elif len(revision) == 2:
 
1566
                if revision[1].get_branch() != revision[0].get_branch():
 
1567
                    # b is taken from revision[0].get_branch(), and
 
1568
                    # show_log will use its revision_history. Having
 
1569
                    # different branches will lead to weird behaviors.
 
1570
                    raise errors.BzrCommandError(
 
1571
                        "Log doesn't accept two revisions in different"
 
1572
                        " branches.")
 
1573
                if revision[0].spec is None:
 
1574
                    # missing begin-range means first revision
 
1575
                    rev1 = 1
 
1576
                else:
 
1577
                    rev1 = revision[0].in_history(b).revno
 
1578
 
 
1579
                if revision[1].spec is None:
 
1580
                    # missing end-range means last known revision
 
1581
                    rev2 = b.revno()
 
1582
                else:
 
1583
                    rev2 = revision[1].in_history(b).revno
 
1584
            else:
1530
1585
                raise errors.BzrCommandError(
1531
 
                    "Log doesn't accept two revisions in different branches.")
1532
 
            if revision[0].spec is None:
1533
 
                # missing begin-range means first revision
1534
 
                rev1 = 1
1535
 
            else:
1536
 
                rev1 = revision[0].in_history(b).revno
1537
 
 
1538
 
            if revision[1].spec is None:
1539
 
                # missing end-range means last known revision
1540
 
                rev2 = b.revno()
1541
 
            else:
1542
 
                rev2 = revision[1].in_history(b).revno
1543
 
        else:
1544
 
            raise errors.BzrCommandError('bzr log --revision takes one or two values.')
1545
 
 
1546
 
        # By this point, the revision numbers are converted to the +ve
1547
 
        # form if they were supplied in the -ve form, so we can do
1548
 
        # this comparison in relative safety
1549
 
        if rev1 > rev2:
1550
 
            (rev2, rev1) = (rev1, rev2)
1551
 
 
1552
 
        if log_format is None:
1553
 
            log_format = log.log_formatter_registry.get_default(b)
1554
 
 
1555
 
        lf = log_format(show_ids=show_ids, to_file=self.outf,
1556
 
                        show_timezone=timezone)
1557
 
 
1558
 
        show_log(b,
1559
 
                 lf,
1560
 
                 file_id,
1561
 
                 verbose=verbose,
1562
 
                 direction=direction,
1563
 
                 start_revision=rev1,
1564
 
                 end_revision=rev2,
1565
 
                 search=message)
 
1586
                    'bzr log --revision takes one or two values.')
 
1587
 
 
1588
            # By this point, the revision numbers are converted to the +ve
 
1589
            # form if they were supplied in the -ve form, so we can do
 
1590
            # this comparison in relative safety
 
1591
            if rev1 > rev2:
 
1592
                (rev2, rev1) = (rev1, rev2)
 
1593
 
 
1594
            if log_format is None:
 
1595
                log_format = log.log_formatter_registry.get_default(b)
 
1596
 
 
1597
            lf = log_format(show_ids=show_ids, to_file=self.outf,
 
1598
                            show_timezone=timezone)
 
1599
 
 
1600
            show_log(b,
 
1601
                     lf,
 
1602
                     file_id,
 
1603
                     verbose=verbose,
 
1604
                     direction=direction,
 
1605
                     start_revision=rev1,
 
1606
                     end_revision=rev2,
 
1607
                     search=message)
 
1608
        finally:
 
1609
            b.unlock()
1566
1610
 
1567
1611
 
1568
1612
def get_log_format(long=False, short=False, line=False, default='long'):
1683
1727
 
1684
1728
 
1685
1729
class cmd_unknowns(Command):
1686
 
    """List unknown files."""
 
1730
    """List unknown files.
 
1731
 
 
1732
    See also: "bzr ls --unknown".
 
1733
    """
 
1734
 
 
1735
    hidden = True
 
1736
 
1687
1737
    @display_command
1688
1738
    def run(self):
1689
1739
        for f in WorkingTree.open_containing(u'.')[0].unknowns():
2335
2385
    default, use --remember. The value will only be saved if the remote
2336
2386
    location can be accessed.
2337
2387
 
 
2388
    The results of the merge are placed into the destination working
 
2389
    directory, where they can be reviewed (with bzr diff), tested, and then
 
2390
    committed to record the result of the merge.
 
2391
 
2338
2392
    Examples:
2339
2393
 
2340
2394
    To merge the latest revision from bzr.dev
2353
2407
    """
2354
2408
    takes_args = ['branch?']
2355
2409
    takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
2356
 
                     Option('show-base', help="Show base revision text in "
2357
 
                            "conflicts"),
2358
 
                     Option('uncommitted', help='Apply uncommitted changes'
2359
 
                            ' from a working copy, instead of branch changes'),
2360
 
                     Option('pull', help='If the destination is already'
2361
 
                             ' completely merged into the source, pull from the'
2362
 
                             ' source rather than merging. When this happens,'
2363
 
                             ' you do not need to commit the result.'),
2364
 
                     ]
 
2410
        Option('show-base', help="Show base revision text in "
 
2411
               "conflicts"),
 
2412
        Option('uncommitted', help='Apply uncommitted changes'
 
2413
               ' from a working copy, instead of branch changes'),
 
2414
        Option('pull', help='If the destination is already'
 
2415
                ' completely merged into the source, pull from the'
 
2416
                ' source rather than merging. When this happens,'
 
2417
                ' you do not need to commit the result.'),
 
2418
        Option('directory',
 
2419
            help='branch to merge into, '
 
2420
                 'rather than the one containing the working directory',
 
2421
            short_name='d',
 
2422
            type=unicode,
 
2423
            ),
 
2424
    ]
2365
2425
 
2366
2426
    def run(self, branch=None, revision=None, force=False, merge_type=None,
2367
 
            show_base=False, reprocess=False, remember=False, 
2368
 
            uncommitted=False, pull=False):
 
2427
            show_base=False, reprocess=False, remember=False,
 
2428
            uncommitted=False, pull=False,
 
2429
            directory=None,
 
2430
            ):
2369
2431
        if merge_type is None:
2370
2432
            merge_type = _mod_merge.Merge3Merger
2371
2433
 
2372
 
        tree = WorkingTree.open_containing(u'.')[0]
 
2434
        if directory is None: directory = u'.'
 
2435
        tree = WorkingTree.open_containing(directory)[0]
 
2436
        change_reporter = delta.ChangeReporter(tree.inventory)
2373
2437
 
2374
2438
        if branch is not None:
2375
2439
            try:
2378
2442
                pass # Continue on considering this url a Branch
2379
2443
            else:
2380
2444
                conflicts = merge_bundle(reader, tree, not force, merge_type,
2381
 
                                            reprocess, show_base)
 
2445
                                         reprocess, show_base, change_reporter)
2382
2446
                if conflicts == 0:
2383
2447
                    return 0
2384
2448
                else:
2437
2501
                    reprocess=reprocess,
2438
2502
                    show_base=show_base,
2439
2503
                    pull=pull,
2440
 
                    pb=pb, file_list=interesting_files)
 
2504
                    this_dir=directory,
 
2505
                    pb=pb, file_list=interesting_files,
 
2506
                    change_reporter=change_reporter)
2441
2507
            finally:
2442
2508
                pb.finished()
2443
2509
            if conflict_count != 0:
2883
2949
 
2884
2950
 
2885
2951
class cmd_bind(Command):
2886
 
    """Bind the current branch to a master branch.
2887
 
 
2888
 
    After binding, commits must succeed on the master branch
2889
 
    before they are executed on the local one.
 
2952
    """Convert the current branch into a checkout of the supplied branch.
 
2953
 
 
2954
    Once converted into a checkout, commits must succeed on the master branch
 
2955
    before they will be applied to the local branch.
 
2956
 
 
2957
    See "help checkouts" for more information on checkouts.
2890
2958
    """
2891
2959
 
2892
 
    takes_args = ['location']
 
2960
    takes_args = ['location?']
2893
2961
    takes_options = []
2894
2962
 
2895
2963
    def run(self, location=None):
2896
2964
        b, relpath = Branch.open_containing(u'.')
 
2965
        if location is None:
 
2966
            try:
 
2967
                location = b.get_old_bound_location()
 
2968
            except errors.UpgradeRequired:
 
2969
                raise errors.BzrCommandError('No location supplied.  '
 
2970
                    'This format does not remember old locations.')
 
2971
            else:
 
2972
                if location is None:
 
2973
                    raise errors.BzrCommandError('No location supplied and no '
 
2974
                        'previous location known')
2897
2975
        b_other = Branch.open(location)
2898
2976
        try:
2899
2977
            b.bind(b_other)
2903
2981
 
2904
2982
 
2905
2983
class cmd_unbind(Command):
2906
 
    """Unbind the current branch from its master branch.
2907
 
 
2908
 
    After unbinding, the local branch is considered independent.
2909
 
    All subsequent commits will be local.
 
2984
    """Convert the current checkout into a regular branch.
 
2985
 
 
2986
    After unbinding, the local branch is considered independent and subsequent
 
2987
    commits will be local only.
 
2988
 
 
2989
    See "help checkouts" for more information on checkouts.
2910
2990
    """
2911
2991
 
2912
2992
    takes_args = []
3136
3216
                  merge_type=None,
3137
3217
                  file_list=None, show_base=False, reprocess=False,
3138
3218
                  pull=False,
3139
 
                  pb=DummyProgress()):
 
3219
                  pb=DummyProgress(),
 
3220
                  change_reporter=None):
3140
3221
    """Merge changes into a tree.
3141
3222
 
3142
3223
    base_revision
3180
3261
        raise errors.BzrCommandError("Cannot do conflict reduction and show base.")
3181
3262
    try:
3182
3263
        merger = _mod_merge.Merger(this_tree.branch, this_tree=this_tree,
3183
 
                                   pb=pb)
 
3264
                                   pb=pb, change_reporter=change_reporter)
3184
3265
        merger.pp = ProgressPhase("Merge phase", 5, pb)
3185
3266
        merger.pp.next_phase()
3186
3267
        merger.check_basis(check_clean)