iterating over revisions in a branch
Jamie Wilkinson
jaq at spacepants.org
Wed Jan 4 13:24:37 GMT 2006
This one time, at band camp, Jelmer Vernooij wrote:
>On Wed, Jan 04, 2006 at 11:56:24PM +1100, Jamie Wilkinson wrote about 'iterating over revisions in a branch':
>> Rob gave me a hint on how to iterate over revisoins in a branch:
>
>> for revision_id in branch.revision_history():
>> revision = branch.get_revision(revision_id)
>
>> It occurred to me just now that it doesn't feel right. If I'm iterating
>> over revisions, I shouldn't have to extract the revision during the body of
>> the iterator loop, surely instead of the revision id I should get back the
>> whole revision?
>
>Efficiency. The list of revision ids can be read directly from the
>.bzr/revision-history file. Reading the revision itself requires reading
>the appropriate file in .bzr/revisions/ (amongst other files).
>
>If, for example, you would only want to do something with the last two
>revisions, that would not require reading all revisions that exist in
>the revision history. Also, for things like 'revno' (which is
>basically length(branch.revision_history()) the revision contents don't
>matter.
Ok.
Still, I think that something that returns an iterator over the *id*s of
revisions should be named as such, from an OO point of view. I'm still
surprised that revision_history() didn't give me a list of Revision objects.
Would it be worth making Branch.__iter__() perform this function?
for revision in branch:
print revision.id
Or if that's not readable, a .revisions() method?
for revision in branch.revisions():
print revision.id
Also, the efficient revision_history() as it stands doesn't feel useful
outside of bzr internals. Well, sure it's efficient, but as a programmer
using the bzrlib API I don't care about the internals of bzr, and well, I'm
back to the OO argument: if I'm iterating over revisions, I want a Revision
object :)
More information about the bazaar
mailing list