How to get lines changed for each file in a diff in pygit2

Viewed 161

Using, pygit2, I can get the total number of files changed, total insertions, total deletions, and the relative path of the files. See below code. However, I can't find a way to get the stats on lines changed for each modified files like git diff --stats shows. Can I do it in pygit2?

def get_diff_stats(repo_path, commit_a, commit_b):
    repo = Repository("{}/.git".format(repo_path))
    diff = repo.diff(commit_a, commit_b)
    print(diff.stats.files_changed)
    print(diff.stats.insertions)
    print(diff.stats.deletions)

    for delta in diff.deltas:
        print(delta.new_file.path, delta.status_char())
0 Answers
Related