~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzr.py

  • Committer: mbp at sourcefrog
  • Date: 2005-03-11 06:36:25 UTC
  • Revision ID: mbp@sourcefrog.net-20050311063625-07858525021f270b
- bzr info: show summary information on branch history
- nicer plurals

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
"""
64
64
 
65
65
# not currently working:
 
66
#  bzr check
 
67
#       Run internal consistency checks.
66
68
#  bzr info
67
69
#       Show some information about this branch.
68
70
 
113
115
## TODO: Perhaps make UUIDs predictable in test mode to make it easier
114
116
## to compare output?
115
117
 
116
 
## TODO: Some kind of global code to generate the right Branch object
117
 
## to work on.  Almost, but not quite all, commands need one, and it
118
 
## can be taken either from their parameters or their working
119
 
## directory.
120
 
 
121
 
## TODO: rename command, needed soon: check destination doesn't exist
122
 
## either in working copy or tree; move working copy; update
123
 
## inventory; write out
124
 
 
125
 
## TODO: move command; check destination is a directory and will not
126
 
## clash; move it.
127
 
 
128
 
## TODO: command to show renames, one per line, as to->from
129
 
 
130
 
 
 
118
 
 
119
 
 
120
 
 
121
######################################################################
 
122
# check status
131
123
 
132
124
 
133
125
def cmd_status(all=False):
149
141
    Branch('.').get_revision(revision_id).write_xml(sys.stdout)
150
142
 
151
143
 
 
144
def cmd_get_inventory(inventory_id):
 
145
    """Return inventory in XML by hash"""
 
146
    Branch('.').get_inventory(inventory_hash).write_xml(sys.stdout)
 
147
 
 
148
 
 
149
def cmd_get_revision_inventory(revision_id):
 
150
    """Output inventory for a revision."""
 
151
    b = Branch('.')
 
152
    b.get_revision_inventory(revision_id).write_xml(sys.stdout)
 
153
 
 
154
 
152
155
def cmd_get_file_text(text_id):
153
156
    """Get contents of a file by hash."""
154
157
    sf = Branch('.').text_store[text_id]
165
168
    print Branch('.').revno()
166
169
    
167
170
 
168
 
    
169
171
def cmd_add(file_list, verbose=False):
170
 
    """Add specified files or directories.
171
 
 
172
 
    In non-recursive mode, all the named items are added, regardless
173
 
    of whether they were previously ignored.  A warning is given if
174
 
    any of the named files are already versioned.
175
 
 
176
 
    In recursive mode (the default), files are treated the same way
177
 
    but the behaviour for directories is different.  Directories that
178
 
    are already versioned do not give a warning.  All directories,
179
 
    whether already versioned or not, are searched for files or
180
 
    subdirectories that are neither versioned or ignored, and these
181
 
    are added.  This search proceeds recursively into versioned
182
 
    directories.
183
 
 
184
 
    Therefore simply saying 'bzr add .' will version all files that
185
 
    are currently unknown.
 
172
    """Add specified files.
 
173
    
 
174
    Fails if the files are already added.
186
175
    """
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
 
 
195
 
    
196
 
 
197
 
def cmd_relpath(filename):
198
 
    print Branch(filename).relpath(filename)
 
176
    Branch('.').add(file_list, verbose=verbose)
199
177
 
200
178
 
201
179
def cmd_inventory(revision=None):
257
235
        firstrev = b.get_revision(history[0])
258
236
        age = int((time.time() - firstrev.timestamp) / 3600 / 24)
259
237
        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
 
        
267
238
    
268
239
 
269
240
 
270
241
def cmd_remove(file_list, verbose=False):
271
 
    b = Branch(file_list[0])
272
 
    b.remove([b.relpath(f) for f in file_list], verbose=verbose)
 
242
    Branch('.').remove(file_list, verbose=verbose)
273
243
 
274
244
 
275
245
 
276
246
def cmd_file_id(filename):
277
 
    b = Branch(filename)
278
 
    i = b.inventory.path2id(b.relpath(filename))
 
247
    i = Branch('.').read_working_inventory().path2id(filename)
279
248
    if i is None:
280
249
        bailout("%s is not a versioned file" % filename)
281
250
    else:
395
364
 
396
365
 
397
366
 
398
 
def cmd_root(filename=None):
399
 
    """Print the branch root."""
400
 
    print bzrlib.branch.find_branch_root(filename)
401
 
    
402
 
 
403
367
def cmd_log(timezone='original'):
404
368
    """Show log of this branch.
405
369
 
466
430
 
467
431
def cmd_uuid():
468
432
    """Print a newly-generated UUID."""
469
 
    print bzrlib.osutils.uuid()
 
433
    print uuid()
470
434
 
471
435
 
472
436
 
475
439
 
476
440
 
477
441
 
478
 
def cmd_commit(message=None, verbose=False):
479
 
    if not message:
480
 
        bailout("please specify a commit message")
 
442
def cmd_commit(message, verbose=False):
481
443
    Branch('.').commit(message, verbose=verbose)
482
444
 
483
445
 
514
476
    print bzrlib.branch._gen_revision_id(time.time())
515
477
 
516
478
 
517
 
def cmd_selftest(verbose=False):
518
 
    """Run internal test suite"""
 
479
def cmd_doctest():
 
480
    """Run internal doctest suite"""
519
481
    ## -v, if present, is seen by doctest; the argument is just here
520
482
    ## so our parser doesn't complain
521
483
 
522
484
    ## TODO: --verbose option
523
 
 
524
 
    failures, tests = 0, 0
525
485
    
526
 
    import doctest, bzrlib.store, bzrlib.tests
 
486
    import bzr, doctest, bzrlib.store
527
487
    bzrlib.trace.verbose = False
528
 
 
529
 
    for m in bzrlib.store, bzrlib.inventory, bzrlib.branch, bzrlib.osutils, \
530
 
        bzrlib.tree, bzrlib.tests, bzrlib.commands, bzrlib.add:
531
 
        mf, mt = doctest.testmod(m)
532
 
        failures += mf
533
 
        tests += mt
534
 
        print '%-40s %3d tests' % (m.__name__, mt),
535
 
        if mf:
536
 
            print '%3d FAILED!' % mf
537
 
        else:
538
 
            print
539
 
 
540
 
    print '%-40s %3d tests' % ('total', tests),
541
 
    if failures:
542
 
        print '%3d FAILED!' % failures
543
 
    else:
544
 
        print
545
 
 
546
 
 
547
 
 
548
 
# deprecated
549
 
cmd_doctest = cmd_selftest
 
488
    doctest.testmod(bzr)
 
489
    doctest.testmod(bzrlib.store)
 
490
    doctest.testmod(bzrlib.inventory)
 
491
    doctest.testmod(bzrlib.branch)
 
492
    doctest.testmod(bzrlib.osutils)
 
493
    doctest.testmod(bzrlib.tree)
 
494
 
 
495
    # more strenuous tests;
 
496
    import bzrlib.tests
 
497
    doctest.testmod(bzrlib.tests)
550
498
 
551
499
 
552
500
######################################################################
619
567
    'commit':                 [],
620
568
    'diff':                   [],
621
569
    'file-id':                ['filename'],
622
 
    'root':                   ['filename?'],
623
 
    'relpath':                ['filename'],
624
570
    'get-file-text':          ['text_id'],
625
571
    'get-inventory':          ['inventory_id'],
626
572
    'get-revision':           ['revision_id'],
641
587
    lookup table, something about the available options, what optargs
642
588
    they take, and which commands will accept them.
643
589
 
644
 
    >>> parse_args('--help'.split())
 
590
    >>> parse_args('bzr --help'.split())
645
591
    ([], {'help': True})
646
 
    >>> parse_args('--version'.split())
 
592
    >>> parse_args('bzr --version'.split())
647
593
    ([], {'version': True})
648
 
    >>> parse_args('status --all'.split())
 
594
    >>> parse_args('bzr status --all'.split())
649
595
    (['status'], {'all': True})
650
 
    >>> parse_args('commit --message=biter'.split())
 
596
    >>> parse_args('bzr commit --message=biter'.split())
651
597
    (['commit'], {'message': u'biter'})
652
598
    """
653
599
    args = []
655
601
 
656
602
    # TODO: Maybe handle '--' to end options?
657
603
 
658
 
    while argv:
659
 
        a = argv.pop(0)
 
604
    it = iter(argv[1:])
 
605
    while it:
 
606
        a = it.next()
660
607
        if a[0] == '-':
661
608
            optarg = None
662
609
            if a[1] == '-':
680
627
            optargfn = OPTIONS[optname]
681
628
            if optargfn:
682
629
                if optarg == None:
683
 
                    if not argv:
 
630
                    if not it:
684
631
                        bailout('option %r needs an argument' % a)
685
632
                    else:
686
 
                        optarg = argv.pop(0)
 
633
                        optarg = it.next()
687
634
                opts[optname] = optargfn(optarg)
688
635
                mutter("    option argument %r" % opts[optname])
689
636
            else:
714
661
    argdict = {}
715
662
    # TODO: Need a way to express 'cp SRC... DEST', where it matches
716
663
    # all but one.
717
 
 
718
 
    # step through args and argform, allowing appropriate 0-many matches
719
664
    for ap in argform:
720
665
        argname = ap[:-1]
721
666
        if ap[-1] == '?':
722
 
            if args:
723
 
                argdict[argname] = args.pop(0)
 
667
            assert 0
724
668
        elif ap[-1] == '*':
725
669
            assert 0
726
670
        elif ap[-1] == '+':
754
698
    logging and error handling.
755
699
    """
756
700
    try:
757
 
        args, opts = parse_args(argv[1:])
 
701
        args, opts = parse_args(argv)
758
702
        if 'help' in opts:
759
703
            # TODO: pass down other arguments in case they asked for
760
704
            # help on a command name?
797
741
    ## TODO: If the arguments are wrong, give a usage message rather
798
742
    ## than just a backtrace.
799
743
 
800
 
    bzrlib.trace.create_tracefile(argv)
801
 
    
802
744
    try:
 
745
        t = bzrlib.trace._tracefile
 
746
        t.write('-' * 60 + '\n')
 
747
        t.write('bzr invoked at %s\n' % format_date(time.time()))
 
748
        t.write('  by %s on %s\n' % (bzrlib.osutils.username(), socket.gethostname()))
 
749
        t.write('  arguments: %r\n' % argv)
 
750
 
 
751
        starttime = os.times()[4]
 
752
 
 
753
        import platform
 
754
        t.write('  platform: %s\n' % platform.platform())
 
755
        t.write('  python: %s\n' % platform.python_version())
 
756
 
803
757
        ret = run_bzr(argv)
 
758
        
 
759
        times = os.times()
 
760
        mutter("finished, %.3fu/%.3fs cpu, %.3fu/%.3fs cum"
 
761
               % times[:4])
 
762
        mutter("    %.3f elapsed" % (times[4] - starttime))
 
763
 
804
764
        return ret
805
765
    except BzrError, e:
806
766
        log_error('bzr: error: ' + e.args[0] + '\n')