Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] JGit iterate all files of a commit

Hi Matthias,

TreeWalk will only return the "file" objects. I.e. in the above workflow when adding "1/1/prop/XYZ" and "1/2/prop/XYZ" it will only return those two. I need the "tree" object itself i.e. "1/1".


2013/11/22 Matthias Sohn <matthias.sohn@xxxxxxxxx>
On Fri, Nov 22, 2013 at 12:48 PM, Philipp Marx <smigfu@xxxxxxxxxxxxxx> wrote:

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.

you could consider to use an in-core DirCache to update trees without
using a working tree in the filesystem
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?

Use a TreeWalk, initialize it with the root tree you can get from RevCommit, 
set tree filters you need and walk the tree.


Back to the top