When we do git log --shortstat
we get the number of lines inserted, deleted, and changed. Something like:
1 file changed, 9 insertions(+), 3 deletions(-)
Please help me with getting the number of lines inserted, deleted, and changed.
I am doing a repository clone to get git project on local machine. Here is the same code:
RepoClone repoClone = new RepoClone(); repoClone.repoCloner(); repository = builder.setGitDir(repoClone.repoDir).setMustExist(true).build();
I am even able to get a
TreeWalk
:TreeWalk treeWalk = getCommitsTreeWalk();
I am able to retrieve file name, count of number of commits per file, LOC, and the number of developers who worked on each xml/ java file.
while (treeWalk.next()) { if (treeWalk.getPathString().endsWith(".xml") || treeWalk.getPathString().endsWith(".java")) { jsonDataset = new JSONObject(); countDevelopers = new HashSet<String>(); count = 0; logs = new Git(repository).log().addPath(treeWalk.getPathString()).call(); for (RevCommit rev: logs) { countDevelopers.add(rev.getAuthorIdent().getEmailAddress()); count++; } jsonDataset.put("FileName", treeWalk.getPathString()); jsonDataset.put("CountDevelopers", countDevelopers.size()); jsonDataset.put("CountCommits", count); jsonDataset.put("LOC", countLines(treeWalk.getPathString())); commitDetails.put(jsonDataset); } }
Now, I want to retrieve the number of lines inserted and deleted for each file.