/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: 2005-11-23 13:54:46 UTC
  • mto: (1185.50.19 bzr-jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1512.
  • Revision ID: john@arbash-meinel.com-20051123135446-6d79a500f3e3f3e2
[patch] Johan Rydberg - let clone use set_revision_history instead of append_revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2004, 2005 by Canonical Ltd
 
2
 
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
 
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
 
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
# DO NOT change this to cStringIO - it results in control files 
 
18
# written as UCS4
 
19
# FIXIT! (Only deal with byte streams OR unicode at any one layer.)
 
20
# RBC 20051018
 
21
from StringIO import StringIO
 
22
import sys
 
23
import os
 
24
 
 
25
import bzrlib
 
26
from bzrlib import BZRDIR
 
27
from bzrlib.commands import Command, display_command
 
28
from bzrlib.branch import Branch
 
29
from bzrlib.revision import common_ancestor
 
30
import bzrlib.errors as errors
 
31
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError, 
 
32
                           NotBranchError, DivergedBranches, NotConflicted,
 
33
                           NoSuchFile, NoWorkingTree, FileInWrongBranch)
 
34
from bzrlib.option import Option
 
35
from bzrlib.revisionspec import RevisionSpec
 
36
import bzrlib.trace
 
37
from bzrlib.trace import mutter, note, log_error, warning
 
38
from bzrlib.workingtree import WorkingTree
 
39
 
 
40
 
 
41
def branch_files(file_list, default_branch='.'):
 
42
    try:
 
43
        return inner_branch_files(file_list, default_branch)
 
44
    except FileInWrongBranch, e:
 
45
        raise BzrCommandError("%s is not in the same branch as %s" %
 
46
                             (e.path, file_list[0]))
 
47
 
 
48
def inner_branch_files(file_list, default_branch='.'):
 
49
    """\
 
50
    Return a branch and list of branch-relative paths.
 
51
    If supplied file_list is empty or None, the branch default will be used,
 
52
    and returned file_list will match the original.
 
53
    """
 
54
    if file_list is None or len(file_list) == 0:
 
55
        return Branch.open_containing(default_branch)[0], file_list
 
56
    b = Branch.open_containing(file_list[0])[0]
 
57
    
 
58
    # note that if this is a remote branch, we would want
 
59
    # relpath against the transport. RBC 20051018
 
60
    # Most branch ops can't meaningfully operate on files in remote branches;
 
61
    # the above comment was in cmd_status.  ADHB 20051026
 
62
    tree = WorkingTree(b.base, b)
 
63
    new_list = []
 
64
    for filename in file_list:
 
65
        try:
 
66
            new_list.append(tree.relpath(filename))
 
67
        except NotBranchError:
 
68
            raise FileInWrongBranch(b, filename)
 
69
    return b, new_list
 
70
 
 
71
 
 
72
# TODO: Make sure no commands unconditionally use the working directory as a
 
73
# branch.  If a filename argument is used, the first of them should be used to
 
74
# specify the branch.  (Perhaps this can be factored out into some kind of
 
75
# Argument class, representing a file in a branch, where the first occurrence
 
76
# opens the branch?)
 
77
 
 
78
class cmd_status(Command):
 
79
    """Display status summary.
 
80
 
 
81
    This reports on versioned and unknown files, reporting them
 
82
    grouped by state.  Possible states are:
 
83
 
 
84
    added
 
85
        Versioned in the working copy but not in the previous revision.
 
86
 
 
87
    removed
 
88
        Versioned in the previous revision but removed or deleted
 
89
        in the working copy.
 
90
 
 
91
    renamed
 
92
        Path of this file changed from the previous revision;
 
93
        the text may also have changed.  This includes files whose
 
94
        parent directory was renamed.
 
95
 
 
96
    modified
 
97
        Text has changed since the previous revision.
 
98
 
 
99
    unchanged
 
100
        Nothing about this file has changed since the previous revision.
 
101
        Only shown with --all.
 
102
 
 
103
    unknown
 
104
        Not versioned and not matching an ignore pattern.
 
105
 
 
106
    To see ignored files use 'bzr ignored'.  For details in the
 
107
    changes to file texts, use 'bzr diff'.
 
108
 
 
109
    If no arguments are specified, the status of the entire working
 
110
    directory is shown.  Otherwise, only the status of the specified
 
111
    files or directories is reported.  If a directory is given, status
 
112
    is reported for everything inside that directory.
 
113
 
 
114
    If a revision argument is given, the status is calculated against
 
115
    that revision, or between two revisions if two are provided.
 
116
    """
 
117
    
 
118
    # TODO: --no-recurse, --recurse options
 
119
    
 
120
    takes_args = ['file*']
 
121
    takes_options = ['all', 'show-ids', 'revision']
 
122
    aliases = ['st', 'stat']
 
123
    
 
124
    @display_command
 
125
    def run(self, all=False, show_ids=False, file_list=None, revision=None):
 
126
        b, file_list = branch_files(file_list)
 
127
            
 
128
        from bzrlib.status import show_status
 
129
        show_status(b, show_unchanged=all, show_ids=show_ids,
 
130
                    specific_files=file_list, revision=revision)
 
131
 
 
132
 
 
133
class cmd_cat_revision(Command):
 
134
    """Write out metadata for a revision.
 
135
    
 
136
    The revision to print can either be specified by a specific
 
137
    revision identifier, or you can use --revision.
 
138
    """
 
139
 
 
140
    hidden = True
 
141
    takes_args = ['revision_id?']
 
142
    takes_options = ['revision']
 
143
    
 
144
    @display_command
 
145
    def run(self, revision_id=None, revision=None):
 
146
 
 
147
        if revision_id is not None and revision is not None:
 
148
            raise BzrCommandError('You can only supply one of revision_id or --revision')
 
149
        if revision_id is None and revision is None:
 
150
            raise BzrCommandError('You must supply either --revision or a revision_id')
 
151
        b = Branch.open_containing('.')[0]
 
152
        if revision_id is not None:
 
153
            sys.stdout.write(b.get_revision_xml_file(revision_id).read())
 
154
        elif revision is not None:
 
155
            for rev in revision:
 
156
                if rev is None:
 
157
                    raise BzrCommandError('You cannot specify a NULL revision.')
 
158
                revno, rev_id = rev.in_history(b)
 
159
                sys.stdout.write(b.get_revision_xml_file(rev_id).read())
 
160
    
 
161
 
 
162
class cmd_revno(Command):
 
163
    """Show current revision number.
 
164
 
 
165
    This is equal to the number of revisions on this branch."""
 
166
    @display_command
 
167
    def run(self):
 
168
        print Branch.open_containing('.')[0].revno()
 
169
 
 
170
 
 
171
class cmd_revision_info(Command):
 
172
    """Show revision number and revision id for a given revision identifier.
 
173
    """
 
174
    hidden = True
 
175
    takes_args = ['revision_info*']
 
176
    takes_options = ['revision']
 
177
    @display_command
 
178
    def run(self, revision=None, revision_info_list=[]):
 
179
 
 
180
        revs = []
 
181
        if revision is not None:
 
182
            revs.extend(revision)
 
183
        if revision_info_list is not None:
 
184
            for rev in revision_info_list:
 
185
                revs.append(RevisionSpec(rev))
 
186
        if len(revs) == 0:
 
187
            raise BzrCommandError('You must supply a revision identifier')
 
188
 
 
189
        b = Branch.open_containing('.')[0]
 
190
 
 
191
        for rev in revs:
 
192
            revinfo = rev.in_history(b)
 
193
            if revinfo.revno is None:
 
194
                print '     %s' % revinfo.rev_id
 
195
            else:
 
196
                print '%4d %s' % (revinfo.revno, revinfo.rev_id)
 
197
 
 
198
    
 
199
class cmd_add(Command):
 
200
    """Add specified files or directories.
 
201
 
 
202
    In non-recursive mode, all the named items are added, regardless
 
203
    of whether they were previously ignored.  A warning is given if
 
204
    any of the named files are already versioned.
 
205
 
 
206
    In recursive mode (the default), files are treated the same way
 
207
    but the behaviour for directories is different.  Directories that
 
208
    are already versioned do not give a warning.  All directories,
 
209
    whether already versioned or not, are searched for files or
 
210
    subdirectories that are neither versioned or ignored, and these
 
211
    are added.  This search proceeds recursively into versioned
 
212
    directories.  If no names are given '.' is assumed.
 
213
 
 
214
    Therefore simply saying 'bzr add' will version all files that
 
215
    are currently unknown.
 
216
 
 
217
    Adding a file whose parent directory is not versioned will
 
218
    implicitly add the parent, and so on up to the root. This means
 
219
    you should never need to explictly add a directory, they'll just
 
220
    get added when you add a file in the directory.
 
221
    """
 
222
    takes_args = ['file*']
 
223
    takes_options = ['no-recurse', 'quiet']
 
224
    
 
225
    def run(self, file_list, no_recurse=False, quiet=False):
 
226
        from bzrlib.add import smart_add, add_reporter_print, add_reporter_null
 
227
        if quiet:
 
228
            reporter = add_reporter_null
 
229
        else:
 
230
            reporter = add_reporter_print
 
231
        smart_add(file_list, not no_recurse, reporter)
 
232
 
 
233
 
 
234
class cmd_mkdir(Command):
 
235
    """Create a new versioned directory.
 
236
 
 
237
    This is equivalent to creating the directory and then adding it.
 
238
    """
 
239
    takes_args = ['dir+']
 
240
 
 
241
    def run(self, dir_list):
 
242
        b = None
 
243
        
 
244
        for d in dir_list:
 
245
            os.mkdir(d)
 
246
            b, dd = Branch.open_containing(d)
 
247
            b.add([dd])
 
248
            print 'added', d
 
249
 
 
250
 
 
251
class cmd_relpath(Command):
 
252
    """Show path of a file relative to root"""
 
253
    takes_args = ['filename']
 
254
    hidden = True
 
255
    
 
256
    @display_command
 
257
    def run(self, filename):
 
258
        branch, relpath = Branch.open_containing(filename)
 
259
        print relpath
 
260
 
 
261
 
 
262
class cmd_inventory(Command):
 
263
    """Show inventory of the current working copy or a revision.
 
264
 
 
265
    It is possible to limit the output to a particular entry
 
266
    type using the --kind option.  For example; --kind file.
 
267
    """
 
268
    takes_options = ['revision', 'show-ids', 'kind']
 
269
    
 
270
    @display_command
 
271
    def run(self, revision=None, show_ids=False, kind=None):
 
272
        if kind and kind not in ['file', 'directory', 'symlink']:
 
273
            raise BzrCommandError('invalid kind specified')
 
274
        b = Branch.open_containing('.')[0]
 
275
        if revision is None:
 
276
            inv = b.working_tree().read_working_inventory()
 
277
        else:
 
278
            if len(revision) > 1:
 
279
                raise BzrCommandError('bzr inventory --revision takes'
 
280
                    ' exactly one revision identifier')
 
281
            inv = b.get_revision_inventory(revision[0].in_history(b).rev_id)
 
282
 
 
283
        for path, entry in inv.entries():
 
284
            if kind and kind != entry.kind:
 
285
                continue
 
286
            if show_ids:
 
287
                print '%-50s %s' % (path, entry.file_id)
 
288
            else:
 
289
                print path
 
290
 
 
291
 
 
292
class cmd_move(Command):
 
293
    """Move files to a different directory.
 
294
 
 
295
    examples:
 
296
        bzr move *.txt doc
 
297
 
 
298
    The destination must be a versioned directory in the same branch.
 
299
    """
 
300
    takes_args = ['source$', 'dest']
 
301
    def run(self, source_list, dest):
 
302
        b, source_list = branch_files(source_list)
 
303
 
 
304
        # TODO: glob expansion on windows?
 
305
        tree = WorkingTree(b.base, b)
 
306
        b.move(source_list, tree.relpath(dest))
 
307
 
 
308
 
 
309
class cmd_rename(Command):
 
310
    """Change the name of an entry.
 
311
 
 
312
    examples:
 
313
      bzr rename frob.c frobber.c
 
314
      bzr rename src/frob.c lib/frob.c
 
315
 
 
316
    It is an error if the destination name exists.
 
317
 
 
318
    See also the 'move' command, which moves files into a different
 
319
    directory without changing their name.
 
320
    """
 
321
    # TODO: Some way to rename multiple files without invoking 
 
322
    # bzr for each one?"""
 
323
    takes_args = ['from_name', 'to_name']
 
324
    
 
325
    def run(self, from_name, to_name):
 
326
        b, (from_name, to_name) = branch_files((from_name, to_name))
 
327
        b.rename_one(from_name, to_name)
 
328
 
 
329
 
 
330
class cmd_mv(Command):
 
331
    """Move or rename a file.
 
332
 
 
333
    usage:
 
334
        bzr mv OLDNAME NEWNAME
 
335
        bzr mv SOURCE... DESTINATION
 
336
 
 
337
    If the last argument is a versioned directory, all the other names
 
338
    are moved into it.  Otherwise, there must be exactly two arguments
 
339
    and the file is changed to a new name, which must not already exist.
 
340
 
 
341
    Files cannot be moved between branches.
 
342
    """
 
343
    takes_args = ['names*']
 
344
    def run(self, names_list):
 
345
        if len(names_list) < 2:
 
346
            raise BzrCommandError("missing file argument")
 
347
        b, rel_names = branch_files(names_list)
 
348
        
 
349
        if os.path.isdir(names_list[-1]):
 
350
            # move into existing directory
 
351
            for pair in b.move(rel_names[:-1], rel_names[-1]):
 
352
                print "%s => %s" % pair
 
353
        else:
 
354
            if len(names_list) != 2:
 
355
                raise BzrCommandError('to mv multiple files the destination '
 
356
                                      'must be a versioned directory')
 
357
            b.rename_one(rel_names[0], rel_names[1])
 
358
            print "%s => %s" % (rel_names[0], rel_names[1])
 
359
            
 
360
    
 
361
class cmd_pull(Command):
 
362
    """Pull any changes from another branch into the current one.
 
363
 
 
364
    If there is no default location set, the first pull will set it.  After
 
365
    that, you can omit the location to use the default.  To change the
 
366
    default, use --remember.
 
367
 
 
368
    This command only works on branches that have not diverged.  Branches are
 
369
    considered diverged if both branches have had commits without first
 
370
    pulling from the other.
 
371
 
 
372
    If branches have diverged, you can use 'bzr merge' to pull the text changes
 
373
    from one into the other.  Once one branch has merged, the other should
 
374
    be able to pull it again.
 
375
 
 
376
    If you want to forget your local changes and just update your branch to
 
377
    match the remote one, use --overwrite.
 
378
    """
 
379
    takes_options = ['remember', 'overwrite', 'verbose']
 
380
    takes_args = ['location?']
 
381
 
 
382
    def run(self, location=None, remember=False, overwrite=False, verbose=False):
 
383
        from bzrlib.merge import merge
 
384
        from shutil import rmtree
 
385
        import errno
 
386
        
 
387
        br_to = Branch.open_containing('.')[0]
 
388
        stored_loc = br_to.get_parent()
 
389
        if location is None:
 
390
            if stored_loc is None:
 
391
                raise BzrCommandError("No pull location known or specified.")
 
392
            else:
 
393
                print "Using saved location: %s" % stored_loc
 
394
                location = stored_loc
 
395
        br_from = Branch.open(location)
 
396
        try:
 
397
            old_rh = br_to.revision_history()
 
398
            br_to.working_tree().pull(br_from, overwrite)
 
399
        except DivergedBranches:
 
400
            raise BzrCommandError("These branches have diverged."
 
401
                                  "  Try merge.")
 
402
        if br_to.get_parent() is None or remember:
 
403
            br_to.set_parent(location)
 
404
 
 
405
        if verbose:
 
406
            new_rh = br_to.revision_history()
 
407
            if old_rh != new_rh:
 
408
                # Something changed
 
409
                from bzrlib.log import show_changed_revisions
 
410
                show_changed_revisions(br_to, old_rh, new_rh)
 
411
 
 
412
 
 
413
class cmd_push(Command):
 
414
    """Push this branch into another branch.
 
415
    
 
416
    The remote branch will not have its working tree populated because this
 
417
    is both expensive, and may not be supported on the remote file system.
 
418
    
 
419
    Some smart servers or protocols *may* put the working tree in place.
 
420
 
 
421
    If there is no default push location set, the first push will set it.
 
422
    After that, you can omit the location to use the default.  To change the
 
423
    default, use --remember.
 
424
 
 
425
    This command only works on branches that have not diverged.  Branches are
 
426
    considered diverged if the branch being pushed to is not an older version
 
427
    of this branch.
 
428
 
 
429
    If branches have diverged, you can use 'bzr push --overwrite' to replace
 
430
    the other branch completely.
 
431
    
 
432
    If you want to ensure you have the different changes in the other branch,
 
433
    do a merge (see bzr help merge) from the other branch, and commit that
 
434
    before doing a 'push --overwrite'.
 
435
    """
 
436
    takes_options = ['remember', 'overwrite', 
 
437
                     Option('create-prefix', 
 
438
                            help='Create the path leading up to the branch '
 
439
                                 'if it does not already exist')]
 
440
    takes_args = ['location?']
 
441
 
 
442
    def run(self, location=None, remember=False, overwrite=False,
 
443
            create_prefix=False, verbose=False):
 
444
        import errno
 
445
        from shutil import rmtree
 
446
        from bzrlib.transport import get_transport
 
447
        
 
448
        br_from = Branch.open_containing('.')[0]
 
449
        stored_loc = br_from.get_push_location()
 
450
        if location is None:
 
451
            if stored_loc is None:
 
452
                raise BzrCommandError("No push location known or specified.")
 
453
            else:
 
454
                print "Using saved location: %s" % stored_loc
 
455
                location = stored_loc
 
456
        try:
 
457
            br_to = Branch.open(location)
 
458
        except NotBranchError:
 
459
            # create a branch.
 
460
            transport = get_transport(location).clone('..')
 
461
            if not create_prefix:
 
462
                try:
 
463
                    transport.mkdir(transport.relpath(location))
 
464
                except NoSuchFile:
 
465
                    raise BzrCommandError("Parent directory of %s "
 
466
                                          "does not exist." % location)
 
467
            else:
 
468
                current = transport.base
 
469
                needed = [(transport, transport.relpath(location))]
 
470
                while needed:
 
471
                    try:
 
472
                        transport, relpath = needed[-1]
 
473
                        transport.mkdir(relpath)
 
474
                        needed.pop()
 
475
                    except NoSuchFile:
 
476
                        new_transport = transport.clone('..')
 
477
                        needed.append((new_transport,
 
478
                                       new_transport.relpath(transport.base)))
 
479
                        if new_transport.base == transport.base:
 
480
                            raise BzrCommandError("Could not creeate "
 
481
                                                  "path prefix.")
 
482
                        
 
483
            NoSuchFile
 
484
            br_to = Branch.initialize(location)
 
485
        try:
 
486
            old_rh = br_to.revision_history()
 
487
            br_to.pull(br_from, overwrite)
 
488
        except DivergedBranches:
 
489
            raise BzrCommandError("These branches have diverged."
 
490
                                  "  Try a merge then push with overwrite.")
 
491
        if br_from.get_push_location() is None or remember:
 
492
            br_from.set_push_location(location)
 
493
 
 
494
        if verbose:
 
495
            new_rh = br_to.revision_history()
 
496
            if old_rh != new_rh:
 
497
                # Something changed
 
498
                from bzrlib.log import show_changed_revisions
 
499
                show_changed_revisions(br_to, old_rh, new_rh)
 
500
 
 
501
class cmd_branch(Command):
 
502
    """Create a new copy of a branch.
 
503
 
 
504
    If the TO_LOCATION is omitted, the last component of the FROM_LOCATION will
 
505
    be used.  In other words, "branch ../foo/bar" will attempt to create ./bar.
 
506
 
 
507
    To retrieve the branch as of a particular revision, supply the --revision
 
508
    parameter, as in "branch foo/bar -r 5".
 
509
 
 
510
    --basis is to speed up branching from remote branches.  When specified, it
 
511
    copies all the file-contents, inventory and revision data from the basis
 
512
    branch before copying anything from the remote branch.
 
513
    """
 
514
    takes_args = ['from_location', 'to_location?']
 
515
    takes_options = ['revision', 'basis']
 
516
    aliases = ['get', 'clone']
 
517
 
 
518
    def run(self, from_location, to_location=None, revision=None, basis=None):
 
519
        from bzrlib.clone import copy_branch
 
520
        import errno
 
521
        from shutil import rmtree
 
522
        if revision is None:
 
523
            revision = [None]
 
524
        elif len(revision) > 1:
 
525
            raise BzrCommandError(
 
526
                'bzr branch --revision takes exactly 1 revision value')
 
527
        try:
 
528
            br_from = Branch.open(from_location)
 
529
        except OSError, e:
 
530
            if e.errno == errno.ENOENT:
 
531
                raise BzrCommandError('Source location "%s" does not'
 
532
                                      ' exist.' % to_location)
 
533
            else:
 
534
                raise
 
535
        br_from.lock_read()
 
536
        try:
 
537
            if basis is not None:
 
538
                basis_branch = Branch.open_containing(basis)[0]
 
539
            else:
 
540
                basis_branch = None
 
541
            if len(revision) == 1 and revision[0] is not None:
 
542
                revision_id = revision[0].in_history(br_from)[1]
 
543
            else:
 
544
                revision_id = None
 
545
            if to_location is None:
 
546
                to_location = os.path.basename(from_location.rstrip("/\\"))
 
547
                name = None
 
548
            else:
 
549
                name = os.path.basename(to_location) + '\n'
 
550
            try:
 
551
                os.mkdir(to_location)
 
552
            except OSError, e:
 
553
                if e.errno == errno.EEXIST:
 
554
                    raise BzrCommandError('Target directory "%s" already'
 
555
                                          ' exists.' % to_location)
 
556
                if e.errno == errno.ENOENT:
 
557
                    raise BzrCommandError('Parent of "%s" does not exist.' %
 
558
                                          to_location)
 
559
                else:
 
560
                    raise
 
561
            try:
 
562
                copy_branch(br_from, to_location, revision_id, basis_branch)
 
563
            except bzrlib.errors.NoSuchRevision:
 
564
                rmtree(to_location)
 
565
                msg = "The branch %s has no revision %s." % (from_location, revision[0])
 
566
                raise BzrCommandError(msg)
 
567
            except bzrlib.errors.UnlistableBranch:
 
568
                rmtree(to_location)
 
569
                msg = "The branch %s cannot be used as a --basis"
 
570
                raise BzrCommandError(msg)
 
571
            if name:
 
572
                branch = Branch.open(to_location)
 
573
                name = StringIO(name)
 
574
                branch.put_controlfile('branch-name', name)
 
575
        finally:
 
576
            br_from.unlock()
 
577
 
 
578
 
 
579
class cmd_renames(Command):
 
580
    """Show list of renamed files.
 
581
    """
 
582
    # TODO: Option to show renames between two historical versions.
 
583
 
 
584
    # TODO: Only show renames under dir, rather than in the whole branch.
 
585
    takes_args = ['dir?']
 
586
 
 
587
    @display_command
 
588
    def run(self, dir='.'):
 
589
        b = Branch.open_containing(dir)[0]
 
590
        old_inv = b.basis_tree().inventory
 
591
        new_inv = b.working_tree().read_working_inventory()
 
592
 
 
593
        renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
 
594
        renames.sort()
 
595
        for old_name, new_name in renames:
 
596
            print "%s => %s" % (old_name, new_name)        
 
597
 
 
598
 
 
599
class cmd_info(Command):
 
600
    """Show statistical information about a branch."""
 
601
    takes_args = ['branch?']
 
602
    
 
603
    @display_command
 
604
    def run(self, branch=None):
 
605
        import info
 
606
        b = Branch.open_containing(branch)[0]
 
607
        info.show_info(b)
 
608
 
 
609
 
 
610
class cmd_remove(Command):
 
611
    """Make a file unversioned.
 
612
 
 
613
    This makes bzr stop tracking changes to a versioned file.  It does
 
614
    not delete the working copy.
 
615
    """
 
616
    takes_args = ['file+']
 
617
    takes_options = ['verbose']
 
618
    aliases = ['rm']
 
619
    
 
620
    def run(self, file_list, verbose=False):
 
621
        b, file_list = branch_files(file_list)
 
622
        tree = b.working_tree()
 
623
        tree.remove(file_list, verbose=verbose)
 
624
 
 
625
 
 
626
class cmd_file_id(Command):
 
627
    """Print file_id of a particular file or directory.
 
628
 
 
629
    The file_id is assigned when the file is first added and remains the
 
630
    same through all revisions where the file exists, even when it is
 
631
    moved or renamed.
 
632
    """
 
633
    hidden = True
 
634
    takes_args = ['filename']
 
635
    @display_command
 
636
    def run(self, filename):
 
637
        b, relpath = Branch.open_containing(filename)
 
638
        i = b.working_tree().inventory.path2id(relpath)
 
639
        if i == None:
 
640
            raise BzrError("%r is not a versioned file" % filename)
 
641
        else:
 
642
            print i
 
643
 
 
644
 
 
645
class cmd_file_path(Command):
 
646
    """Print path of file_ids to a file or directory.
 
647
 
 
648
    This prints one line for each directory down to the target,
 
649
    starting at the branch root."""
 
650
    hidden = True
 
651
    takes_args = ['filename']
 
652
    @display_command
 
653
    def run(self, filename):
 
654
        b, relpath = Branch.open_containing(filename)
 
655
        inv = b.inventory
 
656
        fid = inv.path2id(relpath)
 
657
        if fid == None:
 
658
            raise BzrError("%r is not a versioned file" % filename)
 
659
        for fip in inv.get_idpath(fid):
 
660
            print fip
 
661
 
 
662
 
 
663
class cmd_revision_history(Command):
 
664
    """Display list of revision ids on this branch."""
 
665
    hidden = True
 
666
    @display_command
 
667
    def run(self):
 
668
        for patchid in Branch.open_containing('.')[0].revision_history():
 
669
            print patchid
 
670
 
 
671
 
 
672
class cmd_ancestry(Command):
 
673
    """List all revisions merged into this branch."""
 
674
    hidden = True
 
675
    @display_command
 
676
    def run(self):
 
677
        b = Branch.open_containing('.')[0]
 
678
        for revision_id in b.get_ancestry(b.last_revision()):
 
679
            print revision_id
 
680
 
 
681
 
 
682
class cmd_init(Command):
 
683
    """Make a directory into a versioned branch.
 
684
 
 
685
    Use this to create an empty branch, or before importing an
 
686
    existing project.
 
687
 
 
688
    Recipe for importing a tree of files:
 
689
        cd ~/project
 
690
        bzr init
 
691
        bzr add .
 
692
        bzr status
 
693
        bzr commit -m 'imported project'
 
694
    """
 
695
    takes_args = ['location?']
 
696
    def run(self, location=None):
 
697
        from bzrlib.branch import Branch
 
698
        if location is None:
 
699
            location = '.'
 
700
        else:
 
701
            # The path has to exist to initialize a
 
702
            # branch inside of it.
 
703
            # Just using os.mkdir, since I don't
 
704
            # believe that we want to create a bunch of
 
705
            # locations if the user supplies an extended path
 
706
            if not os.path.exists(location):
 
707
                os.mkdir(location)
 
708
        Branch.initialize(location)
 
709
 
 
710
 
 
711
class cmd_diff(Command):
 
712
    """Show differences in working tree.
 
713
    
 
714
    If files are listed, only the changes in those files are listed.
 
715
    Otherwise, all changes for the tree are listed.
 
716
 
 
717
    examples:
 
718
        bzr diff
 
719
        bzr diff -r1
 
720
        bzr diff -r1..2
 
721
    """
 
722
    # TODO: Allow diff across branches.
 
723
    # TODO: Option to use external diff command; could be GNU diff, wdiff,
 
724
    #       or a graphical diff.
 
725
 
 
726
    # TODO: Python difflib is not exactly the same as unidiff; should
 
727
    #       either fix it up or prefer to use an external diff.
 
728
 
 
729
    # TODO: If a directory is given, diff everything under that.
 
730
 
 
731
    # TODO: Selected-file diff is inefficient and doesn't show you
 
732
    #       deleted files.
 
733
 
 
734
    # TODO: This probably handles non-Unix newlines poorly.
 
735
    
 
736
    takes_args = ['file*']
 
737
    takes_options = ['revision', 'diff-options']
 
738
    aliases = ['di', 'dif']
 
739
 
 
740
    @display_command
 
741
    def run(self, revision=None, file_list=None, diff_options=None):
 
742
        from bzrlib.diff import show_diff
 
743
        try:
 
744
            b, file_list = inner_branch_files(file_list)
 
745
            b2 = None
 
746
        except FileInWrongBranch:
 
747
            if len(file_list) != 2:
 
748
                raise BzrCommandError("Files are in different branches")
 
749
 
 
750
            b, file1 = Branch.open_containing(file_list[0])
 
751
            b2, file2 = Branch.open_containing(file_list[1])
 
752
            if file1 != "" or file2 != "":
 
753
                raise BzrCommandError("Files are in different branches")
 
754
            file_list = None
 
755
        if revision is not None:
 
756
            if b2 is not None:
 
757
                raise BzrCommandError("Can't specify -r with two branches")
 
758
            if len(revision) == 1:
 
759
                return show_diff(b, revision[0], specific_files=file_list,
 
760
                                 external_diff_options=diff_options)
 
761
            elif len(revision) == 2:
 
762
                return show_diff(b, revision[0], specific_files=file_list,
 
763
                                 external_diff_options=diff_options,
 
764
                                 revision2=revision[1])
 
765
            else:
 
766
                raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
 
767
        else:
 
768
            return show_diff(b, None, specific_files=file_list,
 
769
                             external_diff_options=diff_options, b2=b2)
 
770
 
 
771
 
 
772
class cmd_deleted(Command):
 
773
    """List files deleted in the working tree.
 
774
    """
 
775
    # TODO: Show files deleted since a previous revision, or
 
776
    # between two revisions.
 
777
    # TODO: Much more efficient way to do this: read in new
 
778
    # directories with readdir, rather than stating each one.  Same
 
779
    # level of effort but possibly much less IO.  (Or possibly not,
 
780
    # if the directories are very large...)
 
781
    @display_command
 
782
    def run(self, show_ids=False):
 
783
        b = Branch.open_containing('.')[0]
 
784
        old = b.basis_tree()
 
785
        new = b.working_tree()
 
786
        for path, ie in old.inventory.iter_entries():
 
787
            if not new.has_id(ie.file_id):
 
788
                if show_ids:
 
789
                    print '%-50s %s' % (path, ie.file_id)
 
790
                else:
 
791
                    print path
 
792
 
 
793
 
 
794
class cmd_modified(Command):
 
795
    """List files modified in working tree."""
 
796
    hidden = True
 
797
    @display_command
 
798
    def run(self):
 
799
        from bzrlib.delta import compare_trees
 
800
 
 
801
        b = Branch.open_containing('.')[0]
 
802
        td = compare_trees(b.basis_tree(), b.working_tree())
 
803
 
 
804
        for path, id, kind, text_modified, meta_modified in td.modified:
 
805
            print path
 
806
 
 
807
 
 
808
 
 
809
class cmd_added(Command):
 
810
    """List files added in working tree."""
 
811
    hidden = True
 
812
    @display_command
 
813
    def run(self):
 
814
        b = Branch.open_containing('.')[0]
 
815
        wt = b.working_tree()
 
816
        basis_inv = b.basis_tree().inventory
 
817
        inv = wt.inventory
 
818
        for file_id in inv:
 
819
            if file_id in basis_inv:
 
820
                continue
 
821
            path = inv.id2path(file_id)
 
822
            if not os.access(b.abspath(path), os.F_OK):
 
823
                continue
 
824
            print path
 
825
                
 
826
        
 
827
 
 
828
class cmd_root(Command):
 
829
    """Show the tree root directory.
 
830
 
 
831
    The root is the nearest enclosing directory with a .bzr control
 
832
    directory."""
 
833
    takes_args = ['filename?']
 
834
    @display_command
 
835
    def run(self, filename=None):
 
836
        """Print the branch root."""
 
837
        b = Branch.open_containing(filename)[0]
 
838
        print b.base
 
839
 
 
840
 
 
841
class cmd_log(Command):
 
842
    """Show log of this branch.
 
843
 
 
844
    To request a range of logs, you can use the command -r begin..end
 
845
    -r revision requests a specific revision, -r ..end or -r begin.. are
 
846
    also valid.
 
847
    """
 
848
 
 
849
    # TODO: Make --revision support uuid: and hash: [future tag:] notation.
 
850
 
 
851
    takes_args = ['filename?']
 
852
    takes_options = [Option('forward', 
 
853
                            help='show from oldest to newest'),
 
854
                     'timezone', 'verbose', 
 
855
                     'show-ids', 'revision',
 
856
                     Option('line', help='format with one line per revision'),
 
857
                     'long', 
 
858
                     Option('message',
 
859
                            help='show revisions whose message matches this regexp',
 
860
                            type=str),
 
861
                     Option('short', help='use moderately short format'),
 
862
                     ]
 
863
    @display_command
 
864
    def run(self, filename=None, timezone='original',
 
865
            verbose=False,
 
866
            show_ids=False,
 
867
            forward=False,
 
868
            revision=None,
 
869
            message=None,
 
870
            long=False,
 
871
            short=False,
 
872
            line=False):
 
873
        from bzrlib.log import log_formatter, show_log
 
874
        import codecs
 
875
        assert message is None or isinstance(message, basestring), \
 
876
            "invalid message argument %r" % message
 
877
        direction = (forward and 'forward') or 'reverse'
 
878
        
 
879
        if filename:
 
880
            b, fp = Branch.open_containing(filename)
 
881
            if fp != '':
 
882
                try:
 
883
                    inv = b.working_tree().read_working_inventory()
 
884
                except NoWorkingTree:
 
885
                    inv = b.get_inventory(b.last_revision())
 
886
                file_id = inv.path2id(fp)
 
887
            else:
 
888
                file_id = None  # points to branch root
 
889
        else:
 
890
            b, relpath = Branch.open_containing('.')
 
891
            file_id = None
 
892
 
 
893
        if revision is None:
 
894
            rev1 = None
 
895
            rev2 = None
 
896
        elif len(revision) == 1:
 
897
            rev1 = rev2 = revision[0].in_history(b).revno
 
898
        elif len(revision) == 2:
 
899
            rev1 = revision[0].in_history(b).revno
 
900
            rev2 = revision[1].in_history(b).revno
 
901
        else:
 
902
            raise BzrCommandError('bzr log --revision takes one or two values.')
 
903
 
 
904
        # By this point, the revision numbers are converted to the +ve
 
905
        # form if they were supplied in the -ve form, so we can do
 
906
        # this comparison in relative safety
 
907
        if rev1 > rev2:
 
908
            (rev2, rev1) = (rev1, rev2)
 
909
 
 
910
        mutter('encoding log as %r', bzrlib.user_encoding)
 
911
 
 
912
        # use 'replace' so that we don't abort if trying to write out
 
913
        # in e.g. the default C locale.
 
914
        outf = codecs.getwriter(bzrlib.user_encoding)(sys.stdout, errors='replace')
 
915
 
 
916
        log_format = 'long'
 
917
        if short:
 
918
            log_format = 'short'
 
919
        if line:
 
920
            log_format = 'line'
 
921
        lf = log_formatter(log_format,
 
922
                           show_ids=show_ids,
 
923
                           to_file=outf,
 
924
                           show_timezone=timezone)
 
925
 
 
926
        show_log(b,
 
927
                 lf,
 
928
                 file_id,
 
929
                 verbose=verbose,
 
930
                 direction=direction,
 
931
                 start_revision=rev1,
 
932
                 end_revision=rev2,
 
933
                 search=message)
 
934
 
 
935
 
 
936
 
 
937
class cmd_touching_revisions(Command):
 
938
    """Return revision-ids which affected a particular file.
 
939
 
 
940
    A more user-friendly interface is "bzr log FILE"."""
 
941
    hidden = True
 
942
    takes_args = ["filename"]
 
943
    @display_command
 
944
    def run(self, filename):
 
945
        b, relpath = Branch.open_containing(filename)[0]
 
946
        inv = b.working_tree().read_working_inventory()
 
947
        file_id = inv.path2id(relpath)
 
948
        for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
 
949
            print "%6d %s" % (revno, what)
 
950
 
 
951
 
 
952
class cmd_ls(Command):
 
953
    """List files in a tree.
 
954
    """
 
955
    # TODO: Take a revision or remote path and list that tree instead.
 
956
    hidden = True
 
957
    takes_options = ['verbose', 'revision',
 
958
                     Option('non-recursive',
 
959
                            help='don\'t recurse into sub-directories'),
 
960
                     Option('from-root',
 
961
                            help='Print all paths from the root of the branch.'),
 
962
                     Option('unknown', help='Print unknown files'),
 
963
                     Option('versioned', help='Print versioned files'),
 
964
                     Option('ignored', help='Print ignored files'),
 
965
 
 
966
                     Option('null', help='Null separate the files'),
 
967
                    ]
 
968
    @display_command
 
969
    def run(self, revision=None, verbose=False, 
 
970
            non_recursive=False, from_root=False,
 
971
            unknown=False, versioned=False, ignored=False,
 
972
            null=False):
 
973
 
 
974
        if verbose and null:
 
975
            raise BzrCommandError('Cannot set both --verbose and --null')
 
976
        all = not (unknown or versioned or ignored)
 
977
 
 
978
        selection = {'I':ignored, '?':unknown, 'V':versioned}
 
979
 
 
980
        b, relpath = Branch.open_containing('.')
 
981
        if from_root:
 
982
            relpath = ''
 
983
        elif relpath:
 
984
            relpath += '/'
 
985
        if revision == None:
 
986
            tree = b.working_tree()
 
987
        else:
 
988
            tree = b.revision_tree(revision[0].in_history(b).rev_id)
 
989
        for fp, fc, kind, fid, entry in tree.list_files():
 
990
            if fp.startswith(relpath):
 
991
                fp = fp[len(relpath):]
 
992
                if non_recursive and '/' in fp:
 
993
                    continue
 
994
                if not all and not selection[fc]:
 
995
                    continue
 
996
                if verbose:
 
997
                    kindch = entry.kind_character()
 
998
                    print '%-8s %s%s' % (fc, fp, kindch)
 
999
                elif null:
 
1000
                    sys.stdout.write(fp)
 
1001
                    sys.stdout.write('\0')
 
1002
                    sys.stdout.flush()
 
1003
                else:
 
1004
                    print fp
 
1005
 
 
1006
 
 
1007
 
 
1008
class cmd_unknowns(Command):
 
1009
    """List unknown files."""
 
1010
    @display_command
 
1011
    def run(self):
 
1012
        from bzrlib.osutils import quotefn
 
1013
        for f in Branch.open_containing('.')[0].unknowns():
 
1014
            print quotefn(f)
 
1015
 
 
1016
 
 
1017
 
 
1018
class cmd_ignore(Command):
 
1019
    """Ignore a command or pattern.
 
1020
 
 
1021
    To remove patterns from the ignore list, edit the .bzrignore file.
 
1022
 
 
1023
    If the pattern contains a slash, it is compared to the whole path
 
1024
    from the branch root.  Otherwise, it is compared to only the last
 
1025
    component of the path.  To match a file only in the root directory,
 
1026
    prepend './'.
 
1027
 
 
1028
    Ignore patterns are case-insensitive on case-insensitive systems.
 
1029
 
 
1030
    Note: wildcards must be quoted from the shell on Unix.
 
1031
 
 
1032
    examples:
 
1033
        bzr ignore ./Makefile
 
1034
        bzr ignore '*.class'
 
1035
    """
 
1036
    # TODO: Complain if the filename is absolute
 
1037
    takes_args = ['name_pattern']
 
1038
    
 
1039
    def run(self, name_pattern):
 
1040
        from bzrlib.atomicfile import AtomicFile
 
1041
        import os.path
 
1042
 
 
1043
        b, relpath = Branch.open_containing('.')
 
1044
        ifn = b.abspath('.bzrignore')
 
1045
 
 
1046
        if os.path.exists(ifn):
 
1047
            f = open(ifn, 'rt')
 
1048
            try:
 
1049
                igns = f.read().decode('utf-8')
 
1050
            finally:
 
1051
                f.close()
 
1052
        else:
 
1053
            igns = ''
 
1054
 
 
1055
        # TODO: If the file already uses crlf-style termination, maybe
 
1056
        # we should use that for the newly added lines?
 
1057
 
 
1058
        if igns and igns[-1] != '\n':
 
1059
            igns += '\n'
 
1060
        igns += name_pattern + '\n'
 
1061
 
 
1062
        try:
 
1063
            f = AtomicFile(ifn, 'wt')
 
1064
            f.write(igns.encode('utf-8'))
 
1065
            f.commit()
 
1066
        finally:
 
1067
            f.close()
 
1068
 
 
1069
        inv = b.working_tree().inventory
 
1070
        if inv.path2id('.bzrignore'):
 
1071
            mutter('.bzrignore is already versioned')
 
1072
        else:
 
1073
            mutter('need to make new .bzrignore file versioned')
 
1074
            b.add(['.bzrignore'])
 
1075
 
 
1076
 
 
1077
 
 
1078
class cmd_ignored(Command):
 
1079
    """List ignored files and the patterns that matched them.
 
1080
 
 
1081
    See also: bzr ignore"""
 
1082
    @display_command
 
1083
    def run(self):
 
1084
        tree = Branch.open_containing('.')[0].working_tree()
 
1085
        for path, file_class, kind, file_id, entry in tree.list_files():
 
1086
            if file_class != 'I':
 
1087
                continue
 
1088
            ## XXX: Slightly inefficient since this was already calculated
 
1089
            pat = tree.is_ignored(path)
 
1090
            print '%-50s %s' % (path, pat)
 
1091
 
 
1092
 
 
1093
class cmd_lookup_revision(Command):
 
1094
    """Lookup the revision-id from a revision-number
 
1095
 
 
1096
    example:
 
1097
        bzr lookup-revision 33
 
1098
    """
 
1099
    hidden = True
 
1100
    takes_args = ['revno']
 
1101
    
 
1102
    @display_command
 
1103
    def run(self, revno):
 
1104
        try:
 
1105
            revno = int(revno)
 
1106
        except ValueError:
 
1107
            raise BzrCommandError("not a valid revision-number: %r" % revno)
 
1108
 
 
1109
        print Branch.open_containing('.')[0].get_rev_id(revno)
 
1110
 
 
1111
 
 
1112
class cmd_export(Command):
 
1113
    """Export past revision to destination directory.
 
1114
 
 
1115
    If no revision is specified this exports the last committed revision.
 
1116
 
 
1117
    Format may be an "exporter" name, such as tar, tgz, tbz2.  If none is
 
1118
    given, try to find the format with the extension. If no extension
 
1119
    is found exports to a directory (equivalent to --format=dir).
 
1120
 
 
1121
    Root may be the top directory for tar, tgz and tbz2 formats. If none
 
1122
    is given, the top directory will be the root name of the file.
 
1123
 
 
1124
    Note: export of tree with non-ascii filenames to zip is not supported.
 
1125
 
 
1126
    Supported formats       Autodetected by extension
 
1127
    -----------------       -------------------------
 
1128
         dir                            -
 
1129
         tar                          .tar
 
1130
         tbz2                    .tar.bz2, .tbz2
 
1131
         tgz                      .tar.gz, .tgz
 
1132
         zip                          .zip
 
1133
    """
 
1134
    takes_args = ['dest']
 
1135
    takes_options = ['revision', 'format', 'root']
 
1136
    def run(self, dest, revision=None, format=None, root=None):
 
1137
        import os.path
 
1138
        from bzrlib.export import export
 
1139
        b = Branch.open_containing('.')[0]
 
1140
        if revision is None:
 
1141
            rev_id = b.last_revision()
 
1142
        else:
 
1143
            if len(revision) != 1:
 
1144
                raise BzrError('bzr export --revision takes exactly 1 argument')
 
1145
            rev_id = revision[0].in_history(b).rev_id
 
1146
        t = b.revision_tree(rev_id)
 
1147
        try:
 
1148
            export(t, dest, format, root)
 
1149
        except errors.NoSuchExportFormat, e:
 
1150
            raise BzrCommandError('Unsupported export format: %s' % e.format)
 
1151
 
 
1152
 
 
1153
class cmd_cat(Command):
 
1154
    """Write a file's text from a previous revision."""
 
1155
 
 
1156
    takes_options = ['revision']
 
1157
    takes_args = ['filename']
 
1158
 
 
1159
    @display_command
 
1160
    def run(self, filename, revision=None):
 
1161
        if revision is None:
 
1162
            raise BzrCommandError("bzr cat requires a revision number")
 
1163
        elif len(revision) != 1:
 
1164
            raise BzrCommandError("bzr cat --revision takes exactly one number")
 
1165
        b, relpath = Branch.open_containing(filename)
 
1166
        b.print_file(relpath, revision[0].in_history(b).revno)
 
1167
 
 
1168
 
 
1169
class cmd_local_time_offset(Command):
 
1170
    """Show the offset in seconds from GMT to local time."""
 
1171
    hidden = True    
 
1172
    @display_command
 
1173
    def run(self):
 
1174
        print bzrlib.osutils.local_time_offset()
 
1175
 
 
1176
 
 
1177
 
 
1178
class cmd_commit(Command):
 
1179
    """Commit changes into a new revision.
 
1180
    
 
1181
    If no arguments are given, the entire tree is committed.
 
1182
 
 
1183
    If selected files are specified, only changes to those files are
 
1184
    committed.  If a directory is specified then the directory and everything 
 
1185
    within it is committed.
 
1186
 
 
1187
    A selected-file commit may fail in some cases where the committed
 
1188
    tree would be invalid, such as trying to commit a file in a
 
1189
    newly-added directory that is not itself committed.
 
1190
    """
 
