/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-09 07:16:20 UTC
  • mfrom: (2272 +trunk)
  • mto: (2255.6.1 dirstate)
  • mto: This revision was merged to the branch mainline in revision 2322.
  • Revision ID: aaron.bentley@utoronto.ca-20070209071620-gp2n7vtjyb0f2x1e
Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
602
625
    """
603
626
 
604
627
    takes_options = ['remember', 'overwrite', 'verbose',
605
 
                     Option('create-prefix', 
 
628
                     Option('create-prefix',
606
629
                            help='Create the path leading up to the branch '
607
 
                                 'if it does not already exist')]
 
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
                     ]
608
637
    takes_args = ['location?']
609
638
    encoding_type = 'replace'
610
639
 
611
640
    def run(self, location=None, remember=False, overwrite=False,
612
 
            create_prefix=False, verbose=False):
 
641
            create_prefix=False, verbose=False, use_existing_dir=False):
613
642
        # FIXME: Way too big!  Put this into a function called from the
614
643
        # command.
615
644
        
628
657
        location_url = to_transport.base
629
658
 
630
659
        old_rh = []
 
660
        count = 0
 
661
 
 
662
        br_to = repository_to = dir_to = None
631
663
        try:
632
 
            dir_to = bzrdir.BzrDir.open(location_url)
633
 
            br_to = dir_to.open_branch()
 
664
            dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
634
665
        except errors.NotBranchError:
635
 
            # create a branch.
636
 
            to_transport = to_transport.clone('..')
637
 
            if not create_prefix:
 
666
            pass # Didn't find anything
 
667
        else:
 
668
            # If we can open a branch, use its direct repository, otherwise see
 
669
            # if there is a repository without a branch.
 
670
            try:
 
671
                br_to = dir_to.open_branch()
 
672
            except errors.NotBranchError:
 
673
                # Didn't find a branch, can we find a repository?
638
674
                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)
 
675
                    repository_to = dir_to.find_repository()
 
676
                except errors.NoRepositoryPresent:
 
677
                    pass
645
678
            else:
646
 
                current = to_transport.base
647
 
                needed = [(to_transport, to_transport.relpath(location_url))]
 
679
                # Found a branch, so we must have found a repository
 
680
                repository_to = br_to.repository
 
681
 
 
682
        old_rh = []
 
683
        if dir_to is None:
 
684
            # XXX: Refactor the create_prefix/no_create_prefix code into a
 
685
            #      common helper function
 
686
            try:
 
687
                to_transport.mkdir('.')
 
688
            except errors.FileExists:
 
689
                if not use_existing_dir:
 
690
                    raise errors.BzrCommandError("Target directory %s"
 
691
                         " already exists, but does not have a valid .bzr"
 
692
                         " directory. Supply --use-existing-dir to push"
 
693
                         " there anyway." % location)
 
694
            except errors.NoSuchFile:
 
695
                if not create_prefix:
 
696
                    raise errors.BzrCommandError("Parent directory of %s"
 
697
                        " does not exist."
 
698
                        "\nYou may supply --create-prefix to create all"
 
699
                        " leading parent directories."
 
700
                        % location)
 
701
 
 
702
                cur_transport = to_transport
 
703
                needed = [cur_transport]
 
704
                # Recurse upwards until we can create a directory successfully
 
705
                while True:
 
706
                    new_transport = cur_transport.clone('..')
 
707
                    if new_transport.base == cur_transport.base:
 
708
                        raise errors.BzrCommandError("Failed to create path"
 
709
                                                     " prefix for %s."
 
710
                                                     % location)
 
711
                    try:
 
712
                        new_transport.mkdir('.')
 
713
                    except errors.NoSuchFile:
 
714
                        needed.append(new_transport)
 
715
                        cur_transport = new_transport
 
716
                    else:
 
717
                        break
 
718
 
 
719
                # Now we only need to create child directories
648
720
                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.")
 
721
                    cur_transport = needed.pop()
 
722
                    cur_transport.mkdir('.')
 
723
            
 
724
            # Now the target directory exists, but doesn't have a .bzr
 
725
            # directory. So we need to create it, along with any work to create
 
726
            # all of the dependent branches, etc.
660
727
            dir_to = br_from.bzrdir.clone(location_url,
661
728
                revision_id=br_from.last_revision())
662
729
            br_to = dir_to.open_branch()
 
730
            count = br_to.last_revision_info()[0]
 
731
            # We successfully created the target, remember it
 
732
            if br_from.get_push_location() is None or remember:
 
733
                br_from.set_push_location(br_to.base)
 
734
        elif repository_to is None:
 
735
            # we have a bzrdir but no branch or repository
 
736
            # XXX: Figure out what to do other than complain.
 
737
            raise errors.BzrCommandError("At %s you have a valid .bzr control"
 
738
                " directory, but not a branch or repository. This is an"
 
739
                " unsupported configuration. Please move the target directory"
 
740
                " out of the way and try again."
 
741
                % location)
 
742
        elif br_to is None:
 
743
            # We have a repository but no branch, copy the revisions, and then
 
744
            # create a branch.
 
745
            last_revision_id = br_from.last_revision()
 
746
            repository_to.fetch(br_from.repository,
 
747
                                revision_id=last_revision_id)
 
748
            br_to = br_from.clone(dir_to, revision_id=last_revision_id)
663
749
            count = len(br_to.revision_history())
664
 
            # We successfully created the target, remember it
665
750
            if br_from.get_push_location() is None or remember:
666
751
                br_from.set_push_location(br_to.base)
667
 
        else:
 
752
        else: # We have a valid to branch
668
753
            # We were able to connect to the remote location, so remember it
669
754
            # we don't need to successfully push because of possible divergence.
670
755
            if br_from.get_push_location() is None or remember:
676
761
                except errors.NotLocalUrl:
677
762
                    warning('This transport does not update the working '
678
763
                            'tree of: %s' % (br_to.base,))
679
 
                    count = br_to.pull(br_from, overwrite)
 
764
                    count = br_from.push(br_to, overwrite)
680
765
                except errors.NoWorkingTree:
681
 
                    count = br_to.pull(br_from, overwrite)
 
766
                    count = br_from.push(br_to, overwrite)
682
767
                else:
683
 
                    count = tree_to.pull(br_from, overwrite)
 
768
                    tree_to.lock_write()
 
769
                    try:
 
770
                        count = br_from.push(tree_to.branch, overwrite)
 
771
                        tree_to.update()
 
772
                    finally:
 
773
                        tree_to.unlock()
684
774
            except errors.DivergedBranches:
685
775
                raise errors.BzrCommandError('These branches have diverged.'
686
776
                                        '  Try using "merge" and then "push".')
1090
1180
    takes_args = ['location?']
1091
1181
    takes_options = [
1092
1182
                     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',
 
1183
                            help='Specify a format for this branch. See "bzr '
 
1184
                            'help formats" for details',
 
1185
                            converter=bzrdir.format_registry.make_bzrdir,
1097
1186
                            registry=bzrdir.format_registry,
1098
 
                            converter=get_format_type,
1099
 
                            value_switches=True),
 
1187
                            value_switches=True, title="Branch Format"),
1100
1188
                     ]
1101
1189
    def run(self, location=None, format=None):
1102
1190
        if format is None:
1103
 
            format = get_format_type('default')
 
1191
            format = bzrdir.format_registry.make_bzrdir('default')
1104
1192
        if location is None:
1105
1193
            location = u'.'
1106
1194
 
1150
1238
    """
1151
1239
    takes_args = ["location"] 
1152
1240
    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',
 
1241
                            help='Specify a format for this repository. See'
 
1242
                                 ' "bzr help formats" for details',
1157
1243
                            registry=bzrdir.format_registry,
1158
 
                            converter=get_format_type,
1159
 
                            value_switches=True),
 
1244
                            converter=bzrdir.format_registry.make_bzrdir,
 
1245
                            value_switches=True, title='Repository format'),
1160
1246
                     Option('trees',
1161
1247
                             help='Allows branches in repository to have'
1162
1248
                             ' a working tree')]
1163
1249
    aliases = ["init-repo"]
1164
1250
    def run(self, location, format=None, trees=False):
1165
1251
        if format is None:
1166
 
            format = get_format_type('default')
 
1252
            format = bzrdir.format_registry.make_bzrdir('default')
1167
1253
 
1168
1254
        if location is None:
1169
1255
            location = '.'
1381
1467
                             help='show files changed in each revision'),
1382
1468
                     'show-ids', 'revision',
1383
1469
                     'log-format',
1384
 
                     'line', 'long', 
1385
1470
                     Option('message',
1386
1471
                            short_name='m',
1387
1472
                            help='show revisions whose message matches this regexp',
1388
1473
                            type=str),
1389
 
                     'short',
1390
1474
                     ]
1391
1475
    encoding_type = 'replace'
1392
1476
 
1397
1481
            forward=False,
1398
1482
            revision=None,
1399
1483
            log_format=None,
1400
 
            message=None,
1401
 
            long=False,
1402
 
            short=False,
1403
 
            line=False):
1404
 
        from bzrlib.log import log_formatter, show_log
 
1484
            message=None):
 
1485
        from bzrlib.log import show_log
1405
1486
        assert message is None or isinstance(message, basestring), \
1406
1487
            "invalid message argument %r" % message
1407
1488
        direction = (forward and 'forward') or 'reverse'
1468
1549
        if rev1 > rev2:
1469
1550
            (rev2, rev1) = (rev1, rev2)
1470
1551
 
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)
 
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)
1479
1557
 
1480
1558
        show_log(b,
1481
1559
                 lf,
1982
2060
    takes_args = ['url?']
1983
2061
    takes_options = [
1984
2062
                    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',
 
2063
                        help='Upgrade to a specific format.  See "bzr help'
 
2064
                             ' formats" for details',
1989
2065
                        registry=bzrdir.format_registry,
1990
 
                        converter=get_format_type,
1991
 
                        value_switches=True),
 
2066
                        converter=bzrdir.format_registry.make_bzrdir,
 
2067
                        value_switches=True, title='Branch format'),
1992
2068
                    ]
1993
2069
 
1994
2070
 
1995
2071
    def run(self, url='.', format=None):
1996
2072
        from bzrlib.upgrade import upgrade
1997
2073
        if format is None:
1998
 
            format = get_format_type('default')
 
2074
            format = bzrdir.format_registry.make_bzrdir('default')
1999
2075
        upgrade(url, format)
2000
2076
 
2001
2077
 
2223
2299
        branch1 = Branch.open_containing(branch)[0]
2224
2300
        branch2 = Branch.open_containing(other)[0]
2225
2301
 
2226
 
        history_1 = branch1.revision_history()
2227
 
        history_2 = branch2.revision_history()
2228
 
 
2229
2302
        last1 = branch1.last_revision()
2230
2303
        last2 = branch2.last_revision()
2231
2304
 
2290
2363
                             ' you do not need to commit the result.'),
2291
2364
                     ]
2292
2365
 
2293
 
    def help(self):
2294
 
        from inspect import getdoc
2295
 
        return getdoc(self) + '\n' + _mod_merge.merge_type_help()
2296
 
 
2297
2366
    def run(self, branch=None, revision=None, force=False, merge_type=None,
2298
2367
            show_base=False, reprocess=False, remember=False, 
2299
2368
            uncommitted=False, pull=False):
2427
2496
                     Option('show-base', help="Show base revision text in "
2428
2497
                            "conflicts")]
2429
2498
 
2430
 
    def help(self):
2431
 
        from inspect import getdoc
2432
 
        return getdoc(self) + '\n' + _mod_merge.merge_type_help()
2433
 
 
2434
2499
    def run(self, file_list=None, merge_type=None, show_base=False,
2435
2500
            reprocess=False):
2436
2501
        if merge_type is None:
2538
2603
        try:
2539
2604
            tree.revert(file_list, 
2540
2605
                        tree.branch.repository.revision_tree(rev_id),
2541
 
                        not no_backup, pb)
 
2606
                        not no_backup, pb, report_changes=True)
2542
2607
        finally:
2543
2608
            pb.finished()
2544
2609
 
2611
2676
                     Option('theirs-only', 
2612
2677
                            'Display changes in the remote branch only'), 
2613
2678
                     'log-format',
2614
 
                     'line',
2615
 
                     'long', 
2616
 
                     'short',
2617
2679
                     'show-ids',
2618
2680
                     'verbose'
2619
2681
                     ]
2644
2706
            try:
2645
2707
                local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
2646
2708
                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')
 
2709
                    log_format = log.log_formatter_registry.get_default(
 
2710
                        local_branch)
 
2711
                lf = log_format(to_file=self.outf,
 
2712
                                show_ids=show_ids,
 
2713
                                show_timezone='original')
2654
2714
                if reverse is False:
2655
2715
                    local_extra.reverse()
2656
2716
                    remote_extra.reverse()