From 58829de5bc2b02f4ef8632b61d22b78001eb2043 Mon Sep 17 00:00:00 2001
From: Jeremy Stanley <fungi@yuggoth.org>
Date: Fri, 26 Sep 2014 14:50:22 +0000
Subject: [PATCH] Allow a git ref to pin the governance repo

Change-Id: I230c22fb83447b336eda14a7f10cf33e52e3d321
---
 tools/atc/README         |  2 +-
 tools/atc/email_stats.py | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/tools/atc/README b/tools/atc/README
index 01277f7cac..eeba3f6833 100644
--- a/tools/atc/README
+++ b/tools/atc/README
@@ -14,7 +14,7 @@ elections and Summit invitations.
   . venv/bin/activate
   pip install paramiko requests pyyaml
   ./email_stats.py --begin <BEGINDATE>
-  # optionally specify --end, --keyfile and --user
+  # optionally specify --end, --keyfile, --ref and --user
   DATE=`date --iso`
   mv out $DATE
   cat $DATE/*.csv | sort | uniq > $DATE/all.csv
diff --git a/tools/atc/email_stats.py b/tools/atc/email_stats.py
index 7698c3210f..9dd45b4d8d 100755
--- a/tools/atc/email_stats.py
+++ b/tools/atc/email_stats.py
@@ -188,18 +188,28 @@ def main():
     optparser.add_option(
         '-k', '--keyfile', default='~/.ssh/id_rsa',
         help='SSH key (default is ~/.ssh/id_rsa)')
+    optparser.add_option(
+        '-r', '--ref', default='',
+        help='governance git ref (e.g. sept-2014-elections')
     optparser.add_option(
         '-u', '--user', default=os.environ['USER'],
         help='SSH username (default is $USER)')
     options, args = optparser.parse_args()
 
-    for project in get_projects(PROGRAMS_URL):
+    if options.ref:
+        programs_url = '%s?id=%s' % (PROGRAMS_URL, options.ref)
+        extra_atcs_url = '%s?id=%s' % (EXTRA_ATCS_URL, options.ref)
+    else:
+        programs_url = PROGRAMS_URL
+        extra_atcs_url = EXTRA_ATCS_URL
+
+    for project in get_projects(programs_url):
         output = 'out/%s.csv' % project.split('/')[-1]
         project_stats(project, output, options.begin, options.end,
                       options.keyfile, options.user)
 
     writer = csv.writer(open('out/extra-atcs.csv', 'w'))
-    for atc in get_extra_atcs(EXTRA_ATCS_URL):
+    for atc in get_extra_atcs(extra_atcs_url):
         try:
             writer.writerow([''] + list(EXTRA_ATC_RE.match(atc).groups()))
         except AttributeError: