Skip to content

Instantly share code, notes, and snippets.

@charlieman
Created May 1, 2011 18:46
Show Gist options
  • Save charlieman/950725 to your computer and use it in GitHub Desktop.
Save charlieman/950725 to your computer and use it in GitHub Desktop.
Script that shows a list of all files in a git repo and the date and message of the last commit on it
#!/usr/bin/env python
import git
from email.utils import parsedate_tz
from time import strftime
def tree_walk(tree, path=''):
for name, obj in tree.items():
if isinstance(obj, git.Tree):
for filename in tree_walk(obj, name):
yield ("%s/%s " % (path, filename)).strip('/')
continue
yield ("%s/%s " % (path, name)).strip('/')
def list_from_string(repo, text):
"""
Parse out commit information into a list of Commit objects
``repo``
is the Repo
``text``
is the text output from the git command (raw format)
Returns
git.Commit[]
"""
lines = [l for l in text.splitlines() if l.strip()]
while lines:
id = lines.pop(0).split()[1]
author = lines.pop(0).split(' ', 1)[1]
date = parsedate_tz(lines.pop(0).split(' ', 1)[1].strip())
messages = []
while lines and lines[0].startswith(' '):
messages.append(lines.pop(0).strip())
message = '\n'.join(messages)
yield id, author, date, message
def main():
repo = git.Repo('.')
for filename in tree_walk(repo.tree()):
out = repo.git.log(filename.strip(), max_count=1)
for id, author, date, message in list_from_string(repo, out):
print "{0:<60} {1} {2}".format(filename, strftime('%b %d %H:%M', date[:-1]), message[0:60])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment