0

I'm trying to find a way to get insertions count of each commit with JGit. Is there a way to skip binary files when obtaining the list of diff entries from a commit in JGit? or should I obtain all diff entries, get the path from each and manually check the mime type?

diffs = diffFormatter.scan(directParent, commit);
...
path = repoDirectory + diff.getNewPath();
...
type = Files.probeContentType(Paths.get(path));
if (type ...

I would like to know if I could do this with JGit itself.

1 Answer 1

0

The approach that is sketched in your question should work just fine.

Alternatively you could use DiffFormatter::setPathFilter() to specify a TreeFilter that excludes certain files.

Note, however, that using the working directory to probe the content type may fail if the working copy does not exist or in rare cases yield wrong results if the content type changed.

1
  • first of all, thank you for the answer and.. yes, you're absolutely right with the last remark. i found a way to detect mime type supplying raw byte array. the thing is that detected mime type doesn't suffice to make decision if a file is binary or not.
    – blumch
    Apr 27, 2016 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.