Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit » JGIT Get Path
JGIT Get Path [message #988931] Mon, 03 December 2012 20:33 Go to next message
Daniel Wurz is currently offline Daniel Wurz
Messages: 4
Registered: December 2012
Junior Member
I am looking to get the path of a commit (ie ... "/file/path/file.java")

I am able to walk through the commits using Revwalk. However, how do I get the path from the commit?

Thanks all
Re: JGIT Get Path [message #989048 is a reply to message #988931] Tue, 04 December 2012 12:41 Go to previous messageGo to next message
Christian Halstrick is currently offline Christian Halstrick
Messages: 106
Registered: July 2009
Senior Member
I think there is nothing like a "path of a commit". Commits have ID's. But you can ask the commit about the pathes of all the files in the repository (all version controlled files at the moment that commit was created). Something like:

  RevCommit commit=...
  final TreeWalk walk = new TreeWalk(db);
  walk.setRecursive(recursive);
  walk.addTree(commit.getTree());
  while (walk.next())
    outw.print(walk.getPathString());


Ciao
Chris
Re: JGIT Get Path [message #989495 is a reply to message #989048] Thu, 06 December 2012 13:39 Go to previous messageGo to next message
Daniel Wurz is currently offline Daniel Wurz
Messages: 4
Registered: December 2012
Junior Member
Thank you very much for the reply. You've gotten me most of the way there I think.

I am looking to cycle through each commit and find commit information such as commiter,commit time etc.... I am also looking to get the names of all the associated files with the commit. I am able to get the commiter info, but not the names of all the files. Here is my code.


Thanks for the help


CommitListFilter block = new CommitListFilter();
CommitFilter limit = new CommitLimitFilter(1).setStop(true);
AndCommitFilter filters = new AndCommitFilter(limit, block);
CommitCursorFilter cursor = new CommitCursorFilter(filters);
Repository repo = new FileRepository(gitPath);
CommitFinder finder = new CommitFinder(repo);
finder.setFilter(cursor);
RevCommit commit = CommitUtils.getHead(repo);

while (commit != null) {

// System.out.println(commit.getAuthorIdent().getName());
// System.out.println(commit.getAuthorIdent().getEmailAddress());
// System.out.println(commit.getId().getName());

// System.out.println(commit.getAuthorIdent().getWhen());

// System.out.println(walk.getPathString());

finder.findFrom(commit);
commit = cursor.getLast();
cursor.reset();
}
Re: JGIT Get Path [message #990126 is a reply to message #989495] Tue, 11 December 2012 00:47 Go to previous messageGo to next message
Daniel Wurz is currently offline Daniel Wurz
Messages: 4
Registered: December 2012
Junior Member
Also, this returns the "tree" of altered files. I merely want a list of all the files that have changed and where the alterations were.
Re: JGIT Get Path [message #990232 is a reply to message #990126] Tue, 11 December 2012 14:01 Go to previous messageGo to next message
Chris Aniszczyk is currently offline Chris Aniszczyk
Messages: 674
Registered: July 2009
Senior Member
Why don't you just use StatusCommand or DiffCommand from org.eclipse.jgit.api?
Re: JGIT Get Path [message #990344 is a reply to message #990232] Wed, 12 December 2012 04:23 Go to previous message
Daniel Wurz is currently offline Daniel Wurz
Messages: 4
Registered: December 2012
Junior Member
Chris Aniszczyk wrote on Tue, 11 December 2012 09:01
Why don't you just use StatusCommand or DiffCommand from org.eclipse.jgit.api?


Not sure, do you have a code example?
Previous Topic:Help: Unable to merge between two users
Next Topic:eGit
Goto Forum:
  


Current Time: Fri Sep 19 19:54:41 GMT 2014

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

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