336
336
:return: A (mainline_revs, rev_nos, start_rev_id, end_rev_id) tuple.
338
which_revs = _enumerate_history(branch)
338
branch_revno, branch_last_revision = branch.last_revision_info()
339
if branch_revno == 0:
340
340
return None, None, None, None
342
342
# For mainline generation, map start_revision and end_revision to
349
349
if start_revision is None:
352
if isinstance(start_revision,RevisionInfo):
352
if isinstance(start_revision, RevisionInfo):
353
353
start_rev_id = start_revision.rev_id
354
354
start_revno = start_revision.revno or 1
360
360
if end_revision is None:
361
361
end_revno = len(which_revs)
363
if isinstance(end_revision,RevisionInfo):
363
if isinstance(end_revision, RevisionInfo):
364
364
end_rev_id = end_revision.rev_id
365
365
end_revno = end_revision.revno or len(which_revs)
374
374
raise BzrCommandError("Start revision must be older than "
375
375
"the end revision.")
377
# list indexes are 0-based; revisions are 1-based
378
cut_revs = which_revs[(start_revno-1):(end_revno)]
377
if (end_revno < start_revno):
380
378
return None, None, None, None
379
cur_revno = branch_revno
382
for revision_id in branch.repository.iter_reverse_revision_history(
383
branch_last_revision):
384
if cur_revno < start_revno:
385
# We have gone far enough
386
# import pdb; pdb.set_trace()
387
rev_nos[revision_id] = cur_revno
388
mainline_revs.append(revision_id)
390
if cur_revno <= end_revno:
391
rev_nos[revision_id] = cur_revno
392
mainline_revs.append(revision_id)
382
# convert the revision history to a dictionary:
383
rev_nos = dict((k, v) for v, k in cut_revs)
395
mainline_revs.reverse()
385
397
# override the mainline to look like the revision history.
386
mainline_revs = [revision_id for index, revision_id in cut_revs]
387
if cut_revs[0][0] == 1:
388
mainline_revs.insert(0, None)
390
mainline_revs.insert(0, which_revs[start_revno-2][1])
391
398
return mainline_revs, rev_nos, start_rev_id, end_rev_id