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)
274
279
revno = int(revno_spec)
275
except ValueError, e:
276
raise errors.InvalidRevisionSpec(self.user_spec,
282
# dotted decimal. This arguably should not be here
283
# but the from_string method is a little primitive
284
# right now - RBC 20060928
286
match_revno = tuple((int(number) for number in revno_spec.split('.')))
287
except ValueError, e:
288
raise errors.InvalidRevisionSpec(self.user_spec, branch, e)
293
# the user has override the branch to look in.
294
# we need to refresh the revision_history map and
280
296
from bzrlib.branch import Branch
281
297
branch = Branch.open(branch_spec)
282
298
# Need to use a new revision history
283
299
# because we are using a specific branch
284
300
revs = branch.revision_history()
287
if (-revno) >= len(revs):
305
last_rev = branch.last_revision()
306
merge_sorted_revisions = tsort.merge_sort(
307
branch.repository.get_revision_graph(last_rev),
311
return item[3] == match_revno
312
revisions = filter(match, merge_sorted_revisions)
315
if len(revisions) != 1:
316
return RevisionInfo(branch, None, None)
290
revno = len(revs) + revno + 1
292
revision_id = branch.get_rev_id(revno, revs)
293
except errors.NoSuchRevision:
294
raise errors.InvalidRevisionSpec(self.user_spec, branch)
318
# there is no traditional 'revno' for dotted-decimal revnos.
319
# so for API compatability we return None.
320
return RevisionInfo(branch, None, revisions[0][1])
323
if (-revno) >= len(revs):
326
revno = len(revs) + revno + 1
328
revision_id = branch.get_rev_id(revno, revs)
329
except errors.NoSuchRevision:
330
raise errors.InvalidRevisionSpec(self.user_spec, branch)
295
331
return RevisionInfo(branch, revno, revision_id)
297
333
def needs_branch(self):