153
154
# RevisionSpec_revno is special cased, because it is the only
154
155
# one that directly handles plain integers
156
# TODO: This should not be special cased rather it should be
157
# a method invocation on spectype.canparse()
155
158
global _revno_regex
156
159
if _revno_regex is None:
157
_revno_regex = re.compile(r'-?\d+(:.*)?$')
160
_revno_regex = re.compile(r'^(?:(\d+(\.\d+)*)|-\d+)(:.*)?$')
158
161
if _revno_regex.match(spec) is not None:
159
162
return RevisionSpec_revno(spec, _internal=True)
257
262
revno = int(revno_spec)
258
except ValueError, e:
259
raise errors.InvalidRevisionSpec(self.user_spec,
265
# dotted decimal. This arguably should not be here
266
# but the from_string method is a little primitive
267
# right now - RBC 20060928
269
match_revno = tuple((int(number) for number in revno_spec.split('.')))
270
except ValueError, e:
271
raise errors.InvalidRevisionSpec(self.user_spec, branch, e)
276
# the user has override the branch to look in.
277
# we need to refresh the revision_history map and
263
279
from bzrlib.branch import Branch
264
280
branch = Branch.open(branch_spec)
265
281
# Need to use a new revision history
266
282
# because we are using a specific branch
267
283
revs = branch.revision_history()
270
if (-revno) >= len(revs):
288
last_rev = branch.last_revision()
289
merge_sorted_revisions = tsort.merge_sort(
290
branch.repository.get_revision_graph(last_rev),
294
return item[3] == match_revno
295
revisions = filter(match, merge_sorted_revisions)
298
if len(revisions) != 1:
299
return RevisionInfo(branch, None, None)
273
revno = len(revs) + revno + 1
275
revision_id = branch.get_rev_id(revno, revs)
276
except errors.NoSuchRevision:
277
raise errors.InvalidRevisionSpec(self.user_spec, branch)
301
# there is no traditional 'revno' for dotted-decimal revnos.
302
# so for API compatability we return None.
303
return RevisionInfo(branch, None, revisions[0][1])
306
if (-revno) >= len(revs):
309
revno = len(revs) + revno + 1
311
revision_id = branch.get_rev_id(revno, revs)
312
except errors.NoSuchRevision:
313
raise errors.InvalidRevisionSpec(self.user_spec, branch)
278
314
return RevisionInfo(branch, revno, revision_id)
280
316
def needs_branch(self):