Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 92 lines (74 sloc) 2.501 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
#!/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

SEARCH_DEPTH = 10000
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
    myui.pushbuffer()
    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")
      myui.pushbuffer()
      commands.diff(myui, repo, change="qtip", git=True)
      diff = myui.popbuffer()
    else:
      print("Patch source: current diff")
  else:
    diff = url.open(myui, 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():
        changes[file].append(rev)

  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

  print "Potential super-reviewers:"
  for (reviewer, count) in supersuckers.most_common(10):
    print " %s: %d" % (reviewer, count)
  print

  print "Potential ui-reviewers:"
  for (reviewer, count) in uisuckers.most_common(10):
    print " %s: %d" % (reviewer, count)
  print

  return 0

if __name__ == "__main__":
    sys.exit(main())

Something went wrong with that request. Please try again.