~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-28 02:40:49 UTC
  • Revision ID: mbp@sourcefrog.net-20050328024049-9e1d1fea5e834ae7
Make fields wider in 'bzr info' output to accomodate big trees

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/python
2
 
 
3
 
 
4
1
# Copyright (C) 2004, 2005 by Martin Pool
5
2
# Copyright (C) 2005 by Canonical Ltd
6
3
 
28
25
* Metadata format is not stable yet -- you may need to
29
26
  discard history in the future.
30
27
 
31
 
* No handling of subdirectories, symlinks or any non-text files.
32
 
 
33
28
* Insufficient error handling.
34
29
 
35
30
* Many commands unimplemented or partially implemented.
40
35
 
41
36
Interesting commands::
42
37
 
43
 
  bzr help
44
 
       Show summary help screen
 
38
  bzr help [COMMAND]
 
39
       Show help screen
45
40
  bzr version
46
41
       Show software version/licence/non-warranty.
47
42
  bzr init
60
55
       Show summary of pending changes.
61
56
  bzr remove FILE...
62
57
       Make a file not versioned.
 
58
  bzr info
 
59
       Show statistics about this branch.
63
60
"""
64
61
 
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'
 
62
 
75
63
 
76
64
 
77
65
import sys, os, random, time, sha, sets, types, re, shutil, tempfile
184
172
    Therefore simply saying 'bzr add .' will version all files that
185
173
    are currently unknown.
186
174
    """
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
 
 
 
175
    bzrlib.add.smart_add(file_list, verbose)
195
176
    
196
177
 
197
178
def cmd_relpath(filename):
 
179
    """Show path of file relative to root"""
198
180
    print Branch(filename).relpath(filename)
199
181
 
200
182
 
214
196
 
215
197
 
216
198
def cmd_info():
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
 
        
 
199
    import info
 
200
    info.show_info(Branch('.'))        
267
201
    
268
202
 
269
203
 
310
244
 
311
245
 
312
246
def cmd_diff(revision=None):
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
 
    """
 
247
    """bzr diff: Show differences in working tree.
 
248
    
 
249
usage: bzr diff [-r REV]
 
250
 
 
251
--revision REV
 
252
    Show changes since REV, rather than predecessor.
 
253
 
 
254
TODO: Given two revision arguments, show the difference between them.
 
255
 
 
256
TODO: Allow diff across branches.
 
257
 
 
258
TODO: Option to use external diff command; could be GNU diff, wdiff,
 
259
or a graphical diff.
 
260
 
 
261
TODO: Diff selected files.
 
262
"""
 
263
 
 
264
    ## TODO: Shouldn't be in the cmd function.
324
265
 
325
266
    b = Branch('.')
326
267
 
476
417
 
477
418
 
478
419
def cmd_commit(message=None, verbose=False):
 
420
    """Commit changes to a new revision.
 
421
 
 
422
--message MESSAGE
 
423
    Description of changes in this revision; free form text.
 
424
    It is recommended that the first line be a single-sentence
 
425
    summary.
 
426
--verbose
 
427
    Show status of changed files,
 
428
 
 
429
TODO: Commit only selected files.
 
430
 
 
431
TODO: Run hooks on tree to-be-committed, and after commit.
 
432
 
 
433
TODO: Strict commit that fails if there are unknown or deleted files.
 
434
"""
 
435
 
479
436
    if not message:
480
437
        bailout("please specify a commit message")
481
438
    Branch('.').commit(message, verbose=verbose)
553
510
# help
554
511
 
555
512
 
556
 
def cmd_help():
557
 
    # TODO: Specific help for particular commands
558
 
    print __doc__
 
513
def cmd_help(topic=None):
 
514
    if topic == None:
 
515
        print __doc__
 
516
        return
 
517
 
 
518
    # otherwise, maybe the name of a command?
 
519
    try:
 
520
        cmdfn = globals()['cmd_' + topic.replace('-', '_')]
 
521
    except KeyError:
 
522
        bailout("no help for %r" % topic)
 
523
 
 
524
    doc = cmdfn.__doc__
 
525
    if doc == None:
 
526
        bailout("sorry, no detailed help yet for %r" % topic)
 
527
 
 
528
    print doc
 
529
        
 
530
 
559
531
 
560
532
 
561
533
def cmd_version():
562
 
    print "bzr (bazaar-ng) %s" % __version__
563
 
    print __copyright__
 
534
    print "bzr (bazaar-ng) %s" % bzrlib.__version__
 
535
    print bzrlib.__copyright__
564
536
    print "http://bazaar-ng.org/"
565
537
    print
566
538
    print \
614
586
 
615
587
 
616
588
cmd_args = {
617
 
    'init':                   [],
618
589
    'add':                    ['file+'],
619
590
    'commit':                 [],
620
591
    'diff':                   [],
 
592
    'export':                 ['revno', 'dest'],
621
593
    'file-id':                ['filename'],
622
 
    'root':                   ['filename?'],
623
 
    'relpath':                ['filename'],
624
594
    'get-file-text':          ['text_id'],
625
595
    'get-inventory':          ['inventory_id'],
626
596
    'get-revision':           ['revision_id'],
627
597
    'get-revision-inventory': ['revision_id'],
 
598
    'help':                   ['topic?'],
 
599
    'init':                   [],
628
600
    'log':                    [],
629
601
    'lookup-revision':        ['revno'],
630
 
    'export':                 ['revno', 'dest'],
 
602
    'relpath':                ['filename'],
631
603
    'remove':                 ['file+'],
 
604
    'root':                   ['filename?'],
632
605
    'status':                 [],
633
606
    }
634
607