Skip to content

Instantly share code, notes, and snippets.

@karronoli
Created January 9, 2012 06:52
Show Gist options
  • Save karronoli/1581558 to your computer and use it in GitHub Desktop.
Save karronoli/1581558 to your computer and use it in GitHub Desktop.
Google bugspots for Mercurial + python
from mercurial import ui, hg
import re
import time
import math
import sys
DEBUG = 0
repo = hg.repository(ui.ui(), sys.argv[1])
message_matchers = re.compile('fix(es|ed)?|close(s|d)?', re.IGNORECASE)
fixes = [
{'message': ctx.description(),
'date': ctx.date()[0],
'files':ctx.files()}
for ctx in [repo.changectx(c) for c in repo.changelog] \
if message_matchers.match(ctx.description())
]
if DEBUG:
print fixes
hotspots = {}
first_commit_date = min([fix['date'] for fix in fixes])
for fix in fixes:
t = 1 - ((time.time() - fix['date']) / (time.time() - first_commit_date))
for filename in fix['files']:
if DEBUG:
print 'tmp:', t, 'now:', time.time(),\
'date:', fix['date'],\
'fixes.last.date:', fixes[0]['date'],\
'1st commit date:', first_commit_date,\
'file:', filename, 'desc:', fix['message']
hotspots[filename] = hotspots.get(filename, 0) \
+ 1.0 / (1.0 + math.exp((-12.0 * t) + 12.0))
print ['%s: %.6f' % (k, hotspots[k]) for k in hotspots]
@karronoli
Copy link
Author

no work on mercurial 2.5 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment