git-stats

a collection of scripts to analyze git repositories
git clone https://git.ce9e.org/git-stats.git

commit
227ed457294495b3f01d4afc59777eecf55ea405
parent
008b65b15a2e097fd208935494f632b5fa241df1
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2025-05-10 19:24
rm git-stats

Diffstat

D git-stats.py 40 ----------------------------------------

1 files changed, 0 insertions, 40 deletions


diff --git a/git-stats.py b/git-stats.py

@@ -1,40 +0,0 @@
    1    -1 import sys
    2    -1 import subprocess
    3    -1 
    4    -1 # TODO aggregate by month/year
    5    -1 
    6    -1 
    7    -1 def run(args):
    8    -1     proc = subprocess.run(args, check=True, stdout=subprocess.PIPE, encoding='utf-8')
    9    -1     return proc.stdout
   10    -1 
   11    -1 
   12    -1 def parse_stats(s):
   13    -1     line = s.splitlines()[-1].split()
   14    -1     insertions = 0
   15    -1     deletions = 0
   16    -1     for i in range(1, len(line)):
   17    -1         if line[i].startswith('insertion'):
   18    -1             insertions = int(line[i - 1], 10)
   19    -1         elif line[i].startswith('deletion'):
   20    -1             deletions = int(line[i - 1], 10)
   21    -1     return insertions, deletions
   22    -1 
   23    -1 p = subprocess.Popen(
   24    -1     ['git', 'rev-list', 'HEAD', '--no-merges'],
   25    -1     stdout=subprocess.PIPE,
   26    -1     encoding='utf-8',
   27    -1 )
   28    -1 
   29    -1 data = {}
   30    -1 
   31    -1 for i, commit in enumerate(p.stdout):
   32    -1     print(i, file=sys.stderr)
   33    -1     date = run(['git', 'show', '-s', '--format=%cs', commit.rstrip()]).rstrip()
   34    -1     data.setdefault(date, [0, 0])
   35    -1     d = parse_stats(run(['git', 'show', '--shortstat', commit.rstrip()]))
   36    -1     data[date][0] += d[0]
   37    -1     data[date][1] += d[1]
   38    -1 
   39    -1 for key, value in data.items():
   40    -1     print(key, *value)