~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: mbp at sourcefrog
  • Date: 2005-03-23 23:52:10 UTC
  • Revision ID: mbp@sourcefrog.net-20050323235210-5464746b93c39ed0
more notes on darcs

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python
 
2
 
 
3
 
1
4
# Copyright (C) 2004, 2005 by Martin Pool
2
5
# Copyright (C) 2005 by Canonical Ltd
3
6
 
25
28
* Metadata format is not stable yet -- you may need to
26
29
  discard history in the future.
27
30
 
 
31
* No handling of subdirectories, symlinks or any non-text files.
 
32
 
28
33
* Insufficient error handling.
29
34
 
30
35
* Many commands unimplemented or partially implemented.
35
40
 
36
41
Interesting commands::
37
42
 
38
 
  bzr help [COMMAND]
39
 
       Show help screen
 
43
  bzr help
 
44
       Show summary help screen
40
45
  bzr version
41
46
       Show software version/licence/non-warranty.
42
47
  bzr init
55
60
       Show summary of pending changes.
56
61
  bzr remove FILE...
57
62
       Make a file not versioned.
58
 
  bzr info
59
 
       Show statistics about this branch.
60
63
"""
61
64
 
62
 
 
 
65
# not currently working:
 
66
#  bzr info
 
67
#       Show some information about this branch.
 
68
 
 
69
 
 
70
 
 
71
__copyright__ = "Copyright 2005 Canonical Development Ltd."
 
72
__author__ = "Martin Pool <mbp@canonical.com>"
 
73
__docformat__ = "restructuredtext en"
 
74
__version__ = '0.0.0'
63
75
 
64
76
 
65
77
import sys, os, random, time, sha, sets, types, re, shutil, tempfile
172
184
    Therefore simply saying 'bzr add .' will version all files that
173
185
    are currently unknown.
174
186
    """
175
 
    bzrlib.add.smart_add(file_list, verbose)
 
187
    if True:
 
188
        bzrlib.add.smart_add(file_list, verbose)
 
189
    else:
 
190
        # old way
 
191
        assert file_list
 
192
        b = Branch(file_list[0], find_root=True)
 
193
        b.add([b.relpath(f) for f in file_list], verbose=verbose)
 
194
 
176
195
    
177
196
 
178
197
def cmd_relpath(filename):
179
 
    """Show path of file relative to root"""
180
198
    print Branch(filename).relpath(filename)
181
199
 
182
200
 
196
214
 
197
215
 
198
216
def cmd_info():
199
 
    """info: Show statistical information for this branch
200
 
 
201
 
usage: bzr info"""
202
 
    import info
203
 
    info.show_info(Branch('.'))        
 
217
    b = Branch('.')
 
218
    print 'branch format:', b.controlfile('branch-format', 'r').readline().rstrip('\n')
 
219
 
 
220
    def plural(n, base='', pl=None):
 
221
        if n == 1:
 
222
            return base
 
223
        elif pl is not None:
 
224
            return pl
 
225
        else:
 
226
            return 's'
 
227
 
 
228
    count_version_dirs = 0
 
229
 
 
230
    count_status = {'A': 0, 'D': 0, 'M': 0, 'R': 0, '?': 0, 'I': 0, '.': 0}
 
231
    for st_tup in bzrlib.diff_trees(b.basis_tree(), b.working_tree()):
 
232
        fs = st_tup[0]
 
233
        count_status[fs] += 1
 
234
        if fs not in ['I', '?'] and st_tup[4] == 'directory':
 
235
            count_version_dirs += 1
 
236
 
 
237
    print
 
238
    print 'in the working tree:'
 
239
    for name, fs in (('unchanged', '.'),
 
240
                     ('modified', 'M'), ('added', 'A'), ('removed', 'D'),
 
241
                     ('renamed', 'R'), ('unknown', '?'), ('ignored', 'I'),
 
242
                     ):
 
243
        print '  %5d %s' % (count_status[fs], name)
 
244
    print '  %5d versioned subdirector%s' % (count_version_dirs,
 
245
                                             plural(count_version_dirs, 'y', 'ies'))
 
246
 
 
247
    print
 
248
    print 'branch history:'
 
249
    history = b.revision_history()
 
250
    revno = len(history)
 
251
    print '  %5d revision%s' % (revno, plural(revno))
 
252
    committers = Set()
 
253
    for rev in history:
 
254
        committers.add(b.get_revision(rev).committer)
 
255
    print '  %5d committer%s' % (len(committers), plural(len(committers)))
 
256
    if revno > 0:
 
257
        firstrev = b.get_revision(history[0])
 
258
        age = int((time.time() - firstrev.timestamp) / 3600 / 24)
 
259
        print '  %5d day%s old' % (age, plural(age))
 
260
        print '  first revision: %s' % format_date(firstrev.timestamp,
 
261
                                                 firstrev.timezone)
 
262
 
 
263
        lastrev = b.get_revision(history[-1])
 
264
        print '  latest revision: %s' % format_date(lastrev.timestamp,
 
265
                                                    lastrev.timezone)
 
266
        
204
267
    
205
268
 
206
269
 
