~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-29 01:26:19 UTC
  • Revision ID: mbp@sourcefrog.net-20050329012619-dd8959fc63b3a074
- fixup checks on retrieved files to cope with compression,
  and have less checks now there's a check command again

- move code to destroy stores into the ScratchStore subclass

Show diffs side-by-side

added added

removed removed

Lines of Context:
180
180
    print Branch(filename).relpath(filename)
181
181
 
182
182
 
183
 
 
184
183
def cmd_inventory(revision=None):
185
184
    """Show inventory of the current working copy."""
186
185
    ## TODO: Also optionally show a previous inventory
196
195
 
197
196
 
198
197
 
199
 
def cmd_mv(source_list, dest):
200
 
    b = Branch('.')
201
 
 
202
 
    b.rename([b.relpath(s) for s in source_list], b.relpath(dest))
203
 
 
204
 
 
205
 
 
206
 
def cmd_rename(from_name, to_name):
207
 
    """Change the name of an entry.
208
 
 
209
 
usage: bzr rename FROM_NAME TO_NAME
210
 
 
211
 
examples:
212
 
  bzr rename frob.c frobber.c
213
 
  bzr rename src/frob.c lib/frob.c
214
 
 
215
 
It is an error if the destination name exists.
216
 
 
217
 
See also the 'move' command, which moves files into a different
218
 
directory without changing their name.
219
 
 
220
 
TODO: Some way to rename multiple files without invoking bzr for each
221
 
one?"""
222
 
    b = Branch('.')
223
 
    b.rename_one(b.relpath(from_name), b.relpath(to_name))
224
 
    
225
 
 
226
 
 
227
 
 
228
 
def cmd_renames(dir='.'):
229
 
    """Show list of renamed files.
230
 
 
231
 
usage: bzr renames [BRANCH]
232
 
 
233
 
TODO: Option to show renames between two historical versions.
234
 
 
235
 
TODO: Only show renames under dir, rather than in the whole branch.
236
 
"""
237
 
    b = Branch(dir)
238
 
    old_inv = b.basis_tree().inventory
239
 
    new_inv = b.read_working_inventory()
240
 
    
241
 
    renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
242
 
    renames.sort()
243
 
    for old_name, new_name in renames:
244
 
        print "%s => %s" % (old_name, new_name)        
245
 
 
246
 
 
247
 
 
248
198
def cmd_info():
249
199
    """info: Show statistical information for this branch
250
200
 
282
232
        print patchid
283
233
 
284
234
 
285
 
def cmd_directories():
286
 
    for name, ie in Branch('.').read_working_inventory().directories():
287
 
        if name == '':
288
 
            print '.'
289
 
        else:
290
 
            print name
291
 
 
292
 
 
293
 
def cmd_missing():
294
 
    for name, ie in Branch('.').working_tree().missing():
295
 
        print name
296
 
 
297
235
 
298
236
def cmd_init():
299
237
    # TODO: Check we're not already in a working directory?  At the
363
301
        # FIXME: Something about the diff format makes patch unhappy
364
302
        # with newly-added files.
365
303
 
366
 
        def diffit(oldlines, newlines, **kw):
367
 
            # FIXME: difflib is wrong if there is no trailing newline.
368
 
 
369
 
            # Special workaround for Python2.3, where difflib fails if
370
 
            # both sequences are empty.
371
 
            if oldlines or newlines:
372
 
                sys.stdout.writelines(difflib.unified_diff(oldlines, newlines, **kw))
 
304
        def diffit(*a, **kw):
 
305
            sys.stdout.writelines(difflib.unified_diff(*a, **kw))
373
306
            print
374
307
        
375
308
        if file_state in ['.', '?', 'I']:
406
339
 
407
340
 
408
341
 
409
 
def cmd_deleted(show_ids=False):
410
 
    """List files deleted in the working tree.
411
 
 
412
 
TODO: Show files deleted since a previous revision, or between two revisions.
413
 
    """
414
 
    b = Branch('.')
415
 
    old = b.basis_tree()
416
 
    new = b.working_tree()
417
 
 
418
 
    ## TODO: Much more efficient way to do this: read in new
419
 
    ## directories with readdir, rather than stating each one.  Same
420
 
    ## level of effort but possibly much less IO.  (Or possibly not,
421
 
    ## if the directories are very large...)
422
 
 
423
 
    for path, ie in old.inventory.iter_entries():
424
 
        if not new.has_id(ie.file_id):
425
 
            if show_ids:
426
 
                print '%-50s %s' % (path, ie.file_id)
427
 
            else:
428
 
                print path
429
 
 
430
 
 
431
 
 
432
 
def cmd_parse_inventory():
433
 
    import cElementTree
434
 
    
435
 
    cElementTree.ElementTree().parse(file('.bzr/inventory'))
436
 
 
437
 
 
438
 
 
439
 
def cmd_load_inventory():
440
 
    inv = Branch('.').basis_tree().inventory
441
 
 
442
 
 
443
 
 
444
 
def cmd_dump_new_inventory():
445
 
    import bzrlib.newinventory
446
 
    inv = Branch('.').basis_tree().inventory
447
 
    bzrlib.newinventory.write_inventory(inv, sys.stdout)
448
 
 
449
 
 
450
 
def cmd_load_new_inventory():
451
 
    import bzrlib.newinventory
452
 
    bzrlib.newinventory.read_new_inventory(sys.stdin)
453
 
                
454
 
    
455
 
def cmd_dump_slacker_inventory():
456
 
    import bzrlib.newinventory
457
 
    inv = Branch('.').basis_tree().inventory
458
 
    bzrlib.newinventory.write_slacker_inventory(inv, sys.stdout)
459
 
                
460
 
    
461
 
 
462
342
def cmd_root(filename=None):
463
343
    """Print the branch root."""
464
344
    print bzrlib.branch.find_branch_root(filename)
504
384
        print quotefn(f)
505
385
 
506
386
 
507
 
 
508
 
def cmd_ignored(verbose=True):
509
 
    """List ignored files and the patterns that matched them.
510
 
      """
511
 
    tree = Branch('.').working_tree()
512
 
    for path, file_class, kind, id in tree.list_files():
513
 
        if file_class != 'I':
514
 
            continue
515
 
        ## XXX: Slightly inefficient since this was already calculated
516
 
        pat = tree.is_ignored(path)
517
 
        print '%-50s %s' % (path, pat)
518
 
 
519
 
 
520
387
def cmd_lookup_revision(revno):
521
388
    try:
522
389
        revno = int(revno)
704
571
    'all':                    None,
705
572
    'help':                   None,
706
573
    'message':                unicode,
707
 
    'profile':                None,
708
574
    'revision':               int,
709
575
    'show-ids':               None,
710
576
    'timezone':               str,
723
589
cmd_options = {
724
590
    'add':                    ['verbose'],
725
591
    'commit':                 ['message', 'verbose'],
726
 
    'deleted':                ['show-ids'],
727
592
    'diff':                   ['revision'],
728
593
    'inventory':              ['revision'],
729
 
    'log':                    ['timezone'],
 
594
    'log':                    ['show-ids', 'timezone'],
730
595
    'ls':                     ['revision', 'verbose'],
731
596
    'remove':                 ['verbose'],
732
597
    'status':                 ['all'],
747
612
    'init':                   [],
748
613
    'log':                    [],
749
614
    'lookup-revision':        ['revno'],
750
 
    'mv':                     ['source$', 'dest'],
751
615
    'relpath':                ['filename'],
752
616
    'remove':                 ['file+'],
753
 
    'rename':                 ['from_name', 'to_name'],
754
 
    'renames':                ['dir?'],
755
617
    'root':                   ['filename?'],
756
618
    'status':                 [],
757
619
    }
809
671
                    else:
810
672
                        optarg = argv.pop(0)
811
673
                opts[optname] = optargfn(optarg)
 
674
                mutter("    option argument %r" % opts[optname])
812
675
            else:
813
676
                if optarg != None:
814
677
                    bailout('option %r takes no argument' % optname)
853
716
            else:
854
717
                argdict[argname + '_list'] = args[:]
855
718
                args = []
856
 
        elif ap[-1] == '$': # all but one
857
 
            if len(args) < 2:
858
 
                bailout("command %r needs one or more %s"
859
 
                        % (cmd, argname.upper()))
860
 
            argdict[argname + '_list'] = args[:-1]
861
 
            args[:-1] = []                
862
719
        else:
863
720
            # just a plain arg
864
721
            argname = ap
887
744
        if 'help' in opts:
888
745
            # TODO: pass down other arguments in case they asked for
889
746
            # help on a command name?
890
 
            if args:
891
 
                cmd_help(args[0])
892
 
            else:
893
 
                cmd_help()
 
747
            cmd_help()
894
748
            return 0
895
749
        elif 'version' in opts:
896
750
            cmd_version()
906
760
    except KeyError:
907
761
        bailout("unknown command " + `cmd`)
908
762
 
909
 
    # global option
910
 
    if 'profile' in opts:
911
 
        profile = True
912
 
        del opts['profile']
913
 
    else:
914
 
        profile = False
 
763
    # TODO: special --profile option to turn on the Python profiler
915
764
 
916
765
    # check options are reasonable
917
766
    allowed = cmd_options.get(cmd, [])
920
769
            bailout("option %r is not allowed for command %r"
921
770
                    % (oname, cmd))
922
771
 
923
 
    # mix arguments and options into one dictionary
924
772
    cmdargs = _match_args(cmd, args)
925
 
    for k, v in opts.items():
926
 
        cmdargs[k.replace('-', '_')] = v
927
 
 
928
 
    if profile:
929
 
        import hotshot
930
 
        prof = hotshot.Profile('.bzr.profile')
931
 
        ret = prof.runcall(cmd_handler, **cmdargs) or 0
932
 
        prof.close()
933
 
 
934
 
        import hotshot.stats
935
 
        stats = hotshot.stats.load('.bzr.profile')
936
 
        #stats.strip_dirs()
937
 
        stats.sort_stats('time')
938
 
        stats.print_stats(20)
939
 
    else:
940
 
        return cmd_handler(**cmdargs) or 0
 
773
    cmdargs.update(opts)
 
774
 
 
775
    ret = cmd_handler(**cmdargs) or 0
941
776
 
942
777
 
943
778