Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 92 lines (74 sloc) 2.44 KB
#!/usr/bin/env python
from collections import Counter
from mercurial import cmdutil, commands, hg, ui, url
from optparse import OptionParser
import os
import re
import sys
aliases = { 'lw': "luke",
'philringnalda': "philor",
fileRe = re.compile(r"^\+\+\+ (?:b/)?([^\s]*)", re.MULTILINE)
suckerRe = re.compile(r"[^s-]r=(\w+)")
supersuckerRe = re.compile(r"sr=(\w+)")
uisuckerRe = re.compile(r"ui-r=(\w+)")
def canon(reviewer):
reviewer = reviewer.lower()
return aliases.get(reviewer, reviewer)
def main(argv=None):
if argv is None:
argv = sys.argv
parser = OptionParser()
(options, args) = parser.parse_args()
myui = ui.ui()
repo = hg.repository(myui, cmdutil.findrepo(os.getcwd()))
if len(args) == 0:
# we should use the current diff, or if that is empty, the top applied
# patch in the patch queue
commands.diff(myui, repo, git=True)
diff = myui.popbuffer()
changedFiles = fileRe.findall(diff)
if len(changedFiles) == 0:
print("Patch source: top patch in mq queue")
commands.diff(myui, repo, change="qtip", git=True)
diff = myui.popbuffer()
print("Patch source: current diff")
diff =, args[0]).read()
print("Patch source: %s" % args[0])
changedFiles = fileRe.findall(diff)
changes = {}
for changedFile in changedFiles:
changes[changedFile] = []
for revNum in xrange(len(repo) - SEARCH_DEPTH, len(repo)):
rev = repo[revNum]
for file in changedFiles:
if file in rev.files():
suckers = Counter()
supersuckers = Counter()
uisuckers = Counter()
for file in changes:
for change in changes[file]:
suckers.update(canon(x) for x in suckerRe.findall(change.description()))
supersuckers.update(canon(x) for x in supersuckerRe.findall(change.description()))
uisuckers.update(canon(x) for x in uisuckerRe.findall(change.description()))
print "Potential reviewers:"
for (reviewer, count) in suckers.most_common(10):
print " %s: %d" % (reviewer, count)
print "Potential super-reviewers:"
for (reviewer, count) in supersuckers.most_common(10):
print " %s: %d" % (reviewer, count)
print "Potential ui-reviewers:"
for (reviewer, count) in uisuckers.most_common(10):
print " %s: %d" % (reviewer, count)
return 0
if __name__ == "__main__":
Something went wrong with that request. Please try again.