简体   繁体   中英

How to skip binary files when obtaining list of diff entries from commit in JGit?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM