Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » JGit iterate all files of a commit
JGit iterate all files of a commit [message #1201773] Thu, 21 November 2013 22:41 Go to next message
Philipp Marx is currently offline Philipp MarxFriend
Messages: 1
Registered: November 2013
Junior Member

I am building a custom workflow around JGit. I have a bare repository and create blobs and commits directly (i.e. without an index) via the API.

My workflow includes the following:

1. Create an "file" at path "1/1/prop/XYZ"
2. Create a commit
3. Retrieve the "tree" at path "1/1/prop"

Currently I am using the ObjectWalk to get the tree object at step #3.

ObjectWalk objectWalk = new ObjectWalk(getObjectReader());
RevCommit revCommit = objectWalk.parseCommit(commitId);
revCommit =;
RevObject revObject;
while ((revObject = objectWalk.nextObject()) != null)
if (objectWalk path equals to path I look for)
// do my stuff

This works fine so far. In the following there is a difference though:

1. Create an "file" at path "1/1/prop/XYZ"
2. Create an "file" at path "1/2/prop/XYZ" (with the same content as "1/1/prop/XYZ"!)
3. Create a commit
4. Retrieve the "tree" at path "1/2/prop"

The ObjectWalk will never iterate to the object "1/2/prop" because it has the same "contentId" as "1/1/prop". Internally it is marked as "SEEN". I can remove the "SEEN" flag on each object in my loop but I am not sure if this is the most elegant way to do this.

Can somebody think of a better way to iterate through the tree?

Re: JGit iterate all files of a commit [message #1216675 is a reply to message #1201773] Thu, 28 November 2013 15:33 Go to previous message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1122
Registered: July 2009
Senior Member
Use a TreeWalk
Previous Topic:Error pushing to remote
Next Topic:'Git Grep Search' in Egit
Goto Forum:

Current Time: Fri Feb 21 13:34:16 GMT 2020

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

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

Back to the top