Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Track a repo manifest's project count over time using GitPython. Prints simple "datetime count" table.
import os
from git import Repo
import datetime as dt
import xml.etree.ElementTree as ET
repo = Repo('/home/klaus/stats/manifests')
target_file = 'manifest.xml'
assert not repo.bare
manifest_cts = list(repo.iter_commits(paths=target_file))
for ct in reversed(manifest_cts):
date = dt.datetime.utcfromtimestamp(ct.committed_date).isoformat()
# print(ct.hexsha, date, ct.summary)
blob = ct.tree / target_file
root = ET.fromstring(blob.data_stream.read())
proj_count = len(root.findall('./project'))
print(date, proj_count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment