Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] question about commits/trees/parents

On 05/03/2012 04:40 PM, Shawn Pearce wrote:
> On Thu, May 3, 2012 at 5:00 AM, Markus Duft <markus.duft@xxxxxxxxxx> wrote:
>>
>> calling any getter on the parent (like getTree()) yields null or NPE... what am i doing wrong?
> 
> You need to make the RevWalk also parse the parent....

Thanks, that helped a lot :)

Regards,
Markus

> 
>>    /**
>>     * Searches for the commit object associated with the given Gerrit event. If no commit can be
>>     * found, <code>null</code> is returned.
>>     */
>>    public RevCommit getCommit(GerritBaseChangeEvent e) {
>>        GerritPatchset p = e.getPatchset();
>>
>>        if (p == null) {
>>            return null;
>>        }
>>
>>        String rev = p.getRevision();
>>        try {
>>            RevWalk walk = new RevWalk(repo);
>>            return walk.parseCommit(getOidForRev(rev));
> 
> Instead do:
> 
>   RevCommit c = walk.parseCommit(getOidForRev(rev));
>   walk.parseHeaders(c.getParent(0));
>   return c;
> 
> To ensure it can offer good performance, RevWalks only parse the
> minimum number of commits to answer the request. When you parsed the
> one commit here, that only loaded that commit's tree and its parent
> pointers. It didn't walk into the parents and load their trees, or
> their parent pointers. So the only thing we know about the parent is
> that it exists, and what its ObjectId is. We don't know what its tree
> is until we at least parseHeaders on it.


Back to the top