22
from bzrlib.trace import mutter, note, log_error, warning
22
from bzrlib.trace import mutter, note, log_error
23
23
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError
24
24
from bzrlib.branch import find_branch
25
25
from bzrlib import BZRDIR
54
54
def _parse_revision_str(revstr):
55
55
"""This handles a revision string -> revno.
57
It supports integers directly, but everything else it
58
defers for passing to Branch.get_revision_info()
60
>>> _parse_revision_str('234')
62
>>> _parse_revision_str('234..567')
64
>>> _parse_revision_str('..')
66
>>> _parse_revision_str('..234')
68
>>> _parse_revision_str('234..')
70
>>> _parse_revision_str('234..456..789') # Maybe this should be an error
72
>>> _parse_revision_str('234....789') # Error?
74
>>> _parse_revision_str('revid:test@other.com-234234')
75
['revid:test@other.com-234234']
76
>>> _parse_revision_str('revid:test@other.com-234234..revid:test@other.com-234235')
77
['revid:test@other.com-234234', 'revid:test@other.com-234235']
78
>>> _parse_revision_str('revid:test@other.com-234234..23')
79
['revid:test@other.com-234234', 23]
80
>>> _parse_revision_str('date:2005-04-12')
82
>>> _parse_revision_str('date:2005-04-12 12:24:33')
83
['date:2005-04-12 12:24:33']
84
>>> _parse_revision_str('date:2005-04-12T12:24:33')
85
['date:2005-04-12T12:24:33']
86
>>> _parse_revision_str('date:2005-04-12,12:24:33')
87
['date:2005-04-12,12:24:33']
88
>>> _parse_revision_str('-5..23')
90
>>> _parse_revision_str('-5')
92
>>> _parse_revision_str('123a')
94
>>> _parse_revision_str('abc')
57
There are several possibilities:
60
'234:345' -> [234, 345]
64
In the future we will also support:
65
'uuid:blah-blah-blah' -> ?
66
'hash:blahblahblah' -> ?
98
old_format_re = re.compile('\d*:\d*')
99
m = old_format_re.match(revstr)
101
warning('Colon separator for revision numbers is deprecated.'
104
for rev in revstr.split(':'):
106
revs.append(int(rev))
111
for x in revstr.split('..'):
70
if revstr.find(':') != -1:
71
revs = revstr.split(':')
73
raise ValueError('More than 2 pieces not supported for --revision: %r' % revstr)
78
revs[0] = int(revs[0])
83
revs[1] = int(revs[1])
368
335
print find_branch('.').revno()
370
class cmd_revision_info(Command):
371
"""Show revision number and revision id for a given revision identifier.
374
takes_args = ['revision_info*']
375
takes_options = ['revision']
376
def run(self, revision=None, revision_info_list=None):
377
from bzrlib.branch import find_branch
380
if revision is not None:
381
revs.extend(revision)
382
if revision_info_list is not None:
383
revs.extend(revision_info_list)
385
raise BzrCommandError('You must supply a revision identifier')
390
print '%4d %s' % b.get_revision_info(rev)
393
338
class cmd_add(Command):
394
339
"""Add specified files or directories.
456
401
if revision == None:
457
402
inv = b.read_working_inventory()
459
if len(revision) > 1:
460
raise BzrCommandError('bzr inventory --revision takes'
461
' exactly one revision identifier')
462
inv = b.get_revision_inventory(b.lookup_revision(revision[0]))
404
inv = b.get_revision_inventory(b.lookup_revision(revision))
464
406
for path, entry in inv.entries():
620
556
br_to = Branch(to_location, init=True)
622
br_to.set_root_id(br_from.get_root_id())
625
if revision[0] is None:
626
revno = br_from.revno()
628
revno, rev_id = br_from.get_revision_info(revision[0])
630
br_to.update_revisions(br_from, stop_revision=revno)
631
except NoSuchRevision:
633
msg = "The branch %s has no revision %d." % (from_location,
635
raise BzrCommandError(msg)
559
br_to.update_revisions(br_from, stop_revision=revision)
560
except NoSuchRevision:
562
msg = "The branch %s has no revision %d." % (from_location,
564
raise BzrCommandError(msg)
637
565
merge((to_location, -1), (to_location, 0), this_dir=to_location,
638
566
check_clean=False, ignore_zero=True)
639
567
from_location = pull_loc(br_from)
809
737
b = find_branch('.')
811
# TODO: Make show_diff support taking 2 arguments
813
if revision is not None:
814
if len(revision) != 1:
815
raise BzrCommandError('bzr diff --revision takes exactly one revision identifier')
816
base_rev = revision[0]
818
show_diff(b, base_rev, specific_files=file_list,
739
show_diff(b, revision, specific_files=file_list,
819
740
external_diff_options=diff_options)
896
817
-r revision requests a specific revision, -r :end or -r begin: are
899
--message allows you to give a regular expression, which will be evaluated
900
so that only matching entries will be displayed.
902
820
TODO: Make --revision support uuid: and hash: [future tag:] notation.
906
824
takes_args = ['filename?']
907
takes_options = ['forward', 'timezone', 'verbose', 'show-ids', 'revision','long', 'message']
825
takes_options = ['forward', 'timezone', 'verbose', 'show-ids', 'revision','long']
909
827
def run(self, filename=None, timezone='original',
916
833
from bzrlib.branch import find_branch
917
834
from bzrlib.log import log_formatter, show_log
930
847
b = find_branch('.')
936
elif len(revision) == 1:
937
rev1 = rev2 = b.get_revision_info(revision[0])[0]
938
elif len(revision) == 2:
939
rev1 = b.get_revision_info(revision[0])[0]
940
rev2 = b.get_revision_info(revision[1])[0]
851
revision = [None, None]
852
elif isinstance(revision, int):
853
revision = [revision, revision]
942
raise BzrCommandError('bzr log --revision takes one or two values.')
858
assert len(revision) == 2
949
860
mutter('encoding log as %r' % bzrlib.user_encoding)
1130
1040
def run(self, dest, revision=None, format=None, root=None):
1132
1042
b = find_branch('.')
1133
if revision is None:
1134
rev_id = b.last_patch()
1043
if revision == None:
1044
rh = b.revision_history()[-1]
1136
if len(revision) != 1:
1137
raise BzrError('bzr export --revision takes exactly 1 argument')
1138
revno, rev_id = b.get_revision_info(revision[0])
1139
t = b.revision_tree(rev_id)
1046
rh = b.lookup_revision(int(revision))
1047
t = b.revision_tree(rh)
1140
1048
root, ext = os.path.splitext(dest)
1142
1050
if ext in (".tar",):
1159
1067
def run(self, filename, revision=None):
1160
1068
if revision == None:
1161
1069
raise BzrCommandError("bzr cat requires a revision number")
1162
elif len(revision) != 1:
1163
raise BzrCommandError("bzr cat --revision takes exactly one number")
1164
1070
b = find_branch('.')
1165
b.print_file(b.relpath(filename), revision[0])
1071
b.print_file(b.relpath(filename), int(revision))
1168
1074
class cmd_local_time_offset(Command):
1397
1297
takes_options = ['revision']
1399
def run(self, revision=None):
1299
def run(self, revision=-1):
1400
1300
from bzrlib.merge import merge
1401
if revision is None:
1403
elif len(revision) != 1:
1404
raise BzrCommandError('bzr merge-revert --revision takes exactly 1 argument')
1405
merge(('.', revision[0]), parse_spec('.'),
1301
merge(('.', revision), parse_spec('.'),
1406
1302
check_clean=False,
1407
1303
ignore_zero=True)
1435
1331
import bzrlib.plugin
1436
from inspect import getdoc
1437
1332
from pprint import pprint
1438
for plugin in bzrlib.plugin.all_plugins:
1439
print plugin.__path__[0]
1442
print '\t', d.split('\n')[0]
1444
#pprint(bzrlib.plugin.all_plugins)
1333
pprint(bzrlib.plugin.all_plugins)
1498
1387
>>> parse_args('commit --message=biter'.split())
1499
1388
(['commit'], {'message': u'biter'})
1500
1389
>>> parse_args('log -r 500'.split())
1501
(['log'], {'revision': [500]})
1502
>>> parse_args('log -r500..600'.split())
1390
(['log'], {'revision': 500})
1391
>>> parse_args('log -r500:600'.split())
1503
1392
(['log'], {'revision': [500, 600]})
1504
>>> parse_args('log -vr500..600'.split())
1393
>>> parse_args('log -vr500:600'.split())
1505
1394
(['log'], {'verbose': True, 'revision': [500, 600]})
1506
>>> parse_args('log -rv500..600'.split()) #the r takes an argument
1507
(['log'], {'revision': ['v500', 600]})
1395
>>> parse_args('log -rv500:600'.split()) #the r takes an argument
1396
Traceback (most recent call last):
1398
ValueError: invalid literal for int(): v500