Home > Mobile >  Calculating lines of change from a Git diff file
Calculating lines of change from a Git diff file

Time:06-12

The goal

I am building a git stats script in Python that can only access the historical git diff patches, so basically files like this

diff --git a/README b/README
index 980a0d5f..fef29374 100644
--- a/README
    b/README
@@ -1  1,3 @@
 Hello World!
 
 Hello planet! - DD
\ No newline at end of file

What do I want exactly?

  1. Take a list of git diff files as input
  2. Calculate how many lines were changed (optional), added and removed in each diff file
  3. Sum it all up
  4. Print "total lines added = X, total lines removed = Y" etc.

Constraints

The system running this script does not have access to the git repository, nor does it have git installed - introducing an interesting complication.

  • Related