58
58
for cmdname, cmdclass in get_all_cmds():
59
59
if cmd in cmdclass.aliases:
60
60
return cmdname, cmdclass
62
cmdclass = ExternalCommand.find_command(cmd)
66
raise BzrCommandError("unknown command %r" % cmd)
62
raise BzrCommandError("unknown command %r" % cmd)
118
class ExternalCommand(Command):
119
"""Class to wrap external commands.
121
We cheat a little here, when get_cmd_class() calls us we actually give it back
122
an object we construct that has the appropriate path, help, options etc for the
125
When run_bzr() tries to instantiate that 'class' it gets caught by the __call__
126
method, which we override to call the Command.__init__ method. That then calls
127
our run method which is pretty straight forward.
129
The only wrinkle is that we have to map bzr's dictionary of options and arguments
130
back into command line options and arguments for the script.
133
def find_command(cls, cmd):
134
bzrpath = os.environ.get('BZRPATH', '')
136
for dir in bzrpath.split(':'):
137
path = os.path.join(dir, cmd)
138
if os.path.isfile(path):
139
return ExternalCommand(path)
143
find_command = classmethod(find_command)
145
def __init__(self, path):
148
# TODO: If either of these fail, we should detect that and
149
# assume that path is not really a bzr plugin after all.
151
pipe = os.popen('%s --bzr-usage' % path, 'r')
152
self.takes_options = pipe.readline().split()
153
self.takes_args = pipe.readline().split()
156
pipe = os.popen('%s --bzr-help' % path, 'r')
157
self.__doc__ = pipe.read()
160
def __call__(self, options, arguments):
161
Command.__init__(self, options, arguments)
164
def run(self, **kargs):
172
if OPTIONS.has_key(name):
174
opts.append('--%s' % name)
175
if value is not None and value is not True:
176
opts.append(str(value))
178
# it's an arg, or arg list
179
if type(value) is not list:
185
self.status = os.spawnv(os.P_WAIT, self.path, [self.path] + opts + args)
189
115
class cmd_status(Command):
190
116
"""Display status summary.
482
class cmd_modified(Command):
483
"""List files modified in working tree."""
488
inv = b.read_working_inventory()
489
sc = statcache.update_cache(b, inv)
490
basis = b.basis_tree()
491
basis_inv = basis.inventory
493
# We used to do this through iter_entries(), but that's slow
494
# when most of the files are unmodified, as is usually the
495
# case. So instead we iterate by inventory entry, and only
496
# calculate paths as necessary.
498
for file_id in basis_inv:
499
cacheentry = sc.get(file_id)
500
if not cacheentry: # deleted
502
ie = basis_inv[file_id]
503
if cacheentry[statcache.SC_SHA1] != ie.text_sha1:
504
path = inv.id2path(file_id)
509
404
class cmd_root(Command):
510
405
"""Show the tree root directory.
514
409
takes_args = ['filename?']
515
410
def run(self, filename=None):
516
411
"""Print the branch root."""
517
from branch import find_branch
518
b = find_branch(filename)
519
print getattr(b, 'base', None) or getattr(b, 'baseurl')
412
print bzrlib.branch.find_branch_root(filename)
522
416
class cmd_log(Command):
529
423
takes_args = ['filename?']
530
424
takes_options = ['timezone', 'verbose', 'show-ids']
531
425
def run(self, filename=None, timezone='original', verbose=False, show_ids=False):
532
from branch import find_branch
533
b = find_branch((filename or '.'), lock_mode='r')
426
b = Branch((filename or '.'), lock_mode='r')
535
428
filename = b.relpath(filename)
536
429
bzrlib.show_log(b, filename,
591
484
class cmd_ignore(Command):
592
"""Ignore a command or pattern
594
To remove patterns from the ignore list, edit the .bzrignore file.
596
If the pattern contains a slash, it is compared to the whole path
597
from the branch root. Otherwise, it is comapred to only the last
598
component of the path.
600
Ignore patterns are case-insensitive on case-insensitive systems.
602
Note: wildcards must be quoted from the shell on Unix.
605
bzr ignore ./Makefile
485
"""Ignore a command or pattern"""
608
486
takes_args = ['name_pattern']
610
488
def run(self, name_pattern):
643
521
class cmd_ignored(Command):
644
"""List ignored files and the patterns that matched them.
646
See also: bzr ignore"""
522
"""List ignored files and the patterns that matched them."""
648
524
tree = Branch('.').working_tree()
649
525
for path, file_class, kind, file_id in tree.list_files():