git_log_to_array.py 893 B

1234567891011121314151617181920212223242526272829
  1. """ Dump the git log to a file """
  2. __author__ = "Kristian Berg"
  3. __copyright__ = "Copyright (c) 2018 Axis Communications AB"
  4. __license__ = "MIT"
  5. import subprocess
  6. import sys
  7. import json
  8. # Commits are saved in reverse chronological order from newest to oldest
  9. if __name__ == '__main__':
  10. path_to_repo = sys.argv[1]
  11. hashes = subprocess.run(['git', 'rev-list', '02d6908ada70fcf8012833ddef628bc09c6f8389'], cwd=path_to_repo,
  12. stdout=subprocess.PIPE).stdout.decode('ascii').split()
  13. logs = []
  14. i = 0
  15. for hash in hashes:
  16. entry = subprocess.run(['git', 'show', '--quiet', '--date=iso', hash],
  17. cwd=path_to_repo, stdout=subprocess.PIPE)\
  18. .stdout.decode(errors='replace')
  19. logs.append(entry)
  20. i += 1
  21. if i % 10 == 0:
  22. print(i, end='\r')
  23. with open('gitlog.json', 'w') as f:
  24. f.write(json.dumps(logs))