1191
    # TODO: Run hooks on tree to-be-committed, and after commit.
 
1192
 
 
1193
    # TODO: Strict commit that fails if there are deleted files.
 
1194
    #       (what does "deleted files" mean ??)
 
1195
 
 
1196
    # TODO: Give better message for -s, --summary, used by tla people
 
1197
 
 
1198
    # XXX: verbose currently does nothing
 
1199
 
 
1200
    takes_args = ['selected*']
 
1201
    takes_options = ['message', 'verbose', 
 
1202
                     Option('unchanged',
 
1203
                            help='commit even if nothing has changed'),
 
1204
                     Option('file', type=str, 
 
1205
                            argname='msgfile',
 
1206
                            help='file containing commit message'),
 
1207
                     Option('strict',
 
1208
                            help="refuse to commit if there are unknown "
 
1209
                            "files in the working tree."),
 
1210
                     ]
 
1211
    aliases = ['ci', 'checkin']
 
1212
 
 
1213
    def run(self, message=None, file=None, verbose=True, selected_list=None,
 
1214
            unchanged=False, strict=False):
 
1215
        from bzrlib.errors import (PointlessCommit, ConflictsInTree,
 
1216
                StrictCommitFailed)
 
1217
        from bzrlib.msgeditor import edit_commit_message
 
1218
        from bzrlib.status import show_status
 
1219
        from cStringIO import StringIO
 
1220
 
 
1221
        b, selected_list = branch_files(selected_list)
 
1222
        if message is None and not file:
 
1223
            catcher = StringIO()
 
1224
            show_status(b, specific_files=selected_list,
 
1225
                        to_file=catcher)
 
1226
            message = edit_commit_message(catcher.getvalue())
 
1227
 
 
1228
            if message is None:
 
1229
                raise BzrCommandError("please specify a commit message"
 
1230
                                      " with either --message or --file")
 
1231
        elif message and file:
 
1232
            raise BzrCommandError("please specify either --message or --file")
 
1233
        
 
1234
        if file:
 
1235
            import codecs
 
1236
            message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
 
1237
 
 
1238
        if message == "":
 
1239
                raise BzrCommandError("empty commit message specified")
 
1240
            
 
1241
        try:
 
1242
            b.working_tree().commit(message, specific_files=selected_list,
 
1243
                     allow_pointless=unchanged, strict=strict)
 
1244
        except PointlessCommit:
 
1245
            # FIXME: This should really happen before the file is read in;
 
1246
            # perhaps prepare the commit; get the message; then actually commit
 
1247
            raise BzrCommandError("no changes to commit",
 
1248
                                  ["use --unchanged to commit anyhow"])
 
1249
        except ConflictsInTree:
 
1250
            raise BzrCommandError("Conflicts detected in working tree.  "
 
1251
                'Use "bzr conflicts" to list, "bzr resolve FILE" to resolve.')
 
1252
        except StrictCommitFailed:
 
1253
            raise BzrCommandError("Commit refused because there are unknown "
 
1254
                                  "files in the working tree.")
 
1255
 
 
1256
 
 
1257
class cmd_check(Command):
 
1258
    """Validate consistency of branch history.
 
1259
 
 
1260
    This command checks various invariants about the branch storage to
 
1261
    detect data corruption or bzr bugs.
 
1262
    """
 
1263
    takes_args = ['dir?']
 
1264
    takes_options = ['verbose']
 
1265
 
 
1266
    def run(self, dir='.', verbose=False):
 
1267
        from bzrlib.check import check
 
1268
        check(Branch.open_containing(dir)[0], verbose)
 
1269
 
 
1270
 
 
1271
class cmd_scan_cache(Command):
 
1272
    hidden = True
 
1273
    def run(self):
 
1274
        from bzrlib.hashcache import HashCache
 
1275
 
 
1276
        c = HashCache('.')
 
1277
        c.read()
 
1278
        c.scan()
 
1279
            
 
1280
        print '%6d stats' % c.stat_count
 
1281
        print '%6d in hashcache' % len(c._cache)
 
1282
        print '%6d files removed from cache' % c.removed_count
 
1283
        print '%6d hashes updated' % c.update_count
 
1284
        print '%6d files changed too recently to cache' % c.danger_count
 
1285
 
 
1286
        if c.needs_write:
 
1287
            c.write()
 
1288
            
 
1289
 
 
1290
 
 
1291
class cmd_upgrade(Command):
 
1292
    """Upgrade branch storage to current format.
 
1293
 
 
1294
    The check command or bzr developers may sometimes advise you to run
 
1295
    this command.
 
1296
 
 
1297
    This version of this command upgrades from the full-text storage
 
1298
    used by bzr 0.0.8 and earlier to the weave format (v5).
 
1299
    """
 
1300
    takes_args = ['dir?']
 
1301
 
 
1302
    def run(self, dir='.'):
 
1303
        from bzrlib.upgrade import upgrade
 
1304
        upgrade(dir)
 
1305
 
 
1306
 
 
1307
class cmd_whoami(Command):
 
1308
    """Show bzr user id."""
 
1309
    takes_options = ['email']
 
1310
    
 
1311
    @display_command
 
1312
    def run(self, email=False):
 
1313
        try:
 
1314
            b = bzrlib.branch.Branch.open_containing('.')[0]
 
1315
            config = bzrlib.config.BranchConfig(b)
 
1316
        except NotBranchError:
 
1317
            config = bzrlib.config.GlobalConfig()
 
1318
        
 
1319
        if email:
 
1320
            print config.user_email()
 
1321
        else:
 
1322
            print config.username()
 
1323
 
 
1324
class cmd_nick(Command):
 
1325
    """\
 
1326
    Print or set the branch nickname.  
 
1327
    If unset, the tree root directory name is used as the nickname
 
1328
    To print the current nickname, execute with no argument.  
 
1329
    """
 
1330
    takes_args = ['nickname?']
 
1331
    def run(self, nickname=None):
 
1332
        branch = Branch.open_containing('.')[0]
 
1333
        if nickname is None:
 
1334
            self.printme(branch)
 
1335
        else:
 
1336
            branch.nick = nickname
 
1337
 
 
1338
    @display_command
 
1339
    def printme(self, branch):
 
1340
        print branch.nick 
 
1341
 
 
1342
class cmd_selftest(Command):
 
1343
    """Run internal test suite.
 
1344
    
 
1345
    This creates temporary test directories in the working directory,
 
1346
    but not existing data is affected.  These directories are deleted
 
1347
    if the tests pass, or left behind to help in debugging if they
 
1348
    fail and --keep-output is specified.
 
1349
    
 
1350
    If arguments are given, they are regular expressions that say
 
1351
    which tests should run.
 
1352
    """
 
1353
    # TODO: --list should give a list of all available tests
 
1354
    hidden = True
 
1355
    takes_args = ['testspecs*']
 
1356
    takes_options = ['verbose', 
 
1357
                     Option('one', help='stop when one test fails'),
 
1358
                     Option('keep-output', 
 
1359
                            help='keep output directories when tests fail')
 
1360
                    ]
 
1361
 
 
1362
    def run(self, testspecs_list=None, verbose=False, one=False,
 
1363
            keep_output=False):
 
1364
        import bzrlib.ui
 
1365
        from bzrlib.selftest import selftest
 
1366
        # we don't want progress meters from the tests to go to the
 
1367
        # real output; and we don't want log messages cluttering up
 
1368
        # the real logs.
 
1369
        save_ui = bzrlib.ui.ui_factory
 
1370
        bzrlib.trace.info('running tests...')
 
1371
        try:
 
1372
            bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
 
1373
            if testspecs_list is not None:
 
1374
                pattern = '|'.join(testspecs_list)
 
1375
            else:
 
1376
                pattern = ".*"
 
1377
            result = selftest(verbose=verbose, 
 
1378
                              pattern=pattern,
 
1379
                              stop_on_failure=one, 
 
1380
                              keep_output=keep_output)
 
1381
            if result:
 
1382
                bzrlib.trace.info('tests passed')
 
1383
            else:
 
1384
                bzrlib.trace.info('tests failed')
 
1385
            return int(not result)
 
1386
        finally:
 
1387
            bzrlib.ui.ui_factory = save_ui
 
1388
 
 
1389
 
 
1390
def show_version():
 
1391
    print "bzr (bazaar-ng) %s" % bzrlib.__version__
 
1392
    # is bzrlib itself in a branch?
 
1393
    bzrrev = bzrlib.get_bzr_revision()
 
1394
    if bzrrev:
 
1395
        print "  (bzr checkout, revision %d {%s})" % bzrrev
 
1396
    print bzrlib.__copyright__
 
1397
    print "http://bazaar-ng.org/"
 
1398
    print
 
1399
    print "bzr comes with ABSOLUTELY NO WARRANTY.  bzr is free software, and"
 
1400
    print "you may use, modify and redistribute it under the terms of the GNU"
 
1401
    print "General Public License version 2 or later."
 
1402
 
 
1403
 
 
1404
class cmd_version(Command):
 
1405
    """Show version of bzr."""
 
1406
    @display_command
 
1407
    def run(self):
 
1408
        show_version()
 
1409
 
 
1410
class cmd_rocks(Command):
 
1411
    """Statement of optimism."""
 
1412
    hidden = True
 
1413
    @display_command
 
1414
    def run(self):
 
1415
        print "it sure does!"
 
1416
 
 
1417
 
 
1418
class cmd_find_merge_base(Command):
 
1419
    """Find and print a base revision for merging two branches.
 
1420
    """
 
1421
    # TODO: Options to specify revisions on either side, as if
 
1422
    #       merging only part of the history.
 
1423
    takes_args = ['branch', 'other']
 
1424
    hidden = True
 
1425
    
 
1426
    @display_command
 
1427
    def run(self, branch, other):
 
1428
        from bzrlib.revision import common_ancestor, MultipleRevisionSources
 
1429
        
 
1430
        branch1 = Branch.open_containing(branch)[0]
 
1431
        branch2 = Branch.open_containing(other)[0]
 
1432
 
 
1433
        history_1 = branch1.revision_history()
 
1434
        history_2 = branch2.revision_history()
 
1435
 
 
1436
        last1 = branch1.last_revision()
 
1437
        last2 = branch2.last_revision()
 
1438
 
 
1439
        source = MultipleRevisionSources(branch1, branch2)
 
1440
        
 
1441
        base_rev_id = common_ancestor(last1, last2, source)
 
1442
 
 
1443
        print 'merge base is revision %s' % base_rev_id
 
1444
        
 
1445
        return
 
1446
 
 
1447
        if base_revno is None:
 
1448
            raise bzrlib.errors.UnrelatedBranches()
 
1449
 
 
1450
        print ' r%-6d in %s' % (base_revno, branch)
 
1451
 
 
1452
        other_revno = branch2.revision_id_to_revno(base_revid)
 
1453
        
 
1454
        print ' r%-6d in %s' % (other_revno, other)
 
1455
 
 
1456
 
 
1457
 
 
1458
class cmd_merge(Command):
 
1459
    """Perform a three-way merge.
 
1460
    
 
1461
    The branch is the branch you will merge from.  By default, it will
 
1462
    merge the latest revision.  If you specify a revision, that
 
1463
    revision will be merged.  If you specify two revisions, the first
 
1464
    will be used as a BASE, and the second one as OTHER.  Revision
 
1465
    numbers are always relative to the specified branch.
 
1466
 
 
1467
    By default bzr will try to merge in all new work from the other
 
1468
    branch, automatically determining an appropriate base.  If this
 
1469
    fails, you may need to give an explicit base.
 
1470
    
 
1471
    Examples:
 
1472
 
 
1473
    To merge the latest revision from bzr.dev
 
1474
    bzr merge ../bzr.dev
 
1475
 
 
1476
    To merge changes up to and including revision 82 from bzr.dev
 
1477
    bzr merge -r 82 ../bzr.dev
 
1478
 
 
1479
    To merge the changes introduced by 82, without previous changes:
 
1480
    bzr merge -r 81..82 ../bzr.dev
 
1481
    
 
1482
    merge refuses to run if there are any uncommitted changes, unless
 
1483
    --force is given.
 
1484
    """
 
1485
    takes_args = ['branch?']
 
1486
    takes_options = ['revision', 'force', 'merge-type', 'reprocess',
 
1487
                     Option('show-base', help="Show base revision text in "
 
1488
                            "conflicts")]
 
1489
 
 
1490
    def run(self, branch=None, revision=None, force=False, merge_type=None,
 
1491
            show_base=False, reprocess=False):
 
1492
        from bzrlib.merge import merge
 
1493
        from bzrlib.merge_core import ApplyMerge3
 
1494
        if merge_type is None:
 
1495
            merge_type = ApplyMerge3
 
1496
        if branch is None:
 
1497
            branch = Branch.open_containing('.')[0].get_parent()
 
1498
            if branch is None:
 
1499
                raise BzrCommandError("No merge location known or specified.")
 
1500
            else:
 
1501
                print "Using saved location: %s" % branch 
 
1502
        if revision is None or len(revision) < 1:
 
1503
            base = [None, None]
 
1504
            other = [branch, -1]
 
1505
        else:
 
1506
            if len(revision) == 1:
 
1507
                base = [None, None]
 
1508
                other_branch = Branch.open_containing(branch)[0]
 
1509
                revno = revision[0].in_history(other_branch).revno
 
1510
                other = [branch, revno]
 
1511
            else:
 
1512
                assert len(revision) == 2
 
1513
                if None in revision:
 
1514
                    raise BzrCommandError(
 
1515
                        "Merge doesn't permit that revision specifier.")
 
1516
                b = Branch.open_containing(branch)[0]
 
1517
 
 
1518
                base = [branch, revision[0].in_history(b).revno]
 
1519
                other = [branch, revision[1].in_history(b).revno]
 
1520
 
 
1521
        try:
 
1522
            conflict_count = merge(other, base, check_clean=(not force),
 
1523
                                   merge_type=merge_type, reprocess=reprocess,
 
1524
                                   show_base=show_base)
 
1525
            if conflict_count != 0:
 
1526
                return 1
 
1527
            else:
 
1528
                return 0
 
1529
        except bzrlib.errors.AmbiguousBase, e:
 
1530
            m = ("sorry, bzr can't determine the right merge base yet\n"
 
1531
                 "candidates are:\n  "
 
1532
                 + "\n  ".join(e.bases)
 
1533
                 + "\n"
 
1534
                 "please specify an explicit base with -r,\n"
 
1535
                 "and (if you want) report this to the bzr developers\n")
 
1536
            log_error(m)
 
1537
 
 
1538
 
 
1539
class cmd_remerge(Command):
 
1540
    """Redo a merge.
 
1541
    """
 
1542
    takes_args = ['file*']
 
1543
    takes_options = ['merge-type', 'reprocess',
 
1544
                     Option('show-base', help="Show base revision text in "
 
1545
                            "conflicts")]
 
1546
 
 
1547
    def run(self, file_list=None, merge_type=None, show_base=False,
 
1548
            reprocess=False):
 
1549
        from bzrlib.merge import merge_inner, transform_tree
 
1550
        from bzrlib.merge_core import ApplyMerge3
 
1551
        if merge_type is None:
 
1552
            merge_type = ApplyMerge3
 
1553
        b, file_list = branch_files(file_list)
 
1554
        b.lock_write()
 
1555
        try:
 
1556
            pending_merges = b.working_tree().pending_merges() 
 
1557
            if len(pending_merges) != 1:
 
1558
                raise BzrCommandError("Sorry, remerge only works after normal"
 
1559
                                      + " merges.  Not cherrypicking or"
 
1560
                                      + "multi-merges.")
 
1561
            this_tree = b.working_tree()
 
1562
            base_revision = common_ancestor(b.last_revision(), 
 
1563
                                            pending_merges[0], b)
 
1564
            base_tree = b.revision_tree(base_revision)
 
1565
            other_tree = b.revision_tree(pending_merges[0])
 
1566
            interesting_ids = None
 
1567
            if file_list is not None:
 
1568
                interesting_ids = set()
 
1569
                for filename in file_list:
 
1570
                    file_id = this_tree.path2id(filename)
 
1571
                    interesting_ids.add(file_id)
 
1572
                    if this_tree.kind(file_id) != "directory":
 
1573
                        continue
 
1574
                    
 
1575
                    for name, ie in this_tree.inventory.iter_entries(file_id):
 
1576
                        interesting_ids.add(ie.file_id)
 
1577
            transform_tree(this_tree, b.basis_tree(), interesting_ids)
 
1578
            if file_list is None:
 
1579
                restore_files = list(this_tree.iter_conflicts())
 
1580
            else:
 
1581
                restore_files = file_list
 
1582
            for filename in restore_files:
 
1583
                try:
 
1584
                    restore(this_tree.abspath(filename))
 
1585
                except NotConflicted:
 
1586
                    pass
 
1587
            conflicts =  merge_inner(b, other_tree, base_tree, 
 
1588
                                     interesting_ids = interesting_ids, 
 
1589
                                     other_rev_id=pending_merges[0], 
 
1590
                                     merge_type=merge_type, 
 
1591
                                     show_base=show_base,
 
1592
                                     reprocess=reprocess)
 
1593
        finally:
 
1594
            b.unlock()
 
1595
        if conflicts > 0:
 
1596
            return 1
 
1597
        else:
 
1598
            return 0
 
1599
 
 
1600
class cmd_revert(Command):
 
1601
    """Reverse all changes since the last commit.
 
1602
 
 
1603
    Only versioned files are affected.  Specify filenames to revert only 
 
1604
    those files.  By default, any files that are changed will be backed up
 
1605
    first.  Backup files have a '~' appended to their name.
 
1606
    """
 
1607
    takes_options = ['revision', 'no-backup']
 
1608
    takes_args = ['file*']
 
1609
    aliases = ['merge-revert']
 
1610
 
 
1611
    def run(self, revision=None, no_backup=False, file_list=None):
 
1612
        from bzrlib.merge import merge_inner
 
1613
        from bzrlib.commands import parse_spec
 
1614
        if file_list is not None:
 
1615
            if len(file_list) == 0:
 
1616
                raise BzrCommandError("No files specified")
 
1617
        else:
 
1618
            file_list = []
 
1619
        if revision is None:
 
1620
            revno = -1
 
1621
            b = Branch.open_containing('.')[0]
 
1622
            rev_id = b.last_revision()
 
1623
        elif len(revision) != 1:
 
1624
            raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
 
1625
        else:
 
1626
            b, file_list = branch_files(file_list)
 
1627
            rev_id = revision[0].in_history(b).rev_id
 
1628
        b.working_tree().revert(file_list, b.revision_tree(rev_id),
 
1629
                                not no_backup)
 
1630
 
 
1631
 
 
1632
class cmd_assert_fail(Command):
 
1633
    """Test reporting of assertion failures"""
 
1634
    hidden = True
 
1635
    def run(self):
 
1636
        assert False, "always fails"
 
1637
 
 
1638
 
 
1639
class cmd_help(Command):
 
1640
    """Show help on a command or other topic.
 
1641
 
 
1642
    For a list of all available commands, say 'bzr help commands'."""
 
1643
    takes_options = ['long']
 
1644
    takes_args = ['topic?']
 
1645
    aliases = ['?']
 
1646
    
 
1647
    @display_command
 
1648
    def run(self, topic=None, long=False):
 
1649
        import help
 
1650
        if topic is None and long:
 
1651
            topic = "commands"
 
1652
        help.help(topic)
 
1653
 
 
1654
 
 
1655
class cmd_shell_complete(Command):
 
1656
    """Show appropriate completions for context.
 
1657
 
 
1658
    For a list of all available commands, say 'bzr shell-complete'."""
 
1659
    takes_args = ['context?']
 
1660
    aliases = ['s-c']
 
1661
    hidden = True
 
1662
    
 
1663
    @display_command
 
1664
    def run(self, context=None):
 
1665
        import shellcomplete
 
1666
        shellcomplete.shellcomplete(context)
 
1667
 
 
1668
 
 
1669
class cmd_fetch(Command):
 
1670
    """Copy in history from another branch but don't merge it.
 
1671
 
 
1672
    This is an internal method used for pull and merge."""
 
1673
    hidden = True
 
1674
    takes_args = ['from_branch', 'to_branch']
 
1675
    def run(self, from_branch, to_branch):
 
1676
        from bzrlib.fetch import Fetcher
 
1677
        from bzrlib.branch import Branch
 
1678
        from_b = Branch.open(from_branch)
 
1679
        to_b = Branch.open(to_branch)
 
1680
        from_b.lock_read()
 
1681
        try:
 
1682
            to_b.lock_write()
 
1683
            try:
 
1684
                Fetcher(to_b, from_b)
 
1685
            finally:
 
1686
                to_b.unlock()
 
1687
        finally:
 
1688
            from_b.unlock()
 
1689
 
 
1690
 
 
1691
class cmd_missing(Command):
 
1692
    """What is missing in this branch relative to other branch.
 
1693
    """
 
1694
    # TODO: rewrite this in terms of ancestry so that it shows only
 
1695
    # unmerged things
 
1696
    
 
1697
    takes_args = ['remote?']
 
1698
    aliases = ['mis', 'miss']
 
1699
    # We don't have to add quiet to the list, because 
 
1700
    # unknown options are parsed as booleans
 
1701
    takes_options = ['verbose', 'quiet']
 
1702
 
 
1703
    @display_command
 
1704
    def run(self, remote=None, verbose=False, quiet=False):
 
1705
        from bzrlib.errors import BzrCommandError
 
1706
        from bzrlib.missing import show_missing
 
1707
 
 
1708
        if verbose and quiet:
 
1709
            raise BzrCommandError('Cannot pass both quiet and verbose')
 
1710
 
 
1711
        b = Branch.open_containing('.')[0]
 
1712
        parent = b.get_parent()
 
1713
        if remote is None:
 
1714
            if parent is None:
 
1715
                raise BzrCommandError("No missing location known or specified.")
 
1716
            else:
 
1717
                if not quiet:
 
1718
                    print "Using last location: %s" % parent
 
1719
                remote = parent
 
1720
        elif parent is None:
 
1721
            # We only update parent if it did not exist, missing
 
1722
            # should not change the parent
 
1723
            b.set_parent(remote)
 
1724
        br_remote = Branch.open_containing(remote)[0]
 
1725
        return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
 
1726
 
 
1727
 
 
1728
class cmd_plugins(Command):
 
1729
    """List plugins"""
 
1730
    hidden = True
 
1731
    @display_command
 
1732
    def run(self):
 
1733
        import bzrlib.plugin
 
1734
        from inspect import getdoc
 
1735
        for plugin in bzrlib.plugin.all_plugins:
 
1736
            if hasattr(plugin, '__path__'):
 
1737
                print plugin.__path__[0]
 
1738
            elif hasattr(plugin, '__file__'):
 
1739
                print plugin.__file__
 
1740
            else:
 
1741
                print `plugin`
 
1742
                
 
1743
            d = getdoc(plugin)
 
1744
            if d:
 
1745
                print '\t', d.split('\n')[0]
 
1746
 
 
1747
 
 
1748
class cmd_testament(Command):
 
1749
    """Show testament (signing-form) of a revision."""
 
1750
    takes_options = ['revision', 'long']
 
1751
    takes_args = ['branch?']
 
1752
    @display_command
 
1753
    def run(self, branch='.', revision=None, long=False):
 
1754
        from bzrlib.testament import Testament
 
1755
        b = Branch.open_containing(branch)[0]
 
1756
        b.lock_read()
 
1757
        try:
 
1758
            if revision is None:
 
1759
                rev_id = b.last_revision()
 
1760
            else:
 
1761
                rev_id = revision[0].in_history(b).rev_id
 
1762
            t = Testament.from_revision(b, rev_id)
 
1763
            if long:
 
1764
                sys.stdout.writelines(t.as_text_lines())
 
1765
            else:
 
1766
                sys.stdout.write(t.as_short_text())
 
1767
        finally:
 
1768
            b.unlock()
 
1769
 
 
1770
 
 
1771
class cmd_annotate(Command):
 
1772
    """Show the origin of each line in a file.
 
1773
 
 
1774
    This prints out the given file with an annotation on the left side
 
1775
    indicating which revision, author and date introduced the change.
 
1776
 
 
1777
    If the origin is the same for a run of consecutive lines, it is 
 
1778
    shown only at the top, unless the --all option is given.
 
1779
    """
 
1780
    # TODO: annotate directories; showing when each file was last changed
 
1781
    # TODO: annotate a previous version of a file
 
1782
    # TODO: if the working copy is modified, show annotations on that 
 
1783
    #       with new uncommitted lines marked
 
1784
    aliases = ['blame', 'praise']
 
1785
    takes_args = ['filename']
 
1786
    takes_options = [Option('all', help='show annotations on all lines'),
 
1787
                     Option('long', help='show date in annotations'),
 
1788
                     ]
 
1789
 
 
1790
    @display_command
 
1791
    def run(self, filename, all=False, long=False):
 
1792
        from bzrlib.annotate import annotate_file
 
1793
        b, relpath = Branch.open_containing(filename)
 
1794
        b.lock_read()
 
1795
        try:
 
1796
            tree = WorkingTree(b.base, b)
 
1797
            tree = b.revision_tree(b.last_revision())
 
1798
            file_id = tree.inventory.path2id(relpath)
 
1799
            file_version = tree.inventory[file_id].revision
 
1800
            annotate_file(b, file_version, file_id, long, all, sys.stdout)
 
1801
        finally:
 
1802
            b.unlock()
 
1803
 
 
1804
 
 
1805
class cmd_re_sign(Command):
 
1806
    """Create a digital signature for an existing revision."""
 
1807
    # TODO be able to replace existing ones.
 
1808
 
 
1809
    hidden = True # is this right ?
 
1810
    takes_args = ['revision_id?']
 
1811
    takes_options = ['revision']
 
1812
    
 
1813
    def run(self, revision_id=None, revision=None):
 
1814
        import bzrlib.config as config
 
1815
        import bzrlib.gpg as gpg
 
1816
        if revision_id is not None and revision is not None:
 
1817
            raise BzrCommandError('You can only supply one of revision_id or --revision')
 
1818
        if revision_id is None and revision is None:
 
1819
            raise BzrCommandError('You must supply either --revision or a revision_id')
 
1820
        b = Branch.open_containing('.')[0]
 
1821
        gpg_strategy = gpg.GPGStrategy(config.BranchConfig(b))
 
1822
        if revision_id is not None:
 
1823
            b.sign_revision(revision_id, gpg_strategy)
 
1824
        elif revision is not None:
 
1825
            if len(revision) == 1:
 
1826
                revno, rev_id = revision[0].in_history(b)
 
1827
                b.sign_revision(rev_id, gpg_strategy)
 
1828
            elif len(revision) == 2:
 
1829
                # are they both on rh- if so we can walk between them
 
1830
                # might be nice to have a range helper for arbitrary
 
1831
                # revision paths. hmm.
 
1832
                from_revno, from_revid = revision[0].in_history(b)
 
1833
                to_revno, to_revid = revision[1].in_history(b)
 
1834
                if to_revid is None:
 
1835
                    to_revno = b.revno()
 
1836
                if from_revno is None or to_revno is None:
 
1837
                    raise BzrCommandError('Cannot sign a range of non-revision-history revisions')
 
1838
                for revno in range(from_revno, to_revno + 1):
 
1839
                    b.sign_revision(b.get_rev_id(revno), gpg_strategy)
 
1840
            else:
 
1841
                raise BzrCommandError('Please supply either one revision, or a range.')
 
1842
 
 
1843
 
 
1844
# these get imported and then picked up by the scan for cmd_*
 
1845
# TODO: Some more consistent way to split command definitions across files;
 
1846
# we do need to load at least some information about them to know of 
 
1847
# aliases.
 
1848
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore