/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-11-11 17:46:11 UTC
  • mto: (1185.65.2 bzr.revision-storage)
  • mto: This revision was merged to the branch mainline in revision 1509.
  • Revision ID: aaron.bentley@utoronto.ca-20051111174611-05c622f83aca3d78
Support whitespace in diff filenames

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