Skip to content

Instantly share code, notes, and snippets.

@kaorimatz
Created December 18, 2012 15:26
Show Gist options
  • Save kaorimatz/4328938 to your computer and use it in GitHub Desktop.
Save kaorimatz/4328938 to your computer and use it in GitHub Desktop.
Display the number of lines that you have changed.
#!/usr/bin/python2.7
from mercurial import patch, scmutil, ui, hg
from datetime import datetime
from time import gmtime
from itertools import groupby
def changedline(ui, repo, ctx1, ctx2):
added, removed = 0, 0
diff = ''.join(patch.diff(repo, ctx1.node(), ctx2.node()))
for line in diff.split('\n'):
if line.startswith('+') and not line.startswith('+++ '):
added += 1
if line.startswith('-') and not line.startswith('--- '):
removed += 1
return (added, removed)
def formatdate(ui, repo, ctx, fmt):
t, tz = ctx.date()
return datetime(*gmtime(t - tz)[:6]).strftime(fmt)
def listchanges(ui, repo, to):
for i in range(to.rev()):
ctx = repo[i]
parents = ctx.parents()
if len(parents) != 1:
continue
if ctx.user() != user:
continue
changed = changedline(ui, repo, parents[0], ctx)
date = formatdate(ui, repo, ctx, '%Y/%m')
yield ctx, changed, date
if __name__ == '__main__':
repo = hg.repository(ui.ui(), '.')
ui = repo.ui
user = ui.username()
print 'USER:', user
print 'CHANGES:'
tip = repo.changectx('tip')
for date, changes in groupby(listchanges(ui, repo, tip), lambda x: x[2]):
added, removed = 0, 0
for c in changes:
added += c[1][0]
removed += c[1][1]
print ' %s: %6s(added) %6s(removed)' % (date, added, removed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment