/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: 2008-09-05 03:11:40 UTC
  • mfrom: (3691 +trunk)
  • mto: (3697.7.4 1.7)
  • mto: This revision was merged to the branch mainline in revision 3748.
  • Revision ID: john@arbash-meinel.com-20080905031140-hj0adlcf30l7i99v
Merge in bzr.dev 3691

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
    if file_list is None or len(file_list) == 0:
88
88
        return WorkingTree.open_containing(default_branch)[0], file_list
89
89
    tree = WorkingTree.open_containing(osutils.realpath(file_list[0]))[0]
 
90
    return tree, safe_relpath_files(tree, file_list)
 
91
 
 
92
 
 
93
def safe_relpath_files(tree, file_list):
 
94
    """Convert file_list into a list of relpaths in tree.
 
95
 
 
96
    :param tree: A tree to operate on.
 
97
    :param file_list: A list of user provided paths or None.
 
98
    :return: A list of relative paths.
 
99
    :raises errors.PathNotChild: When a provided path is in a different tree
 
100
        than tree.
 
101
    """
 
102
    if file_list is None:
 
103
        return None
90
104
    new_list = []
91
105
    for filename in file_list:
92
106
        try:
93
107
            new_list.append(tree.relpath(osutils.dereference_path(filename)))
94
108
        except errors.PathNotChild:
95
109
            raise errors.FileInWrongBranch(tree.branch, filename)
96
 
    return tree, new_list
 
110
    return new_list
97
111
 
98
112
 
99
113
# TODO: Make sure no commands unconditionally use the working directory as a
170
184
            raise errors.BzrCommandError('bzr status --revision takes exactly'
171
185
                                         ' one or two revision specifiers')
172
186
 
173
 
        tree, file_list = tree_files(file_list)
174
 
            
 
187
        tree, relfile_list = tree_files(file_list)
 
188
        # Avoid asking for specific files when that is not needed.
 
189
        if relfile_list == ['']:
 
190
            relfile_list = None
 
191
            # Don't disable pending merges for full trees other than '.'.
 
192
            if file_list == ['.']:
 
193
                no_pending = True
 
194
        # A specific path within a tree was given.
 
195
        elif relfile_list is not None:
 
196
            no_pending = True
175
197
        show_tree_status(tree, show_ids=show_ids,
176
 
                         specific_files=file_list, revision=revision,
 
198
                         specific_files=relfile_list, revision=revision,
177
199
                         to_file=self.outf, short=short, versioned=versioned,
178
 
                         show_pending=not no_pending)
 
200
                         show_pending=(not no_pending))
179
201
 
180
202
 
181
203
class cmd_cat_revision(Command):
204
226
        # TODO: jam 20060112 should cat-revision always output utf-8?
205
227
        if revision_id is not None:
206
228
            revision_id = osutils.safe_revision_id(revision_id, warn=False)
207
 
            self.outf.write(b.repository.get_revision_xml(revision_id).decode('utf-8'))
 
229
            try:
 
230
                self.outf.write(b.repository.get_revision_xml(revision_id).decode('utf-8'))
 
231
            except errors.NoSuchRevision:
 
232
                msg = "The repository %s contains no revision %s." % (b.repository.base,
 
233
                    revision_id)
 
234
                raise errors.BzrCommandError(msg)
208
235
        elif revision is not None:
209
236
            for rev in revision:
210
237
                if rev is None:
630
657
                display_url = urlutils.unescape_for_display(stored_loc,
631
658
                        self.outf.encoding)
632
659
                if not is_quiet():
633
 
                    self.outf.write("Using saved location: %s\n" % display_url)
 
660
                    self.outf.write("Using saved parent location: %s\n" % display_url)
634
661
                location = stored_loc
635
662
 
636
663
        if mergeable is not None:
779
806
            else:
780
807
                display_url = urlutils.unescape_for_display(stored_loc,
781
808
                        self.outf.encoding)
782
 
                self.outf.write("Using saved location: %s\n" % display_url)
 
809
                self.outf.write("Using saved push location: %s\n" % display_url)
783
810
                location = stored_loc
784
811
 
785
812
        _show_push_branch(br_from, revision_id, location, self.outf,
1052
1079
class cmd_remove(Command):
1053
1080
    """Remove files or directories.
1054
1081
 
1055
 
    This makes bzr stop tracking changes to the specified files and
1056
 
    delete them if they can easily be recovered using revert.
1057
 
 
1058
 
    You can specify one or more files, and/or --new.  If you specify --new,
1059
 
    only 'added' files will be removed.  If you specify both, then new files
1060
 
    in the specified directories will be removed.  If the directories are
1061
 
    also new, they will also be removed.
 
1082
    This makes bzr stop tracking changes to the specified files. bzr will delete
 
1083
    them if they can easily be recovered using revert. If no options or
 
1084
    parameters are given bzr will scan for files that are being tracked by bzr
 
1085
    but missing in your tree and stop tracking them for you.
1062
1086
    """
1063
1087
    takes_args = ['file*']
1064
1088
    takes_options = ['verbose',
1065
 
        Option('new', help='Remove newly-added files.'),
 
1089
        Option('new', help='Only remove files that have never been committed.'),
1066
1090
        RegistryOption.from_kwargs('file-deletion-strategy',
1067
1091
            'The file deletion mode to be used.',
1068
1092
            title='Deletion Strategy', value_switches=True, enum_switch=False,
1071
1095
            keep="Don't delete any files.",
1072
1096
            force='Delete all the specified files, even if they can not be '
1073
1097
                'recovered and even if they are non-empty directories.')]
1074
 
    aliases = ['rm']
 
1098
    aliases = ['rm', 'del']
1075
1099
    encoding_type = 'replace'
1076
1100
 
1077
1101
    def run(self, file_list, verbose=False, new=False,
1080
1104
 
1081
1105
        if file_list is not None:
1082
1106
            file_list = [f for f in file_list]
1083
 
        elif not new:
1084
 
            raise errors.BzrCommandError('Specify one or more files to'
1085
 
            ' remove, or use --new.')
1086
1107
 
1087
 
        if new:
1088
 
            added = tree.changes_from(tree.basis_tree(),
1089
 
                specific_files=file_list).added
1090
 
            file_list = sorted([f[0] for f in added], reverse=True)
1091
 
            if len(file_list) == 0:
1092
 
                raise errors.BzrCommandError('No matching files.')
1093
 
        tree.remove(file_list, verbose=verbose, to_file=self.outf,
1094
 
            keep_files=file_deletion_strategy=='keep',
1095
 
            force=file_deletion_strategy=='force')
 
1108
        tree.lock_write()
 
1109
        try:
 
1110
            # Heuristics should probably all move into tree.remove_smart or
 
1111
            # some such?
 
1112
            if new:
 
1113
                added = tree.changes_from(tree.basis_tree(),
 
1114
                    specific_files=file_list).added
 
1115
                file_list = sorted([f[0] for f in added], reverse=True)
 
1116
                if len(file_list) == 0:
 
1117
                    raise errors.BzrCommandError('No matching files.')
 
1118
            elif file_list is None:
 
1119
                # missing files show up in iter_changes(basis) as
 
1120
                # versioned-with-no-kind.
 
1121
                missing = []
 
1122
                for change in tree.iter_changes(tree.basis_tree()):
 
1123
                    # Find paths in the working tree that have no kind:
 
1124
                    if change[1][1] is not None and change[6][1] is None:
 
1125
                        missing.append(change[1][1])
 
1126
                file_list = sorted(missing, reverse=True)
 
1127
                file_deletion_strategy = 'keep'
 
1128
            tree.remove(file_list, verbose=verbose, to_file=self.outf,
 
1129
                keep_files=file_deletion_strategy=='keep',
 
1130
                force=file_deletion_strategy=='force')
 
1131
        finally:
 
1132
            tree.unlock()
1096
1133
 
1097
1134
 
1098
1135
class cmd_file_id(Command):
1297
1334
            except errors.UpgradeRequired:
1298
1335
                raise errors.BzrCommandError('This branch format cannot be set'
1299
1336
                    ' to append-revisions-only.  Try --experimental-branch6')
 
1337
        if not is_quiet():
 
1338
            from bzrlib.info import show_bzrdir_info
 
1339
            show_bzrdir_info(bzrdir.BzrDir.open_containing_from_transport(
 
1340
                to_transport)[0], verbose=0, outfile=self.outf)
1300
1341
 
1301
1342
 
1302
1343
class cmd_init_repository(Command):
1348
1389
        newdir = format.initialize_on_transport(to_transport)
1349
1390
        repo = newdir.create_repository(shared=True)
1350
1391
        repo.set_make_working_trees(not no_trees)
 
1392
        if not is_quiet():
 
1393
            from bzrlib.info import show_bzrdir_info
 
1394
            show_bzrdir_info(bzrdir.BzrDir.open_containing_from_transport(
 
1395
                to_transport)[0], verbose=0, outfile=self.outf)
1351
1396
 
1352
1397
 
1353
1398
class cmd_diff(Command):
1927
1972
            print "Warning: the following files are version controlled and" \
1928
1973
                  " match your ignore pattern:\n%s" % ("\n".join(matches),)
1929
1974
 
 
1975
 
1930
1976
class cmd_ignored(Command):
1931
1977
    """List ignored files and the patterns that matched them.
 
1978
 
 
1979
    List all the ignored files and the ignore pattern that caused the file to
 
1980
    be ignored.
 
1981
 
 
1982
    Alternatively, to list just the files::
 
1983
 
 
1984
        bzr ls --ignored
1932
1985
    """
1933
1986
 
1934
1987
    encoding_type = 'replace'
1935
 
    _see_also = ['ignore']
 
1988
    _see_also = ['ignore', 'ls']
1936
1989
 
1937
1990
    @display_command
1938
1991
    def run(self):
1996
2049
         zip                          .zip
1997
2050
      =================       =========================
1998
2051
    """
1999
 
    takes_args = ['dest', 'branch?']
 
2052
    takes_args = ['dest', 'branch_or_subdir?']
2000
2053
    takes_options = [
2001
2054
        Option('format',
2002
2055
               help="Type of file to export to.",
2006
2059
               type=str,
2007
2060
               help="Name of the root directory inside the exported file."),
2008
2061
        ]
2009
 
    def run(self, dest, branch=None, revision=None, format=None, root=None):
 
2062
    def run(self, dest, branch_or_subdir=None, revision=None, format=None,
 
2063
        root=None):
2010
2064
        from bzrlib.export import export
2011
2065
 
2012
 
        if branch is None:
 
2066
        if branch_or_subdir is None:
2013
2067
            tree = WorkingTree.open_containing(u'.')[0]
2014
2068
            b = tree.branch
 
2069
            subdir = None
2015
2070
        else:
2016
 
            b = Branch.open(branch)
 
2071
            b, subdir = Branch.open_containing(branch_or_subdir)
2017
2072
            
2018
2073
        if revision is None:
2019
2074
            # should be tree.last_revision  FIXME
2024
2079
            rev_id = revision[0].as_revision_id(b)
2025
2080
        t = b.repository.revision_tree(rev_id)
2026
2081
        try:
2027
 
            export(t, dest, format, root)
 
2082
            export(t, dest, format, root, subdir)
2028
2083
        except errors.NoSuchExportFormat, e:
2029
2084
            raise errors.BzrCommandError('Unsupported export format: %s' % e.format)
2030
2085
 
2106
2161
    committed.  If a directory is specified then the directory and everything 
2107
2162
    within it is committed.
2108
2163
 
 
2164
    When excludes are given, they take precedence over selected files.
 
2165
    For example, too commit only changes within foo, but not changes within
 
2166
    foo/bar::
 
2167
 
 
2168
      bzr commit foo -x foo/bar
 
2169
 
2109
2170
    If author of the change is not the same person as the committer, you can
2110
2171
    specify the author's name using the --author option. The name should be
2111
2172
    in the same format as a committer-id, e.g. "John Doe <jdoe@example.com>".
2141
2202
    _see_also = ['bugs', 'uncommit']
2142
2203
    takes_args = ['selected*']
2143
2204
    takes_options = [
 
2205
            ListOption('exclude', type=str, short_name='x',
 
2206
                help="Do not consider changes made to a given path."),
2144
2207
            Option('message', type=unicode,
2145
2208
                   short_name='m',
2146
2209
                   help="Description of the new revision."),
2195
2258
 
2196
2259
    def run(self, message=None, file=None, verbose=False, selected_list=None,
2197
2260
            unchanged=False, strict=False, local=False, fixes=None,
2198
 
            author=None, show_diff=False):
 
2261
            author=None, show_diff=False, exclude=None):
2199
2262
        from bzrlib.errors import (
2200
2263
            PointlessCommit,
2201
2264
            ConflictsInTree,
2245
2308
                raise errors.BzrCommandError(
2246
2309
                    "please specify either --message or --file")
2247
2310
            if file:
2248
 
                my_message = codecs.open(file, 'rt', 
 
2311
                my_message = codecs.open(file, 'rt',
2249
2312
                                         bzrlib.user_encoding).read()
2250
2313
            if my_message == "":
2251
2314
                raise errors.BzrCommandError("empty commit message specified")
2256
2319
                        specific_files=selected_list,
2257
2320
                        allow_pointless=unchanged, strict=strict, local=local,
2258
2321
                        reporter=None, verbose=verbose, revprops=properties,
2259
 
                        author=author)
 
2322
                        author=author,
 
2323
                        exclude=safe_relpath_files(tree, exclude))
2260
2324
        except PointlessCommit:
2261
2325
            # FIXME: This should really happen before the file is read in;
2262
2326
            # perhaps prepare the commit; get the message; then actually commit
2277
2341
 
2278
2342
 
2279
2343
class cmd_check(Command):
2280
 
    """Validate working tree structure, branch consistency and repository
2281
 
    history.
 
2344
    """Validate working tree structure, branch consistency and repository history.
2282
2345
 
2283
2346
    This command checks various invariants about branch and repository storage
2284
2347
    to detect data corruption or bzr bugs.
2299
2362
            in the checked revisions.  Texts can be repeated when their file
2300
2363
            entries are modified, but the file contents are not.  It does not
2301
2364
            indicate a problem.
 
2365
 
 
2366
    If no restrictions are specified, all Bazaar data that is found at the given
 
2367
    location will be checked.
 
2368
 
 
2369
    :Examples:
 
2370
 
 
2371
        Check the tree and branch at 'foo'::
 
2372
 
 
2373
            bzr check --tree --branch foo
 
2374
 
 
2375
        Check only the repository at 'bar'::
 
2376
 
 
2377
            bzr check --repo bar
 
2378
 
 
2379
        Check everything at 'baz'::
 
2380
 
 
2381
            bzr check baz
2302
2382
    """
2303
2383
 
2304
2384
    _see_also = ['reconcile']
2305
2385
    takes_args = ['path?']
2306
 
    takes_options = ['verbose']
 
2386
    takes_options = ['verbose',
 
2387
                     Option('branch', help="Check the branch related to the"
 
2388
                                           " current directory."),
 
2389
                     Option('repo', help="Check the repository related to the"
 
2390
                                         " current directory."),
 
2391
                     Option('tree', help="Check the working tree related to"
 
2392
                                         " the current directory.")]
2307
2393
 
2308
 
    def run(self, path=None, verbose=False):
 
2394
    def run(self, path=None, verbose=False, branch=False, repo=False,
 
2395
            tree=False):
2309
2396
        from bzrlib.check import check_dwim
2310
2397
        if path is None:
2311
2398
            path = '.'
2312
 
        check_dwim(path, verbose)
 
2399
        if not branch and not repo and not tree:
 
2400
            branch = repo = tree = True
 
2401
        check_dwim(path, verbose, do_branch=branch, do_repo=repo, do_tree=tree)
2313
2402
 
2314
2403
 
2315
2404
class cmd_upgrade(Command):
2577
2666
                            help='Load a test id list from a text file.'),
2578
2667
                     ListOption('debugflag', type=str, short_name='E',
2579
2668
                                help='Turn on a selftest debug flag.'),
2580
 
                     Option('starting-with', type=str, argname='TESTID',
2581
 
                            short_name='s',
2582
 
                            help='Load only the tests starting with TESTID.'),
 
2669
                     ListOption('starting-with', type=str, argname='TESTID',
 
2670
                                param_name='starting_with', short_name='s',
 
2671
                                help=
 
2672
                                'Load only the tests starting with TESTID.'),
2583
2673
                     ]
2584
2674
    encoding_type = 'replace'
2585
2675
 
2986
3076
        Report if the remembered location was used.
2987
3077
        """
2988
3078
        stored_location = tree.branch.get_submit_branch()
 
3079
        stored_location_type = "submit"
2989
3080
        if stored_location is None:
2990
3081
            stored_location = tree.branch.get_parent()
 
3082
            stored_location_type = "parent"
2991
3083
        mutter("%s", stored_location)
2992
3084
        if stored_location is None:
2993
3085
            raise errors.BzrCommandError("No location specified or remembered")
2994
3086
        display_url = urlutils.unescape_for_display(stored_location, 'utf-8')
2995
 
        note(u"%s remembered location %s", verb_string, display_url)
 
3087
        note(u"%s remembered %s location %s", verb_string,
 
3088
                stored_location_type, display_url)
2996
3089
        return stored_location
2997
3090
 
2998
3091
 
3257
3350
                                             " or specified.")
3258
3351
            display_url = urlutils.unescape_for_display(parent,
3259
3352
                                                        self.outf.encoding)
3260
 
            self.outf.write("Using last location: " + display_url + "\n")
 
3353
            self.outf.write("Using saved parent location: "
 
3354
                    + display_url + "\n")
3261
3355
 
3262
3356
        remote_branch = Branch.open(other_branch)
3263
3357
        if remote_branch.base == local_branch.base:
3703
3797
                    print 'Canceled'
3704
3798
                    return 0
3705
3799
 
 
3800
        mutter('Uncommitting from {%s} to {%s}',
 
3801
               last_rev_id, rev_id)
3706
3802
        uncommit(b, tree=tree, dry_run=dry_run, verbose=verbose,
3707
3803
                 revno=revno, local=local)
 
3804
        note('You can restore the old tip by running:\n'
 
3805
             '  bzr pull . -r revid:%s', last_rev_id)
3708
3806
 
3709
3807
 
3710
3808
class cmd_break_lock(Command):
4024
4122
    (For Thunderbird 1.5, this works around some bugs.)  Supported values for
4025
4123
    specific clients are "evolution", "kmail", "mutt", and "thunderbird";
4026
4124
    generic options are "default", "editor", "emacsclient", "mapi", and
4027
 
    "xdg-email".
 
4125
    "xdg-email".  Plugins may also add supported clients.
4028
4126
 
4029
4127
    If mail is being sent, a to address is required.  This can be supplied
4030
4128
    either on the commandline, by setting the submit_to configuration
4102
4200
                raise errors.BzrCommandError(
4103
4201
                    '--remember requires a branch to be specified.')
4104
4202
            stored_submit_branch = branch.get_submit_branch()
4105
 
            remembered_submit_branch = False
 
4203
            remembered_submit_branch = None
4106
4204
            if submit_branch is None:
4107
4205
                submit_branch = stored_submit_branch
4108
 
                remembered_submit_branch = True
 
4206
                remembered_submit_branch = "submit"
4109
4207
            else:
4110
4208
                if stored_submit_branch is None or remember:
4111
4209
                    branch.set_submit_branch(submit_branch)
4112
4210
            if submit_branch is None:
4113
4211
                submit_branch = branch.get_parent()
4114
 
                remembered_submit_branch = True
 
4212
                remembered_submit_branch = "parent"
4115
4213
            if submit_branch is None:
4116
4214
                raise errors.BzrCommandError('No submit branch known or'
4117
4215
                                             ' specified')
4118
 
            if remembered_submit_branch:
4119
 
                note('Using saved location: %s', submit_branch)
 
4216
            if remembered_submit_branch is not None:
 
4217
                note('Using saved %s location "%s" to determine what '
 
4218
                        'changes to submit.', remembered_submit_branch,
 
4219
                        submit_branch)
4120
4220
 
4121
4221
            if mail_to is None:
4122
4222
                submit_config = Branch.open(submit_branch).get_config()
4267
4367
 
4268
4368
    It is an error to give a tag name that already exists unless you pass 
4269
4369
    --force, in which case the tag is moved to point to the new revision.
 
4370
 
 
4371
    To rename a tag (change the name but keep it on the same revsion), run ``bzr
 
4372
    tag new-name -r tag:old-name`` and then ``bzr tag --delete oldname``.
4270
4373
    """
4271
4374
 
4272
4375
    _see_also = ['commit', 'tags']
4344
4447
            ):
4345
4448
        branch, relpath = Branch.open_containing(directory)
4346
4449
        tags = branch.tags.get_tag_dict().items()
 
4450
        if not tags:
 
4451
            return
4347
4452
        if sort == 'alpha':
4348
4453
            tags.sort()
4349
4454
        elif sort == 'time':