Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » JGit missing parents in Git Log
JGit missing parents in Git Log [message #1856947] Tue, 10 January 2023 15:05 Go to next message
Ralph Collett is currently offline Ralph CollettFriend
Messages: 3
Registered: January 2023
Junior Member
Hi there, I am stuck on an issue with JGit where I perform a Git log and iterate the commits. For each I iterate the parent commits and their parents (etc) to find out what has been merged in for certain merge commits.

This works fine but on occasions the parent for a commit is null when based on the Git tree there is a commit.

Does anyone have any advice on what the cause might be or any further information I could provide to help debug? Is there any optimisations for performance where a certain level of depth for a tree is not present when a Git log is done?

I am using JGit version 5.13.1.

Thank you.
Re: JGit missing parents in Git Log [message #1856965 is a reply to message #1856947] Wed, 11 January 2023 08:24 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1268
Registered: July 2009
Senior Member
I don't understand what your are trying to achieve and how you tried that.

5.13.1 is a pretty old JGit version. Latest release is 6.4.0
Re: JGit missing parents in Git Log [message #1857158 is a reply to message #1856965] Fri, 20 January 2023 10:16 Go to previous messageGo to next message
Ralph Collett is currently offline Ralph CollettFriend
Messages: 3
Registered: January 2023
Junior Member
Thank you for getting back to me. I have updated to the latest version and still have the issue. Hopefully this example code block will demonstrate the problem.

If I am searching for the parents of all commits recursively I am hitting instances where RevCommit sometimes has parents as null (and many other fields) despite the real Git log showing it should have a parent.

public void demo(File sourceCode, AnyObjectId start, AnyObjectId finish) throws IOException, GitAPIException {
        Git git = new Git(new FileRepositoryBuilder().setWorkTree(sourceCode).build());
        Iterable<RevCommit> commits = git.log().addRange(start, finish).call();
        for (RevCommit commit : commits) {
            getParents(commit);
        }
    }

    public List<RevCommit> getParents(RevCommit commit) {
        if (commit.getParents() == null || commit.getParents().length == 0) {
            return Collections.singletonList(commit);
        } else {
            List<RevCommit> parents = new ArrayList<>();
            parents.add(commit);
            for (RevCommit parent : commit.getParents()) {
                parents.addAll(getParents((parent)));
            }
            return parents;
        }
    }


When debugging I hit a RevCommit with
tree == null
parents == null
commitTime == 0
inDegree = 0
buffer == null
flags == 0
next == null

I have drafted this for demo due to restrictions of work code I can share but is representative of how to create the issue.
Re: JGit missing parents in Git Log [message #1857326 is a reply to message #1857158] Mon, 30 January 2023 15:39 Go to previous messageGo to next message
Ralph Collett is currently offline Ralph CollettFriend
Messages: 3
Registered: January 2023
Junior Member
Hi, I am just checking whether someone was able to look into my issue?

Thank you, Ralph
Re: JGit missing parents in Git Log [message #1857550 is a reply to message #1857326] Tue, 14 February 2023 23:03 Go to previous message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1268
Registered: July 2009
Senior Member
Traversing the graph of commits is usually done using a RevWalk (that's also used by LogCommand internally).
When loading objects only headers are parsed immediately, if you want all fields initialised you need to use RevWalk#parseCommit.

The demo calls getParents() but doesn't use the result.
Previous Topic:Possible to commit on multiple repo at the same time ?
Next Topic:Remove From View option - Keyboard shortcut
Goto Forum:
  


Current Time: Fri Apr 26 05:49:58 GMT 2024

Powered by FUDForum. Page generated in 0.03309 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top