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
359
359
end_rev_id = None
360
360
if end_revision is None:
361
end_revno = len(which_revs)
361
end_revno = branch_revno
363
if isinstance(end_revision,RevisionInfo):
363
if isinstance(end_revision, RevisionInfo):
364
364
end_rev_id = end_revision.rev_id
365
end_revno = end_revision.revno or len(which_revs)
365
end_revno = end_revision.revno or branch_revno
367
367
branch.check_real_revno(end_revision)
368
368
end_revno = end_revision
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, but we always add 1 more revision
386
rev_nos[revision_id] = cur_revno
387
mainline_revs.append(revision_id)
389
if cur_revno <= end_revno:
390
rev_nos[revision_id] = cur_revno
391
mainline_revs.append(revision_id)
394
# We walked off the edge of all revisions, so we add a 'None' marker
395
mainline_revs.append(None)
382
# convert the revision history to a dictionary:
383
rev_nos = dict((k, v) for v, k in cut_revs)
397
mainline_revs.reverse()
385
399
# 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
400
return mainline_revs, rev_nos, start_rev_id, end_rev_id