Skip to content

Instantly share code, notes, and snippets.

@saml
Created June 17, 2011 17:12
Show Gist options
  • Select an option

  • Save saml/1031819 to your computer and use it in GitHub Desktop.

Select an option

Save saml/1031819 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
'parses `svn log` and outputs as one line per commit'
import sys
import re
import datetime
user_filter = None
if len(sys.argv) > 1:
user_filter = sys.argv[1]
regex_start = re.compile(r'^r(\d+) \| ([^ \|]+) \| (\d+-\d{2}-\d{2}) .+$')
regex_end = re.compile(r'^-+$')
should_skip = user_filter is not None
for line in sys.stdin:
m = regex_start.match(line)
if m:
rev = int(m.group(1),10)
username = m.group(2)
date = datetime.datetime.strptime(m.group(3), '%Y-%m-%d')
comments = []
for line in sys.stdin:
m = regex_end.match(line)
if m:
break
else:
stripped = line.strip()
if len(stripped) > 0:
comments.append(stripped)
if user_filter:
should_skip = True
if user_filter == username:
should_skip = False
if not should_skip:
print('%d\t%s\t%s\t%s' % (rev, username, date.strftime('%Y-%m-%d'), ' '.join(comments)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment