Skip to content

Instantly share code, notes, and snippets.

@klausbrunner
Last active October 3, 2016 08:07
Show Gist options
  • Save klausbrunner/0652a060239828c07d2ede6f233a9099 to your computer and use it in GitHub Desktop.
Save klausbrunner/0652a060239828c07d2ede6f233a9099 to your computer and use it in GitHub Desktop.
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