/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Aaron Bentley
  • Date: 2005-09-22 03:23:22 UTC
  • mto: (1185.1.37)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: aaron.bentley@utoronto.ca-20050922032322-345dab5d05a96893
Fixed non-tree-root bug in branch, revert, merge

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
 
 
18
import sys
 
19
import os
 
20
 
 
21
import bzrlib
 
22
import bzrlib.trace
 
23
from bzrlib.trace import mutter, note, log_error, warning
 
24
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError
 
25
from bzrlib.branch import Branch
 
26
from bzrlib import BZRDIR
 
27
from bzrlib.commands import Command
 
28
 
 
29
 
 
30
class cmd_status(Command):
 
31
    """Display status summary.
 
32
 
 
33
    This reports on versioned and unknown files, reporting them
 
34
    grouped by state.  Possible states are:
 
35
 
 
36
    added
 
37
        Versioned in the working copy but not in the previous revision.
 
38
 
 
39
    removed
 
40
        Versioned in the previous revision but removed or deleted
 
41
        in the working copy.
 
42
 
 
43
    renamed
 
44
        Path of this file changed from the previous revision;
 
45
        the text may also have changed.  This includes files whose
 
46
        parent directory was renamed.
 
47
 
 
48
    modified
 
49
        Text has changed since the previous revision.
 
50
 
 
51
    unchanged
 
52
        Nothing about this file has changed since the previous revision.
 
53
        Only shown with --all.
 
54
 
 
55
    unknown
 
56
        Not versioned and not matching an ignore pattern.
 
57
 
 
58
    To see ignored files use 'bzr ignored'.  For details in the
 
59
    changes to file texts, use 'bzr diff'.
 
60
 
 
61
    If no arguments are specified, the status of the entire working
 
62
    directory is shown.  Otherwise, only the status of the specified
 
63
    files or directories is reported.  If a directory is given, status
 
64
    is reported for everything inside that directory.
 
65
    """
 
66
    # XXX: FIXME: bzr status should accept a -r option to show changes
 
67
    # relative to a revision, or between revisions
 
68
 
 
69
    takes_args = ['file*']
 
70
    takes_options = ['all', 'show-ids']
 
71
    aliases = ['st', 'stat']
 
72
    
 
73
    def run(self, all=False, show_ids=False, file_list=None):
 
74
        if file_list:
 
75
            b = Branch.open_containing(file_list[0])
 
76
            file_list = [b.relpath(x) for x in file_list]
 
77
            # special case: only one path was given and it's the root
 
78
            # of the branch
 
79
            if file_list == ['']:
 
80
                file_list = None
 
81
        else:
 
82
            b = Branch.open_containing('.')
 
83
            
 
84
        from bzrlib.status import show_status
 
85
        show_status(b, show_unchanged=all, show_ids=show_ids,
 
86
                    specific_files=file_list)
 
87
 
 
88
 
 
89
class cmd_cat_revision(Command):
 
90
    """Write out metadata for a revision.
 
91
    
 
92
    The revision to print can either be specified by a specific
 
93
    revision identifier, or you can use --revision.
 
94
    """
 
95
 
 
96
    hidden = True
 
97
    takes_args = ['revision_id?']
 
98
    takes_options = ['revision']
 
99
    
 
100
    def run(self, revision_id=None, revision=None):
 
101
        from bzrlib.revisionspec import RevisionSpec
 
102
 
 
103
        if revision_id is not None and revision is not None:
 
104
            raise BzrCommandError('You can only supply one of revision_id or --revision')
 
105
        if revision_id is None and revision is None:
 
106
            raise BzrCommandError('You must supply either --revision or a revision_id')
 
107
        b = Branch.open_containing('.')
 
108
        if revision_id is not None:
 
109
            sys.stdout.write(b.get_revision_xml_file(revision_id).read())
 
110
        elif revision is not None:
 
111
            for rev in revision:
 
112
                if rev is None:
 
113
                    raise BzrCommandError('You cannot specify a NULL revision.')
 
114
                revno, rev_id = rev.in_history(b)
 
115
                sys.stdout.write(b.get_revision_xml_file(rev_id).read())
 
116
    
 
117
 
 
118
class cmd_revno(Command):
 
119
    """Show current revision number.
 
120
 
 
121
    This is equal to the number of revisions on this branch."""
 
122
    def run(self):
 
123
        print Branch.open_containing('.').revno()
 
124
 
 
125
 
 
126
class cmd_revision_info(Command):
 
127
    """Show revision number and revision id for a given revision identifier.
 
128
    """
 
129
    hidden = True
 
130
    takes_args = ['revision_info*']
 
131
    takes_options = ['revision']
 
132
    def run(self, revision=None, revision_info_list=[]):
 
133
        from bzrlib.revisionspec import RevisionSpec
 
134
 
 
135
        revs = []
 
136
        if revision is not None:
 
137
            revs.extend(revision)
 
138
        if revision_info_list is not None:
 
139
            for rev in revision_info_list:
 
140
                revs.append(RevisionSpec(rev))
 
141
        if len(revs) == 0:
 
142
            raise BzrCommandError('You must supply a revision identifier')
 
143
 
 
144
        b = Branch.open_containing('.')
 
145
 
 
146
        for rev in revs:
 
147
            revinfo = rev.in_history(b)
 
148
            if revinfo.revno is None:
 
149
                print '     %s' % revinfo.rev_id
 
150
            else:
 
151
                print '%4d %s' % (revinfo.revno, revinfo.rev_id)
 
152
 
 
153
    
 
154
class cmd_add(Command):
 
155
    """Add specified files or directories.
 
156
 
 
157
    In non-recursive mode, all the named items are added, regardless
 
158
    of whether they were previously ignored.  A warning is given if
 
159
    any of the named files are already versioned.
 
160
 
 
161
    In recursive mode (the default), files are treated the same way
 
162
    but the behaviour for directories is different.  Directories that
 
163
    are already versioned do not give a warning.  All directories,
 
164
    whether already versioned or not, are searched for files or
 
165
    subdirectories that are neither versioned or ignored, and these
 
166
    are added.  This search proceeds recursively into versioned
 
167
    directories.  If no names are given '.' is assumed.
 
168
 
 
169
    Therefore simply saying 'bzr add' will version all files that
 
170
    are currently unknown.
 
171
 
 
172
    Adding a file whose parent directory is not versioned will
 
173
    implicitly add the parent, and so on up to the root. This means
 
174
    you should never need to explictly add a directory, they'll just
 
175
    get added when you add a file in the directory.
 
176
    """
 
177
    takes_args = ['file*']
 
178
    takes_options = ['verbose', 'no-recurse']
 
179
    
 
180
    def run(self, file_list, verbose=False, no_recurse=False):
 
181
        # verbose currently has no effect
 
182
        from bzrlib.add import smart_add, add_reporter_print
 
183
        smart_add(file_list, not no_recurse, add_reporter_print)
 
184
 
 
185
 
 
186
 
 
187
class cmd_mkdir(Command):
 
188
    """Create a new versioned directory.
 
189
 
 
190
    This is equivalent to creating the directory and then adding it.
 
191
    """
 
192
    takes_args = ['dir+']
 
193
 
 
194
    def run(self, dir_list):
 
195
        b = None
 
196
        
 
197
        for d in dir_list:
 
198
            os.mkdir(d)
 
199
            if not b:
 
200
                b = Branch.open_containing(d)
 
201
            b.add([d])
 
202
            print 'added', d
 
203
 
 
204
 
 
205
class cmd_relpath(Command):
 
206
    """Show path of a file relative to root"""
 
207
    takes_args = ['filename']
 
208
    hidden = True
 
209
    
 
210
    def run(self, filename):
 
211
        print Branch.open_containing(filename).relpath(filename)
 
212
 
 
213
 
 
214
 
 
215
class cmd_inventory(Command):
 
216
    """Show inventory of the current working copy or a revision."""
 
217
    takes_options = ['revision', 'show-ids']
 
218
    
 
219
    def run(self, revision=None, show_ids=False):
 
220
        b = Branch.open_containing('.')
 
221
        if revision is None:
 
222
            inv = b.read_working_inventory()
 
223
        else:
 
224
            if len(revision) > 1:
 
225
                raise BzrCommandError('bzr inventory --revision takes'
 
226
                    ' exactly one revision identifier')
 
227
            inv = b.get_revision_inventory(revision[0].in_history(b).rev_id)
 
228
 
 
229
        for path, entry in inv.entries():
 
230
            if show_ids:
 
231
                print '%-50s %s' % (path, entry.file_id)
 
232
            else:
 
233
                print path
 
234
 
 
235
 
 
236
class cmd_move(Command):
 
237
    """Move files to a different directory.
 
238
 
 
239
    examples:
 
240
        bzr move *.txt doc
 
241
 
 
242
    The destination must be a versioned directory in the same branch.
 
243
    """
 
244
    takes_args = ['source$', 'dest']
 
245
    def run(self, source_list, dest):
 
246
        b = Branch.open_containing('.')
 
247
 
 
248
        # TODO: glob expansion on windows?
 
249
        b.move([b.relpath(s) for s in source_list], b.relpath(dest))
 
250
 
 
251
 
 
252
class cmd_rename(Command):
 
253
    """Change the name of an entry.
 
254
 
 
255
    examples:
 
256
      bzr rename frob.c frobber.c
 
257
      bzr rename src/frob.c lib/frob.c
 
258
 
 
259
    It is an error if the destination name exists.
 
260
 
 
261
    See also the 'move' command, which moves files into a different
 
262
    directory without changing their name.
 
263
 
 
264
    TODO: Some way to rename multiple files without invoking bzr for each
 
265
    one?"""
 
266
    takes_args = ['from_name', 'to_name']
 
267
    
 
268
    def run(self, from_name, to_name):
 
269
        b = Branch.open_containing('.')
 
270
        b.rename_one(b.relpath(from_name), b.relpath(to_name))
 
271
 
 
272
 
 
273
 
 
274
class cmd_mv(Command):
 
275
    """Move or rename a file.
 
276
 
 
277
    usage:
 
278
        bzr mv OLDNAME NEWNAME
 
279
        bzr mv SOURCE... DESTINATION
 
280
 
 
281
    If the last argument is a versioned directory, all the other names
 
282
    are moved into it.  Otherwise, there must be exactly two arguments
 
283
    and the file is changed to a new name, which must not already exist.
 
284
 
 
285
    Files cannot be moved between branches.
 
286
    """
 
287
    takes_args = ['names*']
 
288
    def run(self, names_list):
 
289
        if len(names_list) < 2:
 
290
            raise BzrCommandError("missing file argument")
 
291
        b = Branch.open_containing(names_list[0])
 
292
 
 
293
        rel_names = [b.relpath(x) for x in names_list]
 
294
        
 
295
        if os.path.isdir(names_list[-1]):
 
296
            # move into existing directory
 
297
            for pair in b.move(rel_names[:-1], rel_names[-1]):
 
298
                print "%s => %s" % pair
 
299
        else:
 
300
            if len(names_list) != 2:
 
301
                raise BzrCommandError('to mv multiple files the destination '
 
302
                                      'must be a versioned directory')
 
303
            b.rename_one(rel_names[0], rel_names[1])
 
304
            print "%s => %s" % (rel_names[0], rel_names[1])
 
305
            
 
306
    
 
307
 
 
308
 
 
309
class cmd_pull(Command):
 
310
    """Pull any changes from another branch into the current one.
 
311
 
 
312
    If the location is omitted, the last-used location will be used.
 
313
    Both the revision history and the working directory will be
 
314
    updated.
 
315
 
 
316
    This command only works on branches that have not diverged.  Branches are
 
317
    considered diverged if both branches have had commits without first
 
318
    pulling from the other.
 
319
 
 
320
    If branches have diverged, you can use 'bzr merge' to pull the text changes
 
321
    from one into the other.
 
322
    """
 
323
    takes_args = ['location?']
 
324
 
 
325
    def run(self, location=None):
 
326
        from bzrlib.merge import merge
 
327
        import tempfile
 
328
        from shutil import rmtree
 
329
        import errno
 
330
        
 
331
        br_to = Branch.open_containing('.')
 
332
        stored_loc = br_to.get_parent()
 
333
        if location is None:
 
334
            if stored_loc is None:
 
335
                raise BzrCommandError("No pull location known or specified.")
 
336
            else:
 
337
                print "Using last location: %s" % stored_loc
 
338
                location = stored_loc
 
339
        cache_root = tempfile.mkdtemp()
 
340
        from bzrlib.errors import DivergedBranches
 
341
        br_from = Branch.open_containing(location)
 
342
        location = br_from.base
 
343
        old_revno = br_to.revno()
 
344
        try:
 
345
            from bzrlib.errors import DivergedBranches
 
346
            br_from = Branch.open(location)
 
347
            br_from.setup_caching(cache_root)
 