247
310
 
248
311
 
249
312
def cmd_diff(revision=None):
250
 
    """bzr diff: Show differences in working tree.
251
 
    
252
 
usage: bzr diff [-r REV]
253
 
 
254
 
--revision REV
255
 
    Show changes since REV, rather than predecessor.
256
 
 
257
 
TODO: Given two revision arguments, show the difference between them.
258
 
 
259
 
TODO: Allow diff across branches.
260
 
 
261
 
TODO: Option to use external diff command; could be GNU diff, wdiff,
262
 
or a graphical diff.
263
 
 
264
 
TODO: Diff selected files.
265
 
"""
266
 
 
267
 
    ## TODO: Shouldn't be in the cmd function.
 
313
    """Show diff from basis to working copy.
 
314
 
 
315
    :todo: Take one or two revision arguments, look up those trees,
 
316
           and diff them.
 
317
 
 
318
    :todo: Allow diff across branches.
 
319
 
 
320
    :todo: Mangle filenames in diff to be more relevant.
 
321
 
 
322
    :todo: Shouldn't be in the cmd function.
 
323
    """
268
324
 
269
325
    b = Branch('.')
270
326
 
420
476
 
421
477
 
422
478
def cmd_commit(message=None, verbose=False):
423
 
    """Commit changes to a new revision.
424
 
 
425
 
--message MESSAGE
426
 
    Description of changes in this revision; free form text.
427
 
    It is recommended that the first line be a single-sentence
428
 
    summary.
429
 
--verbose
430
 
    Show status of changed files,
431
 
 
432
 
TODO: Commit only selected files.
433
 
 
434
 
TODO: Run hooks on tree to-be-committed, and after commit.
435
 
 
436
 
TODO: Strict commit that fails if there are unknown or deleted files.
437
 
"""
438
 
 
439
479
    if not message:
440
480
        bailout("please specify a commit message")
441
481
    Branch('.').commit(message, verbose=verbose)
442
482
 
443
483
 
444
 
def cmd_check(dir='.'):
445
 
    """check: Consistency check of branch history.
446
 
 
447
 
usage: bzr check [-v] [BRANCH]
448
 
 
449
 
options:
450
 
  --verbose, -v         Show progress of checking.
451
 
 
452
 
This command checks various invariants about the branch storage to
453
 
detect data corruption or bzr bugs.
454
 
"""
455
 
    import bzrlib.check
456
 
    bzrlib.check.check(Branch(dir, find_root=False))
 
484
def cmd_check():
 
485
    """Check consistency of the branch."""
 
486
    check()
457
487
 
458
488
 
459
489
def cmd_is(pred, *rest):
523
553
# help
524
554
 
525
555
 
526
 
def cmd_help(topic=None):
527
 
    if topic == None:
528
 
        print __doc__
529
 
        return
530
 
 
531
 
    # otherwise, maybe the name of a command?
532
 
    try:
533
 
        cmdfn = globals()['cmd_' + topic.replace('-', '_')]
534
 
    except KeyError:
535
 
        bailout("no help for %r" % topic)
536
 
 
537
 
    doc = cmdfn.__doc__
538
 
    if doc == None:
539
 
        bailout("sorry, no detailed help yet for %r" % topic)
540
 
 
541
 
    print doc
542
 
        
543
 
 
 
556
def cmd_help():
 
557
    # TODO: Specific help for particular commands
 
558
    print __doc__
544
559
 
545
560
 
546
561
def cmd_version():
547
 
    print "bzr (bazaar-ng) %s" % bzrlib.__version__
548
 
    print bzrlib.__copyright__
 
562
    print "bzr (bazaar-ng) %s" % __version__
 
563
    print __copyright__
549
564
    print "http://bazaar-ng.org/"
550
565
    print
551
566
    print \
599
614
 
600
615
 
601
616
cmd_args = {
 
617
    'init':                   [],
602
618
    'add':                    ['file+'],
603
619
    'commit':                 [],
604
620
    'diff':                   [],
605
 
    'export':                 ['revno', 'dest'],
606
621
    'file-id':                ['filename'],
 
622
    'root':                   ['filename?'],
 
623
    'relpath':                ['filename'],
607
624
    'get-file-text':          ['text_id'],
608
625
    'get-inventory':          ['inventory_id'],
609
626
    'get-revision':           ['revision_id'],
610
627
    'get-revision-inventory': ['revision_id'],
611
 
    'help':                   ['topic?'],
612
 
    'init':                   [],
613
628
    'log':                    [],
614
629
    'lookup-revision':        ['revno'],
615
 
    'relpath':                ['filename'],
 
630
    'export':                 ['revno', 'dest'],
616
631
    'remove':                 ['file+'],
617
 
    'root':                   ['filename?'],
618
632
    'status':                 [],
619
633
    }
620
634
 
754
768
        log_error('usage: bzr COMMAND\n')
755
769
        log_error('  try "bzr help"\n')
756
770
        return 1
757
 
 
 
771
            
758
772
    try:
759
773
        cmd_handler = globals()['cmd_' + cmd.replace('-', '_')]
760
774
    except KeyError: