/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: John Arbash Meinel
  • Date: 2007-02-13 20:33:57 UTC
  • mfrom: (2283 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2294.
  • Revision ID: john@arbash-meinel.com-20070213203357-b7yg41mi9sk6cqd0
[merge] bzr.dev 2283
resolve conflicts in moved repository formats
small issue with osutils.contains_whitespace()

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
30
30
    branch,
31
31
    bundle,
32
32
    bzrdir,
 
33
    delta,
33
34
    config,
34
35
    errors,
35
36
    ignores,
37
38
    merge as _mod_merge,
38
39
    osutils,
39
40
    repository,
 
41
    symbol_versioning,
40
42
    transport,
41
43
    tree as _mod_tree,
42
44
    ui,
93
95
    return tree, new_list
94
96
 
95
97
 
 
98
@symbol_versioning.deprecated_function(symbol_versioning.zero_fifteen)
96
99
def get_format_type(typestring):
97
100
    """Parse and return a format specifier."""
98
101
    # Have to use BzrDirMetaFormat1 directly, so that
118
121
    This reports on versioned and unknown files, reporting them
119
122
    grouped by state.  Possible states are:
120
123
 
121
 
    added / A
 
124
    added
122
125
        Versioned in the working copy but not in the previous revision.
123
126
 
124
 
    removed / D
 
127
    removed
125
128
        Versioned in the previous revision but removed or deleted
126
129
        in the working copy.
127
130
 
128
 
    renamed / R
 
131
    renamed
129
132
        Path of this file changed from the previous revision;
130
133
        the text may also have changed.  This includes files whose
131
134
        parent directory was renamed.
132
135
 
133
 
    modified / M
 
136
    modified
134
137
        Text has changed since the previous revision.
135
138
 
136
 
    unknown / ?
 
139
    kind changed
 
140
        File kind has been changed (e.g. from file to directory).
 
141
 
 
142
    unknown
137
143
        Not versioned and not matching an ignore pattern.
138
144
 
139
145
    To see ignored files use 'bzr ignored'.  For details in the
140
146
    changes to file texts, use 'bzr diff'.
141
147
    
142
 
    --short gives a one character status flag for each item, similar
143
 
    to the SVN's status command.
 
148
    --short gives a status flags for each item, similar to the SVN's status
 
149
    command.
 
150
 
 
151
    Column 1: versioning / renames
 
152
      + File versioned
 
153
      - File unversioned
 
154
      R File renamed
 
155
      ? File unknown
 
156
      C File has conflicts
 
157
      P Entry for a pending merge (not a file)
 
158
 
 
159
    Column 2: Contents
 
160
      N File created
 
161
      D File deleted
 
162
      K File kind changed
 
163
      M File modified
 
164
 
 
165
    Column 3: Execute
 
166
      * The execute bit was changed
144
167
 
145
168
    If no arguments are specified, the status of the entire working
146
169
    directory is shown.  Otherwise, only the status of the specified
393
416
 
394
417
    It is also possible to restrict the list of files to a specific
395
418
    set. For example: bzr inventory --show-ids this/file
 
419
 
 
420
    See also: bzr ls
396
421
    """
397
422
 
 
423
    hidden = True
 
424
 
398
425
    takes_options = ['revision', 'show-ids', 'kind']
 
426
 
399
427
    takes_args = ['file*']
400
428
 
401
429
    @display_command
602
630
    """
603
631
 
604
632
    takes_options = ['remember', 'overwrite', 'verbose',
605
 
                     Option('create-prefix', 
 
633
                     Option('create-prefix',
606
634
                            help='Create the path leading up to the branch '
607
 
                                 'if it does not already exist')]
 
635
                                 'if it does not already exist'),
 
636
                     Option('use-existing-dir',
 
637
                            help='By default push will fail if the target'
 
638
                                 ' directory exists, but does not already'
 
639
                                 ' have a control directory. This flag will'
 
640
                                 ' allow push to proceed.'),
 
641
                     ]
608
642
    takes_args = ['location?']
609
643
    encoding_type = 'replace'
610
644
 
611
645
    def run(self, location=None, remember=False, overwrite=False,
612
 
            create_prefix=False, verbose=False):
 
646
            create_prefix=False, verbose=False, use_existing_dir=False):
613
647
        # FIXME: Way too big!  Put this into a function called from the
614
648
        # command.
615
649
        
628
662
        location_url = to_transport.base
629
663
 
630
664
        old_rh = []
 
665
        count = 0
 
666
 
 
667
        br_to = repository_to = dir_to = None
631
668
        try:
632
 
            dir_to = bzrdir.BzrDir.open(location_url)
633
 
            br_to = dir_to.open_branch()
 
669
            dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
634
670
        except errors.NotBranchError:
635
 
            # create a branch.
636
 
            to_transport = to_transport.clone('..')
637
 
            if not create_prefix:
 
671
            pass # Didn't find anything
 
672
        else:
 
673
            # If we can open a branch, use its direct repository, otherwise see
 
674
            # if there is a repository without a branch.
 
675
            try:
 
676
                br_to = dir_to.open_branch()
 
677
            except errors.NotBranchError:
 
678
                # Didn't find a branch, can we find a repository?
638
679
                try:
639
 
                    relurl = to_transport.relpath(location_url)
640
 
                    mutter('creating directory %s => %s', location_url, relurl)
641
 
                    to_transport.mkdir(relurl)
642
 
                except errors.NoSuchFile:
643
 
                    raise errors.BzrCommandError("Parent directory of %s "
644
 
                                                 "does not exist." % location)
 
680
                    repository_to = dir_to.find_repository()
 
681
                except errors.NoRepositoryPresent:
 
682
                    pass
645
683
            else:
646
 
                current = to_transport.base
647
 
                needed = [(to_transport, to_transport.relpath(location_url))]
 
684
                # Found a branch, so we must have found a repository
 
685
                repository_to = br_to.repository
 
686
 
 
687
        old_rh = []
 
688
        if dir_to is None:
 
689
            # XXX: Refactor the create_prefix/no_create_prefix code into a
 
690
            #      common helper function
 
691
            try:
 
692
                to_transport.mkdir('.')
 
693
            except errors.FileExists:
 
694
                if not use_existing_dir:
 
695
                    raise errors.BzrCommandError("Target directory %s"
 
696
                         " already exists, but does not have a valid .bzr"
 
697
                         " directory. Supply --use-existing-dir to push"
 
698
                         " there anyway." % location)
 
699
            except errors.NoSuchFile:
 
700
                if not create_prefix:
 
701
                    raise errors.BzrCommandError("Parent directory of %s"
 
702
                        " does not exist."
 
703
                        "\nYou may supply --create-prefix to create all"
 
704
                        " leading parent directories."
 
705
                        % location)
 
706
 
 
707
                cur_transport = to_transport
 
708
                needed = [cur_transport]
 
709
                # Recurse upwards until we can create a directory successfully
 
710
                while True:
 
711
                    new_transport = cur_transport.clone('..')
 
712
                    if new_transport.base == cur_transport.base:
 
713
                        raise errors.BzrCommandError("Failed to create path"
 
714
                                                     " prefix for %s."
 
715
                                                     % location)
 
716
                    try:
 
717
                        new_transport.mkdir('.')
 
718
                    except errors.NoSuchFile:
 
719
                        needed.append(new_transport)
 
720
                        cur_transport = new_transport
 
721
                    else:
 
722
                        break
 
723
 
 
724
                # Now we only need to create child directories
648
725
                while needed:
649
 
                    try:
650
 
                        to_transport, relpath = needed[-1]
651
 
                        to_transport.mkdir(relpath)
652
 
                        needed.pop()
653
 
                    except errors.NoSuchFile:
654
 
                        new_transport = to_transport.clone('..')
655
 
                        needed.append((new_transport,
656
 
                                       new_transport.relpath(to_transport.base)))
657
 
                        if new_transport.base == to_transport.base:
658
 
                            raise errors.BzrCommandError("Could not create "
659
 
                                                         "path prefix.")
 
726
                    cur_transport = needed.pop()
 
727
                    cur_transport.mkdir('.')
 
728
            
 
729
            # Now the target directory exists, but doesn't have a .bzr
 
730
            # directory. So we need to create it, along with any work to create
 
731
            # all of the dependent branches, etc.
660
732
            dir_to = br_from.bzrdir.clone(location_url,
661
733
                revision_id=br_from.last_revision())
662
734
            br_to = dir_to.open_branch()
 
735
            count = br_to.last_revision_info()[0]
 
736
            # We successfully created the target, remember it
 
737
            if br_from.get_push_location() is None or remember:
 
738
                br_from.set_push_location(br_to.base)
 
739
        elif repository_to is None:
 
740
            # we have a bzrdir but no branch or repository
 
741
            # XXX: Figure out what to do other than complain.
 
742
            raise errors.BzrCommandError("At %s you have a valid .bzr control"
 
743
                " directory, but not a branch or repository. This is an"
 
744
                " unsupported configuration. Please move the target directory"
 
745
                " out of the way and try again."
 
746
                % location)
 
747
        elif br_to is None:
 
748
            # We have a repository but no branch, copy the revisions, and then
 
749
            # create a branch.
 
750
            last_revision_id = br_from.last_revision()
 
751
            repository_to.fetch(br_from.repository,
 
752
                                revision_id=last_revision_id)
 
753
            br_to = br_from.clone(dir_to, revision_id=last_revision_id)
663
754
            count = len(br_to.revision_history())
664
 
            # We successfully created the target, remember it
665
755
            if br_from.get_push_location() is None or remember:
666
756
                br_from.set_push_location(br_to.base)
667
 
        else:
 
757
        else: # We have a valid to branch
668
758
            # We were able to connect to the remote location, so remember it
669
759
            # we don't need to successfully push because of possible divergence.
670
760
            if br_from.get_push_location() is None or remember:
676
766
                except errors.NotLocalUrl:
677
767
                    warning('This transport does not update the working '
678
768
                            'tree of: %s' % (br_to.base,))
679
 
                    count = br_to.pull(br_from, overwrite)
 
769
                    count = br_from.push(br_to, overwrite)
680
770
                except errors.NoWorkingTree:
681
 
                    count = br_to.pull(br_from, overwrite)
 
771
                    count = br_from.push(br_to, overwrite)
682
772
                else:
683
 
                    count = tree_to.pull(br_from, overwrite)
 
773
                    tree_to.lock_write()
 
774
                    try:
 
775
                        count = br_from.push(tree_to.branch, overwrite)
 
776
                        tree_to.update()
 
777
                    finally:
 
778
                        tree_to.unlock()
684
779
            except errors.DivergedBranches:
685
780
                raise errors.BzrCommandError('These branches have diverged.'
686
781
                                        '  Try using "merge" and then "push".')
793
888
    --basis is to speed up checking out from remote branches.  When specified, it
794
889
    uses the inventory and file contents from the basis branch in preference to the
795
890
    branch being checked out.
 
891
 
 
892
    See "help checkouts" for more information on checkouts.
796
893
    """
797
894
    takes_args = ['branch_location?', 'to_location?']
798
895
    takes_options = ['revision', # , 'basis']
1089
1186
    """
1090
1187
    takes_args = ['location?']
1091
1188
    takes_options = [
1092
 
                     RegistryOption('format',
1093
 
                            help='Specify a format for this branch. Current'
1094
 
                                 ' formats are: default, knit, metaweave and'
1095
 
                                 ' weave. Default is knit; metaweave and'
1096
 
                                 ' weave are deprecated',
1097
 
                            registry=bzrdir.format_registry,
1098
 
                            converter=get_format_type,
1099
 
                            value_switches=True),
1100
 
                     ]
 
1189
         RegistryOption('format',
 
1190
                help='Specify a format for this branch. '
 
1191
                'See "help formats".',
 
1192
                registry=bzrdir.format_registry,
 
1193
                converter=bzrdir.format_registry.make_bzrdir,
 
1194
                value_switches=True,
 
1195
                title="Branch Format",
 
1196
                ),
 
1197
         ]
1101
1198
    def run(self, location=None, format=None):
1102
1199
        if format is None:
1103
 
            format = get_format_type('default')
 
1200
            format = bzrdir.format_registry.make_bzrdir('default')
1104
1201
        if location is None:
1105
1202
            location = u'.'
1106
1203
 
1148
1245
        cd trunk-checkout
1149
1246
        (add files here)
1150
1247
    """
1151
 
    takes_args = ["location"] 
 
1248
    takes_args = ["location"]
1152
1249
    takes_options = [RegistryOption('format',
1153
 
                            help='Specify a format for this repository.'
1154
 
                                 ' Current formats are: default, knit,'
1155
 
                                 ' metaweave and weave. Default is knit;'
1156
 
                                 ' metaweave and weave are deprecated',
 
1250
                            help='Specify a format for this repository. See'
 
1251
                                 ' "bzr help formats" for details',
1157
1252
                            registry=bzrdir.format_registry,
1158
 
                            converter=get_format_type,
1159
 
                            value_switches=True),
 
1253
                            converter=bzrdir.format_registry.make_bzrdir,
 
1254
                            value_switches=True, title='Repository format'),
1160
1255
                     Option('trees',
1161
1256
                             help='Allows branches in repository to have'
1162
1257
                             ' a working tree')]
1163
1258
    aliases = ["init-repo"]
1164
1259
    def run(self, location, format=None, trees=False):
1165
1260
        if format is None:
1166
 
            format = get_format_type('default')
 
1261
            format = bzrdir.format_registry.make_bzrdir('default')
1167
1262
 
1168
1263
        if location is None:
1169
1264
            location = '.'
1313
1408
 
1314
1409
 
1315
1410
class cmd_modified(Command):
1316
 
    """List files modified in working tree."""
 
1411
    """List files modified in working tree.
 
1412
 
 
1413
    See also: "bzr status".
 
1414
    """
 
1415
 
1317
1416
    hidden = True
 
1417
 
1318
1418
    @display_command
1319
1419
    def run(self):
1320
1420
        tree = WorkingTree.open_containing(u'.')[0]
1324
1424
 
1325
1425
 
1326
1426
class cmd_added(Command):
1327
 
    """List files added in working tree."""
 
1427
    """List files added in working tree.
 
1428
 
 
1429
    See also: "bzr status".
 
1430
    """
 
1431
 
1328
1432
    hidden = True
 
1433
 
1329
1434
    @display_command
1330
1435
    def run(self):
1331
1436
        wt = WorkingTree.open_containing(u'.')[0]
1381
1486
                             help='show files changed in each revision'),
1382
1487
                     'show-ids', 'revision',
1383
1488
                     'log-format',
1384
 
                     'line', 'long', 
1385
1489
                     Option('message',
1386
1490
                            short_name='m',
1387
1491
                            help='show revisions whose message matches this regexp',
1388
1492
                            type=str),
1389
 
                     'short',
1390
1493
                     ]
1391
1494
    encoding_type = 'replace'
1392
1495
 
1397
1500
            forward=False,
1398
1501
            revision=None,
1399
1502
            log_format=None,
1400
 
            message=None,
1401
 
            long=False,
1402
 
            short=False,
1403
 
            line=False):
1404
 
        from bzrlib.log import log_formatter, show_log
 
1503
            message=None):
 
1504
        from bzrlib.log import show_log
1405
1505
        assert message is None or isinstance(message, basestring), \
1406
1506
            "invalid message argument %r" % message
1407
1507
        direction = (forward and 'forward') or 'reverse'
1411
1511
        if location:
1412
1512
            # find the file id to log:
1413
1513
 
1414
 
            dir, fp = bzrdir.BzrDir.open_containing(location)
1415
 
            b = dir.open_branch()
 
1514
            tree, b, fp = bzrdir.BzrDir.open_containing_tree_or_branch(
 
1515
                location)
1416
1516
            if fp != '':
1417
 
                try:
1418
 
                    # might be a tree:
1419
 
                    inv = dir.open_workingtree().inventory
1420
 
                except (errors.NotBranchError, errors.NotLocalUrl):
1421
 
                    # either no tree, or is remote.
1422
 
                    inv = b.basis_tree().inventory
 
1517
                if tree is None:
 
1518
                    tree = b.basis_tree()
 
1519
                inv = tree.inventory
1423
1520
                file_id = inv.path2id(fp)
1424
1521
                if file_id is None:
1425
1522
                    raise errors.BzrCommandError(
1468
1565
        if rev1 > rev2:
1469
1566
            (rev2, rev1) = (rev1, rev2)
1470
1567
 
1471
 
        if (log_format is None):
1472
 
            default = b.get_config().log_format()
1473
 
            log_format = get_log_format(long=long, short=short, line=line, 
1474
 
                                        default=default)
1475
 
        lf = log_formatter(log_format,
1476
 
                           show_ids=show_ids,
1477
 
                           to_file=self.outf,
1478
 
                           show_timezone=timezone)
 
1568
        if log_format is None:
 
1569
            log_format = log.log_formatter_registry.get_default(b)
 
1570
 
 
1571
        lf = log_format(show_ids=show_ids, to_file=self.outf,
 
1572
                        show_timezone=timezone)
1479
1573
 
1480
1574
        show_log(b,
1481
1575
                 lf,
1605
1699
 
1606
1700
 
1607
1701
class cmd_unknowns(Command):
1608
 
    """List unknown files."""
 
1702
    """List unknown files.
 
1703
 
 
1704
    See also: "bzr ls --unknown".
 
1705
    """
 
1706
 
 
1707
    hidden = True
 
1708
 
1609
1709
    @display_command
1610
1710
    def run(self):
1611
1711
        for f in WorkingTree.open_containing(u'.')[0].unknowns():
1982
2082
    takes_args = ['url?']
1983
2083
    takes_options = [
1984
2084
                    RegistryOption('format',
1985
 
                        help='Upgrade to a specific format. Current formats'
1986
 
                             ' are: default, knit, metaweave and weave.'
1987
 
                             ' Default is knit; metaweave and weave are'
1988
 
                             ' deprecated',
 
2085
                        help='Upgrade to a specific format.  See "bzr help'
 
2086
                             ' formats" for details',
1989
2087
                        registry=bzrdir.format_registry,
1990
 
                        converter=get_format_type,
1991
 
                        value_switches=True),
 
2088
                        converter=bzrdir.format_registry.make_bzrdir,
 
2089
                        value_switches=True, title='Branch format'),
1992
2090
                    ]
1993
2091
 
1994
2092
 
1995
2093
    def run(self, url='.', format=None):
1996
2094
        from bzrlib.upgrade import upgrade
1997
2095
        if format is None:
1998
 
            format = get_format_type('default')
 
2096
            format = bzrdir.format_registry.make_bzrdir('default')
1999
2097
        upgrade(url, format)
2000
2098
 
2001
2099
 
2223
2321
        branch1 = Branch.open_containing(branch)[0]
2224
2322
        branch2 = Branch.open_containing(other)[0]
2225
2323
 
2226
 
        history_1 = branch1.revision_history()
2227
 
        history_2 = branch2.revision_history()
2228
 
 
2229
2324
        last1 = branch1.last_revision()
2230
2325
        last2 = branch2.last_revision()
2231
2326
 
2290
2385
                             ' you do not need to commit the result.'),
2291
2386
                     ]
2292
2387
 
2293
 
    def help(self):
2294
 
        from inspect import getdoc
2295
 
        return getdoc(self) + '\n' + _mod_merge.merge_type_help()
2296
 
 
2297
2388
    def run(self, branch=None, revision=None, force=False, merge_type=None,
2298
2389
            show_base=False, reprocess=False, remember=False, 
2299
2390
            uncommitted=False, pull=False):
2427
2518
                     Option('show-base', help="Show base revision text in "
2428
2519
                            "conflicts")]
2429
2520
 
2430
 
    def help(self):
2431
 
        from inspect import getdoc
2432
 
        return getdoc(self) + '\n' + _mod_merge.merge_type_help()
2433
 
 
2434
2521
    def run(self, file_list=None, merge_type=None, show_base=False,
2435
2522
            reprocess=False):
2436
2523
        if merge_type is None:
2538
2625
        try:
2539
2626
            tree.revert(file_list, 
2540
2627
                        tree.branch.repository.revision_tree(rev_id),
2541
 
                        not no_backup, pb)
 
2628
                        not no_backup, pb, report_changes=True)
2542
2629
        finally:
2543
2630
            pb.finished()
2544
2631
 
2611
2698
                     Option('theirs-only', 
2612
2699
                            'Display changes in the remote branch only'), 
2613
2700
                     'log-format',
2614
 
                     'line',
2615
 
                     'long', 
2616
 
                     'short',
2617
2701
                     'show-ids',
2618
2702
                     'verbose'
2619
2703
                     ]
2644
2728
            try:
2645
2729
                local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
2646
2730
                if (log_format is None):
2647
 
                    default = local_branch.get_config().log_format()
2648
 
                    log_format = get_log_format(long=long, short=short, 
2649
 
                                                line=line, default=default)
2650
 
                lf = log_formatter(log_format,
2651
 
                                   to_file=self.outf,
2652
 
                                   show_ids=show_ids,
2653
 
                                   show_timezone='original')
 
2731
                    log_format = log.log_formatter_registry.get_default(
 
2732
                        local_branch)
 
2733
                lf = log_format(to_file=self.outf,
 
2734
                                show_ids=show_ids,
 
2735
                                show_timezone='original')
2654
2736
                if reverse is False:
2655
2737
                    local_extra.reverse()
2656
2738
                    remote_extra.reverse()
2823
2905
 
2824
2906
 
2825
2907
class cmd_bind(Command):
2826
 
    """Bind the current branch to a master branch.
2827
 
 
2828
 
    After binding, commits must succeed on the master branch
2829
 
    before they are executed on the local one.
 
2908
    """Convert the current branch into a checkout of the supplied branch.
 
2909
 
 
2910
    Once converted into a checkout, commits must succeed on the master branch
 
2911
    before they will be applied to the local branch.
 
2912
 
 
2913
    See "help checkouts" for more information on checkouts.
2830
2914
    """
2831
2915
 
2832
2916
    takes_args = ['location']
2843
2927
 
2844
2928
 
2845
2929
class cmd_unbind(Command):
2846
 
    """Unbind the current branch from its master branch.
2847
 
 
2848
 
    After unbinding, the local branch is considered independent.
2849
 
    All subsequent commits will be local.
 
2930
    """Convert the current checkout into a regular branch.
 
2931
 
 
2932
    After unbinding, the local branch is considered independent and subsequent
 
2933
    commits will be local only.
 
2934
 
 
2935
    See "help checkouts" for more information on checkouts.
2850
2936
    """
2851
2937
 
2852
2938
    takes_args = []