348
            location = br_from.base
 
349
            old_revno = br_to.revno()
 
350
            try:
 
351
                br_to.update_revisions(br_from)
 
352
            except DivergedBranches:
 
353
                raise BzrCommandError("These branches have diverged."
 
354
                    "  Try merge.")
 
355
                
 
356
            merge(('.', -1), ('.', old_revno), check_clean=False)
 
357
            if location != stored_loc:
 
358
                br_to.set_parent(location)
 
359
        finally:
 
360
            rmtree(cache_root)
 
361
 
 
362
 
 
363
 
 
364
class cmd_branch(Command):
 
365
    """Create a new copy of a branch.
 
366
 
 
367
    If the TO_LOCATION is omitted, the last component of the FROM_LOCATION will
 
368
    be used.  In other words, "branch ../foo/bar" will attempt to create ./bar.
 
369
 
 
370
    To retrieve the branch as of a particular revision, supply the --revision
 
371
    parameter, as in "branch foo/bar -r 5".
 
372
    """
 
373
    takes_args = ['from_location', 'to_location?']
 
374
    takes_options = ['revision']
 
375
    aliases = ['get', 'clone']
 
376
 
 
377
    def run(self, from_location, to_location=None, revision=None):
 
378
        from bzrlib.branch import copy_branch
 
379
        import tempfile
 
380
        import errno
 
381
        from shutil import rmtree
 
382
        cache_root = tempfile.mkdtemp()
 
383
        try:
 
384
            if revision is None:
 
385
                revision = [None]
 
386
            elif len(revision) > 1:
 
387
                raise BzrCommandError(
 
388
                    'bzr branch --revision takes exactly 1 revision value')
 
389
            try:
 
390
                br_from = Branch.open(from_location)
 
391
            except OSError, e:
 
392
                if e.errno == errno.ENOENT:
 
393
                    raise BzrCommandError('Source location "%s" does not'
 
394
                                          ' exist.' % to_location)
 
395
                else:
 
396
                    raise
 
397
            br_from.setup_caching(cache_root)
 
398
            if len(revision) == 1 and revision[0] is not None:
 
399
                revno = revision[0].in_history(br_from)[0]
 
400
            else:
 
401
                revno = None
 
402
            if to_location is None:
 
403
                to_location = os.path.basename(from_location.rstrip("/\\"))
 
404
            try:
 
405
                os.mkdir(to_location)
 
406
            except OSError, e:
 
407
                if e.errno == errno.EEXIST:
 
408
                    raise BzrCommandError('Target directory "%s" already'
 
409
                                          ' exists.' % to_location)
 
410
                if e.errno == errno.ENOENT:
 
411
                    raise BzrCommandError('Parent of "%s" does not exist.' %
 
412
                                          to_location)
 
413
                else:
 
414
                    raise
 
415
            try:
 
416
                copy_branch(br_from, to_location, revno)
 
417
            except bzrlib.errors.NoSuchRevision:
 
418
                rmtree(to_location)
 
419
                msg = "The branch %s has no revision %d." % (from_location, revision[0])
 
420
                raise BzrCommandError(msg)
 
421
        finally:
 
422
            rmtree(cache_root)
 
423
 
 
424
 
 
425
class cmd_renames(Command):
 
426
    """Show list of renamed files.
 
427
 
 
428
    TODO: Option to show renames between two historical versions.
 
429
 
 
430
    TODO: Only show renames under dir, rather than in the whole branch.
 
431
    """
 
432
    takes_args = ['dir?']
 
433
 
 
434
    def run(self, dir='.'):
 
435
        b = Branch.open_containing(dir)
 
436
        old_inv = b.basis_tree().inventory
 
437
        new_inv = b.read_working_inventory()
 
438
 
 
439
        renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
 
440
        renames.sort()
 
441
        for old_name, new_name in renames:
 
442
            print "%s => %s" % (old_name, new_name)        
 
443
 
 
444
 
 
445
class cmd_info(Command):
 
446
    """Show statistical information about a branch."""
 
447
    takes_args = ['branch?']
 
448
    
 
449
    def run(self, branch=None):
 
450
        import info
 
451
 
 
452
        b = Branch.open_containing(branch)
 
453
        info.show_info(b)
 
454
 
 
455
 
 
456
class cmd_remove(Command):
 
457
    """Make a file unversioned.
 
458
 
 
459
    This makes bzr stop tracking changes to a versioned file.  It does
 
460
    not delete the working copy.
 
461
    """
 
462
    takes_args = ['file+']
 
463
    takes_options = ['verbose']
 
464
    
 
465
    def run(self, file_list, verbose=False):
 
466
        b = Branch.open_containing(file_list[0])
 
467
        b.remove([b.relpath(f) for f in file_list], verbose=verbose)
 
468
 
 
469
 
 
470
class cmd_file_id(Command):
 
471
    """Print file_id of a particular file or directory.
 
472
 
 
473
    The file_id is assigned when the file is first added and remains the
 
474
    same through all revisions where the file exists, even when it is
 
475
    moved or renamed.
 
476
    """
 
477
    hidden = True
 
478
    takes_args = ['filename']
 
479
    def run(self, filename):
 
480
        b = Branch.open_containing(filename)
 
481
        i = b.inventory.path2id(b.relpath(filename))
 
482
        if i == None:
 
483
            raise BzrError("%r is not a versioned file" % filename)
 
484
        else:
 
485
            print i
 
486
 
 
487
 
 
488
class cmd_file_path(Command):
 
489
    """Print path of file_ids to a file or directory.
 
490
 
 
491
    This prints one line for each directory down to the target,
 
492
    starting at the branch root."""
 
493
    hidden = True
 
494
    takes_args = ['filename']
 
495
    def run(self, filename):
 
496
        b = Branch.open_containing(filename)
 
497
        inv = b.inventory
 
498
        fid = inv.path2id(b.relpath(filename))
 
499
        if fid == None:
 
500
            raise BzrError("%r is not a versioned file" % filename)
 
501
        for fip in inv.get_idpath(fid):
 
502
            print fip
 
503
 
 
504
 
 
505
class cmd_revision_history(Command):
 
506
    """Display list of revision ids on this branch."""
 
507
    hidden = True
 
508
    def run(self):
 
509
        for patchid in Branch.open_containing('.').revision_history():
 
510
            print patchid
 
511
 
 
512
 
 
513
class cmd_directories(Command):
 
514
    """Display list of versioned directories in this branch."""
 
515
    def run(self):
 
