22
from bzrlib.trace import mutter, note, log_error
22
from bzrlib.trace import mutter, note, log_error, warning
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
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' -> ?
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')
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])
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('..'):
335
368
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)
338
393
class cmd_add(Command):
339
394
"""Add specified files or directories.
401
456
if revision == None:
402
457
inv = b.read_working_inventory()
404
inv = b.get_revision_inventory(b.lookup_revision(revision))
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]))
406
464
for path, entry in inv.entries():
556
618
br_to = Branch(to_location, init=True)
620
revno = br_to.lookup_revision(revision[0])
559
br_to.update_revisions(br_from, stop_revision=revision)
622
br_to.update_revisions(br_from, stop_revision=revno)
560
623
except NoSuchRevision:
561
624
rmtree(to_location)
562
625
msg = "The branch %s has no revision %d." % (from_location,
564
627
raise BzrCommandError(msg)
565
628
merge((to_location, -1), (to_location, 0), this_dir=to_location,
566
629
check_clean=False, ignore_zero=True)
737
800
b = find_branch('.')
802
# TODO: Make show_diff support taking 2 arguments
804
if revision is not None:
805
if len(revision) != 1:
806
raise BzrCommandError('bzr diff --revision takes exactly one revision identifier')
807
base_rev = revision[0]
739
show_diff(b, revision, specific_files=file_list,
809
show_diff(b, base_rev, specific_files=file_list,
740
810
external_diff_options=diff_options)
847
917
b = find_branch('.')
851
revision = [None, None]
852
elif isinstance(revision, int):
853
revision = [revision, revision]
923
elif len(revision) == 1:
924
rev1 = rev2 = b.get_revision_info(revision[0])[0]
925
elif len(revision) == 2:
926
rev1 = b.get_revision_info(revision[0])[0]
927
rev2 = b.get_revision_info(revision[1])[0]
858
assert len(revision) == 2
929
raise BzrCommandError('bzr log --revision takes one or two values.')
860
936
mutter('encoding log as %r' % bzrlib.user_encoding)
1040
1116
def run(self, dest, revision=None, format=None, root=None):
1042
1118
b = find_branch('.')
1043
if revision == None:
1044
rh = b.revision_history()[-1]
1119
if revision is None:
1120
rev_id = b.last_patch()
1046
rh = b.lookup_revision(int(revision))
1047
t = b.revision_tree(rh)
1122
if len(revision) != 1:
1123
raise BzrError('bzr export --revision takes exactly 1 argument')
1124
revno, rev_id = b.get_revision_info(revision[0])
1125
t = b.revision_tree(rev_id)
1048
1126
root, ext = os.path.splitext(dest)
1050
1128
if ext in (".tar",):
1067
1145
def run(self, filename, revision=None):
1068
1146
if revision == None:
1069
1147
raise BzrCommandError("bzr cat requires a revision number")
1148
elif len(revision) != 1:
1149
raise BzrCommandError("bzr cat --revision takes exactly one number")
1070
1150
b = find_branch('.')
1071
b.print_file(b.relpath(filename), int(revision))
1151
b.print_file(b.relpath(filename), revision[0])
1074
1154
class cmd_local_time_offset(Command):
1297
1383
takes_options = ['revision']
1299
def run(self, revision=-1):
1385
def run(self, revision=None):
1300
1386
from bzrlib.merge import merge
1301
merge(('.', revision), parse_spec('.'),
1387
if revision is None:
1389
elif len(revision) != 1:
1390
raise BzrCommandError('bzr merge-revert --revision takes exactly 1 argument')
1391
merge(('.', revision[0]), parse_spec('.'),
1302
1392
check_clean=False,
1303
1393
ignore_zero=True)
1387
1477
>>> parse_args('commit --message=biter'.split())
1388
1478
(['commit'], {'message': u'biter'})
1389
1479
>>> parse_args('log -r 500'.split())
1390
(['log'], {'revision': 500})
1391
>>> parse_args('log -r500:600'.split())
1480
(['log'], {'revision': [500]})
1481
>>> parse_args('log -r500..600'.split())
1392
1482
(['log'], {'revision': [500, 600]})
1393
>>> parse_args('log -vr500:600'.split())
1483
>>> parse_args('log -vr500..600'.split())
1394
1484
(['log'], {'verbose': True, 'revision': [500, 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
1485
>>> parse_args('log -rv500..600'.split()) #the r takes an argument
1486
(['log'], {'revision': ['v500', 600]})