Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit » 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
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.

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?


Cheers
Philipp
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: 612
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 Dec 19 15:17:11 GMT 2014

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

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