|Re: [jgit-dev] parents array not set correctly in a RevCommit|
On Sat, Jan 22, 2011 at 03:46, Jan Finis <finis@xxxxxxxxx> wrote: > > The commit was aquired by first parsing a commit from a rev walk ( > revWalk.parseCommit(ref.getObjectId()) ) and then following the parents > hierarchy. The first parents array is not empty. But after taking the parent > commit, its parents are empty. Correct. RevWalk only parses the object its given. If it parsed all the way back to the initial commit of the repository, it would take a very long time, and a very large amount of memory, and most users only need the most recent few commits. So its a performance optimization. Likewise we don't try to magically load parents on demand like a SQL ORM might try to do for you. That would require back references from RevCommit to its parent RevWalk, which increases the memory used by RevCommit by at least one more pointer. Because we sometimes need to load 100,000+ RevCommits at once, we try hard to limit how much data we put into a RevCommit. > This leads me to believe that the parents > fields are only set correctly if the commit was acquired via parseCommit. > How can I resolve those parents? Take the commit's object id and let the > revWalk parse it? Yes. Or better, use parseHeaders(): RevCommit commit = rw.parseCommit(theId); RevCommit parent = commit.getParent(0); rw.parseHeaders(parent); -- Shawn.
Back to the top