libgit2 / libgit2/pygit2

How to efficiently generating the diffstat?

Open
#894 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.7k
Forks
408
Avg merge
2d 57m
Merged PRs (30d)
7

Description

Hi,

I need some help to efficiently generating the diffstat. I would like to get the number of lines added and deleted from one commit to another, like the following command does:

git log --stat

I wrote the following code, but it is pretty slow.

for raw_parent in self.__raw_commit.parents:
    diff = self.__raw_commit.tree.diff_to_tree(raw_parent.tree)
    self._stats.insertions += diff.stats.insertions
    self._stats.deletions += diff.stats.deletions
    self._stats.files_changed += diff.stats.files_changed

Do you know a better way to capture this information?

Best regards,

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Python loop over self.__raw_commit.parents and the tree.diff_to_tree and diff.stats entry points, then compare its goal with git log --stat. Determine whether pygit2 or libgit2 exposes a more efficient way to obtain insertions, deletions, and files changed; done means the approach is identified and produces equivalent diffstat values.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, python
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.