Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@iamaziz
Last active February 15, 2020 01:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamaziz/1019e5a9261132ac2a9a to your computer and use it in GitHub Desktop.
Save iamaziz/1019e5a9261132ac2a9a to your computer and use it in GitHub Desktop.
See the total size growth between a number of consecutive commits in your git project. Based on http://stackoverflow.com/questions/10845051/git-show-total-file-size-difference-between-two-commits/10847242#10847242
#!/usr/bin/env python
"""
Usage:
$ git-file-size-growth <NUM_COMMIT>
note:
- Put `git-file-size-growth` somewhere in your PATH along with `git-file-size-diff`
# see `git-file-size-diff` at: http://stackoverflow.com/questions/10845051/git-show-total-file-size-difference-between-two-commits/10847242#10847242
"""
import os
logs_history = os.popen('git log --oneline').read()
logs = logs_history.split('\n')
log_ids = [l.split(' ')[0] for l in logs if l is not '']
total_commit = len(log_ids) - 1
if total_commit == 0:
print("No git COMMIT found!")
exit()
# get numbe of commit
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("NUM_COMMIT", help="number of commits to show difference in size growth, MAX: {}".format(total_commit), type=int)
args = parser.parse_args()
length = args.NUM_COMMIT
if length > total_commit:
print('NUM_COMMIT exceeds the limit: {}'.format(total_commit))
exit()
for i in range(length):
os.system('git-file-size-diff {0} {1} && echo {0} {1}'.format(log_ids[i + 1], log_ids[i]))
@iamaziz
Copy link
Author

iamaziz commented Apr 22, 2015

In git-file-size-diff, remember to comment the line where it prints the details of size difference for each file:

#!/bin/sh
#. git-sh-setup
args=$(git rev-parse --sq "$@")
eval "git diff-tree -r $args" | {
  total=0
  while read A B C D M P
  do
    case $M in
      M) bytes=$(( $(git cat-file -s $D) - $(git cat-file -s $C) )) ;;
      A) bytes=$(git cat-file -s $D) ;;
      D) bytes=-$(git cat-file -s $C) ;;
      *)
        echo >&2 warning: unhandled mode $M in \"$A $B $C $D $M $P\"
        continue
        ;;
    esac
    total=$(( $total + $bytes ))
    #printf '%d\t%s\n' $bytes "$P" # uncommet to see diff for each file
  done
  echo total $total
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment