113
115
## TODO: Perhaps make UUIDs predictable in test mode to make it easier
114
116
## to compare output?
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
121
######################################################################
123
125
def cmd_status(all=False):
139
141
Branch('.').get_revision(revision_id).write_xml(sys.stdout)
144
def cmd_get_inventory(inventory_id):
145
"""Return inventory in XML by hash"""
146
Branch('.').get_inventory(inventory_hash).write_xml(sys.stdout)
149
def cmd_get_revision_inventory(revision_id):
150
"""Output inventory for a revision."""
152
b.get_revision_inventory(revision_id).write_xml(sys.stdout)
142
155
def cmd_get_file_text(text_id):
143
156
"""Get contents of a file by hash."""
144
157
sf = Branch('.').text_store[text_id]
183
196
print 'branch format:', b.controlfile('branch-format', 'r').readline().rstrip('\n')
185
def plural(n, base='', pl=None):
193
count_version_dirs = 0
195
count_status = {'A': 0, 'D': 0, 'M': 0, 'R': 0, '?': 0, 'I': 0, '.': 0}
196
for st_tup in bzrlib.diff_trees(b.basis_tree(), b.working_tree()):
198
count_status[fs] += 1
199
if fs not in ['I', '?'] and st_tup[4] == 'directory':
200
count_version_dirs += 1
203
print 'in the working tree:'
204
for name, fs in (('unchanged', '.'),
205
('modified', 'M'), ('added', 'A'), ('removed', 'D'),
206
('renamed', 'R'), ('unknown', '?'), ('ignored', 'I'),
208
print ' %5d %s' % (count_status[fs], name)
209
print ' %5d versioned subdirector%s' % (count_version_dirs,
210
plural(count_version_dirs, 'y', 'ies'))
213
print 'branch history:'
214
history = b.revision_history()
216
print ' %5d revision%s' % (revno, plural(revno))
219
committers.add(b.get_revision(rev).committer)
220
print ' %5d committer%s' % (len(committers), plural(len(committers)))
222
firstrev = b.get_revision(history[0])
223
age = int((time.time() - firstrev.timestamp) / 3600 / 24)
224
print ' %5d day%s old' % (age, plural(age))
225
print ' first revision: %s' % format_date(firstrev.timestamp,
228
lastrev = b.get_revision(history[-1])
229
print ' latest revision: %s' % format_date(lastrev.timestamp,
197
print 'revision number:', b.revno()
198
print 'number of versioned files:', len(b.read_working_inventory())
235
201
def cmd_remove(file_list, verbose=False):
581
547
lookup table, something about the available options, what optargs
582
548
they take, and which commands will accept them.
584
>>> parse_args('--help'.split())
550
>>> parse_args('bzr --help'.split())
585
551
([], {'help': True})
586
>>> parse_args('--version'.split())
552
>>> parse_args('bzr --version'.split())
587
553
([], {'version': True})
588
>>> parse_args('status --all'.split())
554
>>> parse_args('bzr status --all'.split())
589
555
(['status'], {'all': True})
590
>>> parse_args('commit --message=biter'.split())
556
>>> parse_args('bzr commit --message=biter'.split())
591
557
(['commit'], {'message': u'biter'})
692
658
logging and error handling.
695
args, opts = parse_args(argv[1:])
661
args, opts = parse_args(argv)
696
662
if 'help' in opts:
697
663
# TODO: pass down other arguments in case they asked for
698
664
# help on a command name?
736
702
## than just a backtrace.
739
# TODO: Lift into separate function in trace.py
740
# TODO: Also show contents of /etc/lsb-release, if it can be parsed.
741
# Perhaps that should eventually go into the platform library?
742
# TODO: If the file doesn't exist, add a note describing it.
743
705
t = bzrlib.trace._tracefile
744
706
t.write('-' * 60 + '\n')
745
707
t.write('bzr invoked at %s\n' % format_date(time.time()))
746
t.write(' by %s on %s\n' % (bzrlib.osutils.username(), socket.getfqdn()))
708
t.write(' by %s on %s\n' % (bzrlib.osutils.username(), socket.gethostname()))
747
709
t.write(' arguments: %r\n' % argv)
749
711
starttime = os.times()[4]