325
325
# the branch object.
326
326
from bzrlib.branch import Branch
327
327
branch = Branch.open(branch_spec)
328
# Need to use a new revision history
329
# because we are using a specific branch
330
revs = branch.revision_history()
333
331
branch.lock_read()
345
343
# so for API compatability we return None.
346
344
return RevisionInfo(branch, None, revisions[0])
346
last_revno, last_revision_id = branch.last_revision_info()
349
348
# if get_rev_id supported negative revnos, there would not be a
350
349
# need for this special case.
351
if (-revno) >= len(revs):
350
if (-revno) >= last_revno:
354
revno = len(revs) + revno + 1
353
revno = last_revno + revno + 1
356
355
revision_id = branch.get_rev_id(revno, revs)
357
356
except errors.NoSuchRevision:
358
357
raise errors.InvalidRevisionSpec(self.user_spec, branch)
359
358
return RevisionInfo(branch, revno, revision_id)
360
def in_branch(self, branch, need_revno=True):
361
return self._match_on(branch, None)
361
363
def needs_branch(self):
362
364
return self.spec.find(':') == -1
386
388
revid:aaaa@bbbb-123456789 -> Select revision 'aaaa@bbbb-123456789'
388
391
prefix = 'revid:'
390
def _match_on(self, branch, revs):
393
def _match_on(self, branch, revs, need_revno=True):
391
394
# self.spec comes straight from parsing the command line arguments,
392
395
# so we expect it to be a Unicode string. Switch it to the internal
393
396
# representation.
394
397
revision_id = osutils.safe_revision_id(self.spec, warn=False)
395
return RevisionInfo.from_revision_id(branch, revision_id, revs)
400
# XXX Branch needs a method for incremental
401
# revision_id -> revno resolving without loading
402
# the whole history. (Lukas Lalinsky, 20081203)
403
revs = branch.revision_history()
404
return RevisionInfo.from_revision_id(branch, revision_id, revs)
406
return RevisionInfo(branch, None, revision_id)
408
def in_branch(self, branch, need_revno=True):
409
# Same as RevisionSpec.in_history, but without history loading.
410
return self._match_on(branch, None, need_revno)
397
412
SPEC_TYPES.append(RevisionSpec_revid)