Get revisions affecting a file?
John Arbash Meinel
john at arbash-meinel.com
Wed Dec 2 15:40:08 GMT 2009
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Michael Gliwinski wrote:
> On Tuesday 01 December 2009 15:56:45 John Arbash Meinel wrote:
>>> wt = WorkingTree.open_containing('.')[0]
>> wt.lock_read()
>> basis = wt.basis_tree()
>> basis.lock_read()
>> file_id = wt.path2id(filename)
>> basis_ie = basis.inventory[file_id]
>> file_key = (file_id, basis_ie.revision)
>> texts = wt.branch.repository.texts
>>
>> # loop over this
>> texts.get_parent_map([file_key])
>>
>> This will give you the revisions that actually modified the file, but
>> not revisions that merged those changes (which log includes).
>
> Thanks for the tip John, that seems easier indeed. I'll have to ask some
> followup questions as I'm only starting to dig into bzrlib and some things
> aren't clear to me yet.
>
> So basically texts.get_parent_map returns a map of specified file_keys to a
> tuple of tuples, each of which represents what exactly? And how are they
> ordered?
>
> Specifically I'll want to use that to obtain the most recent revision where
> that file was modified and it's date. Would that be the first tuple? Or are
> they unordered?
basis_ie.revision is the last modification of a file (provided it isn't
modified on disk).
You can use:
rev = wt.repository.get_revision(basis_ie.revision)
To turn that revision-id into a Revision object which has
"self.timestamp" as the seconds-since-epoch when the file was committed.
>
> Also, maybe I'm getting confused here, but how are revisions represented in
> the code, are they tuples? Some places also refer to Revision objects, how
> can these be obtained?
>
> Feel free to give me a pointer to somewhere in the code where this is used,
> I'll read through it and figure out as much as I can :) Also, I may be
> missing something fundamental, I admit I didn't have time to read through all
> developer docs just yet, so I apologise, I'm getting there though.
>
>
A revision_id is a simple string that implies a revision. You can use
"repo.get_revision(revision_id)" to get the Revision object described.
You can also use the revision id to get the inventory (tree-shape
information), and other such objects.
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAksWilcACgkQJdeBCYSNAAPIYwCeNGblwKrClEwy5Lusl1V1LTov
vH8AnA1peWjfoX/VmFo+dprF170bg1Sm
=IYzD
-----END PGP SIGNATURE-----
More information about the bazaar
mailing list