Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » How to list files affected in a commit ?[SOLVED]
How to list files affected in a commit ?[SOLVED] [message #684954] Thu, 16 June 2011 14:21 Go to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 8
Registered: June 2011
Junior Member
Hi People,

I'm currently using JGit and i'm trying to simply list all commits and their respectives changedSet (files modified in each revision).

Although i've managed to browse each "RevCommit", i'm still unable to retrieve this list of files...

Does someone has an idea ?!

Thank you very much

Cédric

Edit : i didn't find any thread in this forum dealing with this concern. if it's the case, i'm sorry for this duplication

[Updated on: Thu, 16 June 2011 18:37]

Report message to a moderator

Re: How to list files affected in a commit ? [message #685037 is a reply to message #684954] Thu, 16 June 2011 17:36 Go to previous messageGo to next message
James Moger is currently offline James MogerFriend
Messages: 8
Registered: June 2011
Junior Member
This example is basically what you want and should work as long as there is a parent. I handle the first commit differently by parsing the tree, but perhaps you can supply a null for the parent tree in this code. Not sure.

And there may be better ways to do this. As you've discovered, finding docs/samples on JGit can be tough. Peeking at the JGit unit tests and other JGit projects is very useful.

RevWalk rw = new RevWalk(repository);
ObjectId head = repository.resolve(Constants.HEAD);
RevCommit commit = rw.parseCommit(head);
RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
df.setRepository(repository);
df.setDiffComparator(RawTextComparator.DEFAULT);
df.setDetectRenames(true);
List<DiffEntry> diffs = df.scan(parent.getTree(), commit.getTree());
for (DiffEntry diff : diffs) {
    System.out.println(MessageFormat.format("({0} {1} {2}", diff.getChangeType().name(), diff.getNewMode().getBits(), diff.getNewPath()));
}
Re: How to list files affected in a commit ? [message #685048 is a reply to message #685037] Thu, 16 June 2011 18:02 Go to previous messageGo to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 8
Registered: June 2011
Junior Member
Thank you so much James ! It'es working well now ! Smile
You're right, it's not that easy to understand the API without any exemple.

In case you can help me again, i'm looking for a manner to access to a particular version of a file. That is, using your code, in more of getting the changeSet of files, i'd like to retrieve or "re-create" the content of this file. I think there's a way to do so. Do you know smth about it ?

Thank you again !

Cédric

[Updated on: Thu, 16 June 2011 18:29]

Report message to a moderator

Re: How to list files affected in a commit ? [message #685061 is a reply to message #685048] Thu, 16 June 2011 18:36 Go to previous messageGo to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 8
Registered: June 2011
Junior Member
i've found the solution, and so i share it Smile

(i can't share links since i'm new in the forum, so i've removed http)

stackoverflow.com/questions/4777453/looping-over-commits-for-a-file-with-jgit
Re: How to list files affected in a commit ? [message #1014676 is a reply to message #685037] Tue, 26 February 2013 09:11 Go to previous messageGo to next message
xiaochen zhang is currently offline xiaochen zhangFriend
Messages: 1
Registered: February 2013
Junior Member
Hey, I also tried your code, it works fine for all the commits but not the initial one, since the initial commit does not have any parent commits, so the code gives an error message. Could you tell me how you solved this problem? thanks.
Re: How to list files affected in a commit ?[SOLVED] [message #1016031 is a reply to message #684954] Mon, 04 March 2013 16:18 Go to previous message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 8
Registered: June 2011
Junior Member
Hi

I think you should identify the code that throws the error, and apply a simple null checking to avoid the errors. I'm not sure what happens with the initial commit, but i think it must have a null parent.

Then, to get the initial files, simply find the working copy of the repo at this commit.
Previous Topic:egit upgrade fails due to conflicting dependency
Next Topic:Stash Apply
Goto Forum:
  


Current Time: Tue Mar 19 09:18:22 GMT 2024

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

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

Back to the top