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

Ah, ok I see. I think my problem is that I setRecursive to true which will cause the TreeWalk to automatically advance to the next file object if it hits a tree. Thanks.


2013/11/22 Philipp Marx <smigfu@xxxxxxxxxxxxxx>
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".

Cheers
Philipp


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

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);
objectWalk.markStart(revCommit);
revCommit = objectWalk.next();
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.

--
Matthias 



Back to the top