516
        for name, ie in Branch.open_containing('.').read_working_inventory().directories():
 
517
            if name == '':
 
518
                print '.'
 
519
            else:
 
520
                print name
 
521
 
 
522
 
 
523
class cmd_init(Command):
 
524
    """Make a directory into a versioned branch.
 
525
 
 
526
    Use this to create an empty branch, or before importing an
 
527
    existing project.
 
528
 
 
529
    Recipe for importing a tree of files:
 
530
        cd ~/project
 
531
        bzr init
 
532
        bzr add -v .
 
533
        bzr status
 
534
        bzr commit -m 'imported project'
 
535
    """
 
536
    def run(self):
 
537
        from bzrlib.branch import Branch
 
538
        Branch.initialize('.')
 
539
 
 
540
 
 
541
class cmd_diff(Command):
 
542
    """Show differences in working tree.
 
543
    
 
544
    If files are listed, only the changes in those files are listed.
 
545
    Otherwise, all changes for the tree are listed.
 
546
 
 
547
    TODO: Allow diff across branches.
 
548
 
 
549
    TODO: Option to use external diff command; could be GNU diff, wdiff,
 
550
          or a graphical diff.
 
551
 
 
552
    TODO: Python difflib is not exactly the same as unidiff; should
 
553
          either fix it up or prefer to use an external diff.
 
554
 
 
555
    TODO: If a directory is given, diff everything under that.
 
556
 
 
557
    TODO: Selected-file diff is inefficient and doesn't show you
 
558
          deleted files.
 
559
 
 
560
    TODO: This probably handles non-Unix newlines poorly.
 
561
 
 
562
    examples:
 
563
        bzr diff
 
564
        bzr diff -r1
 
565
        bzr diff -r1..2
 
566
    """
 
567
    
 
568
    takes_args = ['file*']
 
569
    takes_options = ['revision', 'diff-options']
 
570
    aliases = ['di', 'dif']
 
571
 
 
572
    def run(self, revision=None, file_list=None, diff_options=None):
 
573
        from bzrlib.diff import show_diff
 
574
 
 
575
        if file_list:
 
576
            b = Branch.open_containing(file_list[0])
 
577
            file_list = [b.relpath(f) for f in file_list]
 
578
            if file_list == ['']:
 
579
                # just pointing to top-of-tree
 
580
                file_list = None
 
581
        else:
 
582
            b = Branch.open_containing('.')
 
583
 
 
584
        if revision is not None:
 
585
            if len(revision) == 1:
 
586
                show_diff(b, revision[0], specific_files=file_list,
 
587
                          external_diff_options=diff_options)
 
588
            elif len(revision) == 2:
 
589
                show_diff(b, revision[0], specific_files=file_list,
 
590
                          external_diff_options=diff_options,
 
591
                          revision2=revision[1])
 
592
            else:
 
593
                raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
 
594
        else:
 
595
            show_diff(b, None, specific_files=file_list,
 
596
                      external_diff_options=diff_options)
 
597
 
 
598
        
 
599
 
 
600
 
 
601
class cmd_deleted(Command):
 
602
    """List files deleted in the working tree.
 
603
 
 
604
    TODO: Show files deleted since a previous revision, or between two revisions.
 
605
    """
 
606
    def run(self, show_ids=False):
 
607
        b = Branch.open_containing('.')
 
608
        old = b.basis_tree()
 
609
        new = b.working_tree()
 
610
 
 
611
        ## TODO: Much more efficient way to do this: read in new
 
612
        ## directories with readdir, rather than stating each one.  Same
 
613
        ## level of effort but possibly much less IO.  (Or possibly not,
 
614
        ## if the directories are very large...)
 
615
 
 
616
        for path, ie in old.inventory.iter_entries():
 
617
            if not new.has_id(ie.file_id):
 
618
                if show_ids:
 
619
                    print '%-50s %s' % (path, ie.file_id)
 
620
                else:
 
621
                    print path
 
622
 
 
623
 
 
624
class cmd_modified(Command):
 
625
    """List files modified in working tree."""
 
626
    hidden = True
 
627
    def run(self):
 
628
        from bzrlib.delta import compare_trees
 
629
 
 
630
        b = Branch.open_containing('.')
 
631
        td = compare_trees(b.basis_tree(), b.working_tree())
 
632
 
 
633
        for path, id, kind in td.modified:
 
634
            print path
 
635
 
 
636
 
 
637
 
 
638
class cmd_added(Command):
 
639
    """List files added in working tree."""
 
640
    hidden = True
 
641
    def run(self):
 
642
        b = Branch.open_containing('.')
 
643
        wt = b.working_tree()
 
644
        basis_inv = b.basis_tree().inventory
 
645
        inv = wt.inventory
 
646
        for file_id in inv:
 
647
            if file_id in basis_inv:
 
648
                continue
 
649
            path = inv.id2path(file_id)
 
650
            if not os.access(b.abspath(path), os.F_OK):
 
651
                continue
 
652
            print path
 
653
                
 
654
        
 
655
 
 
656
class cmd_root(Command):
 
657
    """Show the tree root directory.
 
658
 
 
659
    The root is the nearest enclosing directory with a .bzr control
 
660
    directory."""
 
661
    takes_args = ['filename?']
 
662
    def run(self, filename=None):
 
663
        """Print the branch root."""
 
664
        b = Branch.open_containing(filename)
 
665
        print b.base
 
666
 
 
667
 
 
668
class cmd_log(Command):
 
669
    """Show log of this branch.
 
670
 
 
671
    To request a range of logs, you can use the command -r begin:end
 
672
    -r revision requests a specific revision, -r :end or -r begin: are
 
673
    also valid.
 
674
 
 
675
    --message allows you to give a regular expression, which will be evaluated
 
676
    so that only matching entries will be displayed.
 
677
 
 
678
    TODO: Make --revision support uuid: and hash: [future tag:] notation.
 
679
  
 
680
    """
 
681
 
 
682
    takes_args = ['filename?']
 
683
    takes_options = ['forward', 'timezone', 'verbose', 'show-ids', 'revision',
 
684
                     'long', 'message', 'short',]
 
685
    
 
686
    def run(self, filename=None, timezone='original',
 
687
            verbose=False,
 
688
            show_ids=False,
 
689
            forward=False,
 
690
            revision=None,
 
691
            message=None,
 
692
            long=False,
 
693
            short=False):
 
694
        from bzrlib.log import log_formatter, show_log
 
695
        import codecs
 
696
 
 
697
        direction = (forward and 'forward') or 'reverse'
 
698
        
 
699
        if filename:
 
700
            b = Branch.open_containing(filename)
 
701
            fp = b.relpath(filename)
 
702
            if fp:
 
703
                file_id = b.read_working_inventory().path2id(fp)
 
704
            else:
 
705
                file_id = None  # points to branch root
 
706
        else:
 
707
            b = Branch.open_containing('.')
 
708
            file_id = None
 
709
 
 
710
        if revision is None:
 
711
            rev1 = None
 
712
            rev2 = None
 
713
        elif len(revision) == 1:
 
714
            rev1 = rev2 = revision[0].in_history(b).revno
 
715
        elif len(revision) == 2:
 
716
            rev1 = revision[0].in_history(b).revno
 
717
            rev2 = revision[1].in_history(b).revno
 
718
        else:
 
719
            raise BzrCommandError('bzr log --revision takes one or two values.')
 
720
 
 
721
        if rev1 == 0:
 
722
            rev1 = None
 
723
        if rev2 == 0:
 
724
            rev2 = None
 
725
 
 
726
        mutter('encoding log as %r' % bzrlib.user_encoding)
 
727
 
 
728
        # use 'replace' so that we don't abort if trying to write out
 
729
        # in e.g. the default C locale.
 
730
        outf = codecs.getwriter(bzrlib.user_encoding)(sys.stdout, errors='replace')
 
731
 
 
732
        if not short:
 
733
            log_format = 'long'
 
734
        else:
 
735
            log_format = 'short'
 
736
        lf = log_formatter(log_format,
 
737
                           show_ids=show_ids,
 
738
                           to_file=outf,
 
739
                           show_timezone=timezone)
 
740
 
 
741
        show_log(b,
 
742
                 lf,
 
743
                 file_id,
 
744
                 verbose=verbose,
 
745
                 direction=direction,
 
746
                 start_revision=rev1,
 
747
                 end_revision=rev2,
 
748
                 search=message)
 
749
 
 
750
 
 
751
 
 
752
class cmd_touching_revisions(Command):
 
753
    """Return revision-ids which affected a particular file.
 
754
 
 
755
    A more user-friendly interface is "bzr log FILE"."""
 
756
    hidden = True
 
757
    takes_args = ["filename"]
 
758
    def run(self, filename):
 
759
        b = Branch.open_containing(filename)
 
760
        inv = b.read_working_inventory()
 
761
        file_id = inv.path2id(b.relpath(filename))
 
762
        for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
 
763
            print "%6d %s" % (revno, what)
 
764
 
 
765
 
 
766
class cmd_ls(Command):
 
767
    """List files in a tree.
 
768
 
 
769
    TODO: Take a revision or remote path and list that tree instead.
 
770
    """
 
771
    hidden = True
 
772
    def run(self, revision=None, verbose=False):
 
773
        b = Branch.open_containing('.')
 
774
        if revision == None:
 
775
            tree = b.working_tree()
 
776
        else:
 
777
            tree = b.revision_tree(revision.in_history(b).rev_id)
 
778
 
 
779
        for fp, fc, kind, fid in tree.list_files():
 
780
            if verbose:
 
781
                if kind == 'directory':
 
782
                    kindch = '/'
 
783
                elif kind == 'file':
 
784
                    kindch = ''
 
785
                else:
 
786
                    kindch = '???'
 
787
 
 
788
                print '%-8s %s%s' % (fc, fp, kindch)
 
789
            else:
 
790
                print fp
 
791
 
 
792
 
 
793
 
 
794
class cmd_unknowns(Command):
 
795
    """List unknown files."""
 
796
    def run(self):
 
797
        from bzrlib.osutils import quotefn
 
798
        for f in Branch.open_containing('.').unknowns():
 
799
            print quotefn(f)
 
800
 
 
801
 
 
802
 
 
803
class cmd_ignore(Command):
 
804
    """Ignore a command or pattern.
 
805
 
 
806
    To remove patterns from the ignore list, edit the .bzrignore file.
 
807
 
 
808
    If the pattern contains a slash, it is compared to the whole path
 
809
    from the branch root.  Otherwise, it is comapred to only the last
 
810
    component of the path.
 
811
 
 
812
    Ignore patterns are case-insensitive on case-insensitive systems.
 
813
 
 
814
    Note: wildcards must be quoted from the shell on Unix.
 
815
 
 
816
    examples:
 
817
        bzr ignore ./Makefile
 
818
        bzr ignore '*.class'
 
819
    """
 
820
    takes_args = ['name_pattern']
 
821
    
 
822
    def run(self, name_pattern):
 
823
        from bzrlib.atomicfile import AtomicFile
 
824
        import os.path
 
825
 
 
826
        b = Branch.open_containing('.')
 
827
        ifn = b.abspath('.bzrignore')
 
828
 
 
829
        if os.path.exists(ifn):
 
830
            f = open(ifn, 'rt')
 
831
            try:
 
832
                igns = f.read().decode('utf-8')
 
833
            finally:
 
834
                f.close()
 
835
        else:
 
836
            igns = ''
 
837
 
 
838
        # TODO: If the file already uses crlf-style termination, maybe
 
839
        # we should use that for the newly added lines?
 
840
 
 
841
        if igns and igns[-1] != '\n':
 
842
            igns += '\n'
 
843
        igns += name_pattern + '\n'
 
844
 
 
845
        try:
 
846
            f = AtomicFile(ifn, 'wt')
 
847
            f.write(igns.encode('utf-8'))
 
848
            f.commit()
 
849
        finally:
 
850
            f.close()
 
851
 
 
852
        inv = b.working_tree().inventory
 
853
        if inv.path2id('.bzrignore'):
 
854
            mutter('.bzrignore is already versioned')
 
855
        else:
 
856
            mutter('need to make new .bzrignore file versioned')
 
857
            b.add(['.bzrignore'])
 
858
 
 
859
 
 
860
 
 
861
class cmd_ignored(Command):
 
862
    """List ignored files and the patterns that matched them.
 
863
 
 
864
    See also: bzr ignore"""
 
865
    def run(self):
 
866
        tree = Branch.open_containing('.').working_tree()
 
867
        for path, file_class, kind, file_id in tree.list_files():
 
868
            if file_class != 'I':
 
869
                continue
 
870
            ## XXX: Slightly inefficient since this was already calculated
 
871
            pat = tree.is_ignored(path)
 
872
            print '%-50s %s' % (path, pat)
 
873
 
 
874
 
 
875
class cmd_lookup_revision(Command):
 
876
    """Lookup the revision-id from a revision-number
 
877
 
 
878
    example:
 
879
        bzr lookup-revision 33
 
880
    """
 
881
    hidden = True
 
882
    takes_args = ['revno']
 
883
    
 
884
    def run(self, revno):
 
885
        try:
 
886
            revno = int(revno)
 
887
        except ValueError:
 
888
            raise BzrCommandError("not a valid revision-number: %r" % revno)
 
889
 
 
890
        print Branch.open_containing('.').get_rev_id(revno)
 
891
 
 
892
 
 
893
class cmd_export(Command):
 
894
    """Export past revision to destination directory.
 
895
 
 
896
    If no revision is specified this exports the last committed revision.
 
897
 
 
898
    Format may be an "exporter" name, such as tar, tgz, tbz2.  If none is
 
899
    given, try to find the format with the extension. If no extension
 
900
    is found exports to a directory (equivalent to --format=dir).
 
901
 
 
902
    Root may be the top directory for tar, tgz and tbz2 formats. If none
 
903
    is given, the top directory will be the root name of the file."""
 
904
    # TODO: list known exporters
 
905
    takes_args = ['dest']
 
906
    takes_options = ['revision', 'format', 'root']
 
907
    def run(self, dest, revision=None, format=None, root=None):
 
908
        import os.path
 
909
        b = Branch.open_containing('.')
 
910
        if revision is None:
 
911
            rev_id = b.last_patch()
 
912
        else:
 
913
            if len(revision) != 1:
 
914
                raise BzrError('bzr export --revision takes exactly 1 argument')
 
915
            rev_id = revision[0].in_history(b).rev_id
 
916
        t = b.revision_tree(rev_id)
 
917
        root, ext = os.path.splitext(dest)
 
918
        if not format:
 
919
            if ext in (".tar",):
 
920
                format = "tar"
 
921
            elif ext in (".gz", ".tgz"):
 
922
                format = "tgz"
 
923
            elif ext in (".bz2", ".tbz2"):
 
924
                format = "tbz2"
 
925
            else:
 
926
                format = "dir"
 
927
        t.export(dest, format, root)
 
928
 
 
929
 
 
930
class cmd_cat(Command):
 
931
    """Write a file's text from a previous revision."""
 
932
 
 
933
    takes_options = ['revision']
 
934
    takes_args = ['filename']
 
935
 
 
936
    def run(self, filename, revision=None):
 
937
        if revision is None:
 
938
            raise BzrCommandError("bzr cat requires a revision number")
 
939
        elif len(revision) != 1:
 
940
            raise BzrCommandError("bzr cat --revision takes exactly one number")
 
941
        b = Branch.open_containing('.')
 
942
        b.print_file(b.relpath(filename), revision[0].in_history(b).revno)
 
943
 
 
944
 
 
945
class cmd_local_time_offset(Command):
 
946
    """Show the offset in seconds from GMT to local time."""
 
947
    hidden = True    
 
948
    def run(self):
 
949
        print bzrlib.osutils.local_time_offset()
 
950
 
 
951
 
 
952
 
 
953
class cmd_commit(Command):
 
954
    """Commit changes into a new revision.
 
955
    
 
956
    If no arguments are given, the entire tree is committed.
 
957
 
 
958
    If selected files are specified, only changes to those files are
 
959
    committed.  If a directory is specified then the directory and everything 
 
960
    within it is committed.
 
961
 
 
962
    A selected-file commit may fail in some cases where the committed
 
963
    tree would be invalid, such as trying to commit a file in a
 
964
    newly-added directory that is not itself committed.
 
965
 
 
966
    TODO: Run hooks on tree to-be-committed, and after commit.
 
967
 
 
968
    TODO: Strict commit that fails if there are unknown or deleted files.
 
969
    """
 
970
    takes_args = ['selected*']
 
971
    takes_options = ['message', 'file', 'verbose', 'unchanged']
 
972
    aliases = ['ci', 'checkin']
 
973
 
 
974
    # TODO: Give better message for -s, --summary, used by tla people
 
975
    
 
976
    def run(self, message=None, file=None, verbose=True, selected_list=None,
 
977
            unchanged=False):
 
978
        from bzrlib.errors import PointlessCommit
 
979
        from bzrlib.msgeditor import edit_commit_message
 
980
        from bzrlib.status import show_status
 
981
        from cStringIO import StringIO
 
982
 
 
983
        b = Branch.open_containing('.')
 
984
        if selected_list:
 
985
            selected_list = [b.relpath(s) for s in selected_list]
 
986
            
 
987
        if not message and not file:
 
988
            catcher = StringIO()
 
989
            show_status(b, specific_files=selected_list,
 
990
                        to_file=catcher)
 
991
            message = edit_commit_message(catcher.getvalue())
 
992
            
 
993
            if message is None:
 
994
                raise BzrCommandError("please specify a commit message"
 
995
                                      " with either --message or --file")
 
996
        elif message and file:
 
997
            raise BzrCommandError("please specify either --message or --file")
 
998
        
 
999
        if file:
 
1000
            import codecs
 
1001
            message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
 
1002
 
 
1003
        try:
 
1004
            b.commit(message, verbose=verbose,
 
1005
                     specific_files=selected_list,
 
1006
                     allow_pointless=unchanged)
 
1007
        except PointlessCommit:
 
1008
            # FIXME: This should really happen before the file is read in;
 
1009
            # perhaps prepare the commit; get the message; then actually commit
 
1010
            raise BzrCommandError("no changes to commit",
 
1011
                                  ["use --unchanged to commit anyhow"])
 
1012
 
 
1013
 
 
1014
class cmd_check(Command):
 
1015
    """Validate consistency of branch history.
 
1016
 
 
1017
    This command checks various invariants about the branch storage to
 
1018
    detect data corruption or bzr bugs.
 
1019
    """
 
1020
    takes_args = ['dir?']
 
1021
 
 
1022
    def run(self, dir='.'):
 
1023
        from bzrlib.check import check
 
1024
 
 
1025
        check(Branch.open_containing(dir))
 
1026
 
 
1027
 
 
1028
class cmd_scan_cache(Command):
 
1029
    hidden = True
 
1030
    def run(self):
 
1031
        from bzrlib.hashcache import HashCache
 
1032
 
 
1033
        c = HashCache('.')
 
1034
        c.read()
 
1035
        c.scan()
 
1036
            
 
1037
        print '%6d stats' % c.stat_count
 
1038
        print '%6d in hashcache' % len(c._cache)
 
1039
        print '%6d files removed from cache' % c.removed_count
 
1040
        print '%6d hashes updated' % c.update_count
 
1041
        print '%6d files changed too recently to cache' % c.danger_count
 
1042
 
 
1043
        if c.needs_write:
 
1044
            c.write()
 
1045
            
 
1046
 
 
1047
 
 
1048
class cmd_upgrade(Command):
 
1049
    """Upgrade branch storage to current format.
 
1050
 
 
1051
    The check command or bzr developers may sometimes advise you to run
 
1052
    this command.
 
1053
    """
 
1054
    takes_args = ['dir?']
 
1055
 
 
1056
    def run(self, dir='.'):
 
1057
        from bzrlib.upgrade import upgrade
 
1058
        upgrade(Branch.open_containing(dir))
 
1059
 
 
1060
 
 
1061
 
 
1062
class cmd_whoami(Command):
 
1063
    """Show bzr user id."""
 
1064
    takes_options = ['email']
 
1065
    
 
1066
    def run(self, email=False):
 
1067
        try:
 
1068
            b = bzrlib.branch.Branch.open_containing('.')
 
1069
        except:
 
1070
            b = None
 
1071
        
 
1072
        if email:
 
1073
            print bzrlib.osutils.user_email(b)
 
1074
        else:
 
1075
            print bzrlib.osutils.username(b)
 
1076
 
 
1077
 
 
1078
class cmd_selftest(Command):
 
1079
    """Run internal test suite"""
 
1080
    hidden = True
 
1081
    takes_options = ['verbose', 'pattern']
 
1082
    def run(self, verbose=False, pattern=".*"):
 
1083
        import bzrlib.ui
 
1084
        from bzrlib.selftest import selftest
 
1085
        # we don't want progress meters from the tests to go to the
 
1086
        # real output; and we don't want log messages cluttering up
 
1087
        # the real logs.
 
1088
        save_ui = bzrlib.ui.ui_factory
 
1089
        bzrlib.trace.info('running tests...')
 
1090
        try:
 
1091
            bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
 
1092
            result = selftest(verbose=verbose, pattern=pattern)
 
1093
            if result:
 
1094
                bzrlib.trace.info('tests passed')
 
1095
            else:
 
1096
                bzrlib.trace.info('tests failed')
 
1097
            return int(not result)
 
1098
        finally:
 
1099
            bzrlib.ui.ui_factory = save_ui
 
1100
 
 
1101
 
 
1102
def show_version():
 
1103
    print "bzr (bazaar-ng) %s" % bzrlib.__version__
 
1104
    # is bzrlib itself in a branch?
 
1105
    bzrrev = bzrlib.get_bzr_revision()
 
1106
    if bzrrev:
 
1107
        print "  (bzr checkout, revision %d {%s})" % bzrrev
 
1108
    print bzrlib.__copyright__
 
1109
    print "http://bazaar-ng.org/"
 
1110
    print
 
1111
    print "bzr comes with ABSOLUTELY NO WARRANTY.  bzr is free software, and"
 
1112
    print "you may use, modify and redistribute it under the terms of the GNU"
 
1113
    print "General Public License version 2 or later."
 
1114
 
 
1115
 
 
1116
class cmd_version(Command):
 
1117
    """Show version of bzr."""
 
1118
    def run(self):
 
1119
        show_version()
 
1120
 
 
1121
class cmd_rocks(Command):
 
1122
    """Statement of optimism."""
 
1123
    hidden = True
 
1124
    def run(self):
 
1125
        print "it sure does!"
 
1126
 
 
1127
 
 
1128
class cmd_find_merge_base(Command):
 
1129
    """Find and print a base revision for merging two branches.
 
1130
 
 
1131
    TODO: Options to specify revisions on either side, as if
 
1132
          merging only part of the history.
 
1133
    """
 
1134
    takes_args = ['branch', 'other']
 
1135
    hidden = True
 
1136
    
 
1137
    def run(self, branch, other):
 
1138
        from bzrlib.revision import common_ancestor, MultipleRevisionSources
 
1139
        
 
1140
        branch1 = Branch.open_containing(branch)
 
1141
        branch2 = Branch.open_containing(other)
 
1142
 
 
1143
        history_1 = branch1.revision_history()
 
1144
        history_2 = branch2.revision_history()
 
1145
 
 
1146
        last1 = branch1.last_patch()
 
1147
        last2 = branch2.last_patch()
 
1148
 
 
1149
        source = MultipleRevisionSources(branch1, branch2)
 
1150
        
 
1151
        base_rev_id = common_ancestor(last1, last2, source)
 
1152
 
 
1153
        print 'merge base is revision %s' % base_rev_id
 
1154
        
 
1155
        return
 
1156
 
 
1157
        if base_revno is None:
 
1158
            raise bzrlib.errors.UnrelatedBranches()
 
1159
 
 
1160
        print ' r%-6d in %s' % (base_revno, branch)
 
1161
 
 
1162
        other_revno = branch2.revision_id_to_revno(base_revid)
 
1163
        
 
1164
        print ' r%-6d in %s' % (other_revno, other)
 
1165
 
 
1166
 
 
1167
 
 
1168
class cmd_merge(Command):
 
1169
    """Perform a three-way merge.
 
1170
    
 
1171
    The branch is the branch you will merge from.  By default, it will
 
1172
    merge the latest revision.  If you specify a revision, that
 
1173
    revision will be merged.  If you specify two revisions, the first
 
1174
    will be used as a BASE, and the second one as OTHER.  Revision
 
1175
    numbers are always relative to the specified branch.
 
1176
 
 
1177
    By default bzr will try to merge in all new work from the other
 
1178
    branch, automatically determining an appropriate base.  If this
 
1179
    fails, you may need to give an explicit base.
 
1180
    
 
1181
    Examples:
 
1182
 
 
1183
    To merge the latest revision from bzr.dev
 
1184
    bzr merge ../bzr.dev
 
1185
 
 
1186
    To merge changes up to and including revision 82 from bzr.dev
 
1187
    bzr merge -r 82 ../bzr.dev
 
1188
 
 
1189
    To merge the changes introduced by 82, without previous changes:
 
1190
    bzr merge -r 81..82 ../bzr.dev
 
1191
    
 
1192
    merge refuses to run if there are any uncommitted changes, unless
 
1193
    --force is given.
 
1194
    """
 
1195
    takes_args = ['branch?']
 
1196
    takes_options = ['revision', 'force', 'merge-type']
 
1197
 
 
1198
    def run(self, branch='.', revision=None, force=False, 
 
1199
            merge_type=None):
 
1200
        from bzrlib.merge import merge
 
1201
        from bzrlib.merge_core import ApplyMerge3
 
1202
        if merge_type is None:
 
1203
            merge_type = ApplyMerge3
 
1204
 
 
1205
        if revision is None or len(revision) < 1:
 
1206
            base = [None, None]
 
1207
            other = [branch, -1]
 
1208
        else:
 
1209
            if len(revision) == 1:
 
1210
                base = [None, None]
 
1211
                other = [branch, revision[0].in_history(branch).revno]
 
1212
            else:
 
1213
                assert len(revision) == 2
 
1214
                if None in revision:
 
1215
                    raise BzrCommandError(
 
1216
                        "Merge doesn't permit that revision specifier.")
 
1217
                from bzrlib.branch import Branch
 
1218
                b = Branch.open(branch)
 
1219
 
 
1220
                base = [branch, revision[0].in_history(b).revno]
 
1221
                other = [branch, revision[1].in_history(b).revno]
 
1222
 
 
1223
        try:
 
1224
            merge(other, base, check_clean=(not force), merge_type=merge_type)
 
1225
        except bzrlib.errors.AmbiguousBase, e:
 
1226
            m = ("sorry, bzr can't determine the right merge base yet\n"
 
1227
                 "candidates are:\n  "
 
1228
                 + "\n  ".join(e.bases)
 
1229
                 + "\n"
 
1230
                 "please specify an explicit base with -r,\n"
 
1231
                 "and (if you want) report this to the bzr developers\n")
 
1232
            log_error(m)
 
1233
 
 
1234
 
 
1235
class cmd_revert(Command):
 
1236
    """Reverse all changes since the last commit.
 
1237
 
 
1238
    Only versioned files are affected.  Specify filenames to revert only 
 
1239
    those files.  By default, any files that are changed will be backed up
 
1240
    first.  Backup files have a '~' appended to their name.
 
1241
    """
 
1242
    takes_options = ['revision', 'no-backup']
 
1243
    takes_args = ['file*']
 
1244
    aliases = ['merge-revert']
 
1245
 
 
1246
    def run(self, revision=None, no_backup=False, file_list=None):
 
1247
        from bzrlib.merge import merge
 
1248
        from bzrlib.branch import Branch
 
1249
        from bzrlib.commands import parse_spec
 
1250
 
 
1251
        if file_list is not None:
 
1252
            if len(file_list) == 0:
 
1253
                raise BzrCommandError("No files specified")
 
1254
        if revision is None:
 
1255
            revno = -1
 
1256
        elif len(revision) != 1:
 
1257
            raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
 
1258
        else:
 
1259
            b = Branch.open_containing('.')
 
1260
            revno = revision[0].in_history(b).revno
 
1261
        merge(('.', revno), parse_spec('.'),
 
1262
              check_clean=False,
 
1263
              ignore_zero=True,
 
1264
              backup_files=not no_backup,
 
1265
              file_list=file_list)
 
1266
        if not file_list:
 
1267
            Branch.open_containing('.').set_pending_merges([])
 
1268
 
 
1269
 
 
1270
class cmd_assert_fail(Command):
 
1271
    """Test reporting of assertion failures"""
 
1272
    hidden = True
 
1273
    def run(self):
 
1274
        assert False, "always fails"
 
1275
 
 
1276
 
 
1277
class cmd_help(Command):
 
1278
    """Show help on a command or other topic.
 
1279
 
 
1280
    For a list of all available commands, say 'bzr help commands'."""
 
1281
    takes_options = ['long']
 
1282
    takes_args = ['topic?']
 
1283
    aliases = ['?']
 
1284
    
 
1285
    def run(self, topic=None, long=False):
 
1286
        import help
 
1287
        if topic is None and long:
 
1288
            topic = "commands"
 
1289
        help.help(topic)
 
1290
 
 
1291
 
 
1292
class cmd_shell_complete(Command):
 
1293
    """Show appropriate completions for context.
 
1294
 
 
1295
    For a list of all available commands, say 'bzr shell-complete'."""
 
1296
    takes_args = ['context?']
 
1297
    aliases = ['s-c']
 
1298
    hidden = True
 
1299
    
 
1300
    def run(self, context=None):
 
1301
        import shellcomplete
 
1302
        shellcomplete.shellcomplete(context)
 
1303
 
 
1304
 
 
1305
class cmd_missing(Command):
 
1306
    """What is missing in this branch relative to other branch.
 
1307
    """
 
1308
    takes_args = ['remote?']
 
1309
    aliases = ['mis', 'miss']
 
1310
    # We don't have to add quiet to the list, because 
 
1311
    # unknown options are parsed as booleans
 
1312
    takes_options = ['verbose', 'quiet']
 
1313
 
 
1314
    def run(self, remote=None, verbose=False, quiet=False):
 
1315
        from bzrlib.errors import BzrCommandError
 
1316
        from bzrlib.missing import show_missing
 
1317
 
 
1318
        if verbose and quiet:
 
1319
            raise BzrCommandError('Cannot pass both quiet and verbose')
 
1320
 
 
1321
        b = Branch.open_containing('.')
 
1322
        parent = b.get_parent()
 
1323
        if remote is None:
 
1324
            if parent is None:
 
1325
                raise BzrCommandError("No missing location known or specified.")
 
1326
            else:
 
1327
                if not quiet:
 
1328
                    print "Using last location: %s" % parent
 
1329
                remote = parent
 
1330
        elif parent is None:
 
1331
            # We only update parent if it did not exist, missing
 
1332
            # should not change the parent
 
1333
            b.set_parent(remote)
 
1334
        br_remote = Branch.open_containing(remote)
 
1335
 
 
1336
        return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
 
1337
 
 
1338
 
 
1339
 
 
1340
class cmd_plugins(Command):
 
1341
    """List plugins"""
 
1342
    hidden = True
 
1343
    def run(self):
 
1344
        import bzrlib.plugin
 
1345
        from inspect import getdoc
 
1346
        for plugin in bzrlib.plugin.all_plugins:
 
1347
            if hasattr(plugin, '__path__'):
 
1348
                print plugin.__path__[0]
 
1349
            elif hasattr(plugin, '__file__'):
 
1350
                print plugin.__file__
 
1351
            else:
 
1352
                print `plugin`
 
1353
                
 
1354
            d = getdoc(plugin)
 
1355
            if d:
 
1356
                print '\t', d.split('\n')[0]
 
1357
 
 
1358