summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2012-04-06 15:14:11 +0200
committerOndřej Surý <ondrej@sury.org>2012-04-06 15:14:11 +0200
commit505c19580e0f43fe5224431459cacb7c21edd93d (patch)
tree79e2634c253d60afc0cc0b2f510dc7dcbb48497b /lib
parent1336a7c91e596c423a49d1194ea42d98bca0d958 (diff)
downloadgolang-505c19580e0f43fe5224431459cacb7c21edd93d.tar.gz
Imported Upstream version 1upstream/1
Diffstat (limited to 'lib')
-rw-r--r--lib/codereview/codereview.py1308
-rwxr-xr-xlib/codereview/test.sh198
-rw-r--r--lib/godoc/example.html15
-rw-r--r--lib/godoc/godoc.html109
-rw-r--r--lib/godoc/opensearch.xml11
-rw-r--r--lib/godoc/package.html212
-rw-r--r--lib/godoc/package.txt35
-rw-r--r--lib/godoc/search.html27
-rw-r--r--lib/godoc/search.txt29
-rw-r--r--lib/time/README10
-rwxr-xr-xlib/time/update.bash50
-rw-r--r--lib/time/zoneinfo.zipbin0 -> 370359 bytes
12 files changed, 1333 insertions, 671 deletions
diff --git a/lib/codereview/codereview.py b/lib/codereview/codereview.py
index 63f67fff9..61e2fd772 100644
--- a/lib/codereview/codereview.py
+++ b/lib/codereview/codereview.py
@@ -22,7 +22,7 @@ To configure, set the following options in
your repository's .hg/hgrc file.
[extensions]
- codereview = path/to/codereview.py
+ codereview = /path/to/codereview.py
[codereview]
server = codereview.appspot.com
@@ -38,100 +38,60 @@ For example, if change 123456 contains the files x.go and y.go,
"hg diff @123456" is equivalent to"hg diff x.go y.go".
'''
-from mercurial import cmdutil, commands, hg, util, error, match
-from mercurial.node import nullrev, hex, nullid, short
-import os, re, time
-import stat
-import subprocess
-import threading
-from HTMLParser import HTMLParser
-
-# The standard 'json' package is new in Python 2.6.
-# Before that it was an external package named simplejson.
-try:
- # Standard location in 2.6 and beyond.
- import json
-except Exception, e:
- try:
- # Conventional name for earlier package.
- import simplejson as json
- except:
- try:
- # Was also bundled with django, which is commonly installed.
- from django.utils import simplejson as json
- except:
- # We give up.
- raise e
-
-try:
- hgversion = util.version()
-except:
- from mercurial.version import version as v
- hgversion = v.get_version()
-
-try:
- from mercurial.discovery import findcommonincoming
-except:
- def findcommonincoming(repo, remote):
- return repo.findcommonincoming(remote)
-
-# in Mercurial 1.9 the cmdutil.match and cmdutil.revpair moved to scmutil
-if hgversion >= '1.9':
- from mercurial import scmutil
-else:
- scmutil = cmdutil
-
-oldMessage = """
-The code review extension requires Mercurial 1.3 or newer.
-
-To install a new Mercurial,
-
- sudo easy_install mercurial
-
-works on most systems.
-"""
+import sys
-linuxMessage = """
-You may need to clear your current Mercurial installation by running:
+if __name__ == "__main__":
+ print >>sys.stderr, "This is a Mercurial extension and should not be invoked directly."
+ sys.exit(2)
- sudo apt-get remove mercurial mercurial-common
- sudo rm -rf /etc/mercurial
-"""
+# We require Python 2.6 for the json package.
+if sys.version < '2.6':
+ print >>sys.stderr, "The codereview extension requires Python 2.6 or newer."
+ print >>sys.stderr, "You are running Python " + sys.version
+ sys.exit(2)
-if hgversion < '1.3':
- msg = oldMessage
- if os.access("/etc/mercurial", 0):
- msg += linuxMessage
- raise util.Abort(msg)
+import json
+import os
+import re
+import stat
+import subprocess
+import threading
+import time
-def promptyesno(ui, msg):
- # Arguments to ui.prompt changed between 1.3 and 1.3.1.
- # Even so, some 1.3.1 distributions seem to have the old prompt!?!?
- # What a terrible way to maintain software.
- try:
- return ui.promptchoice(msg, ["&yes", "&no"], 0) == 0
- except AttributeError:
- return ui.prompt(msg, ["&yes", "&no"], "y") != "n"
+from mercurial import commands as hg_commands
+from mercurial import util as hg_util
-# To experiment with Mercurial in the python interpreter:
-# >>> repo = hg.repository(ui.ui(), path = ".")
+defaultcc = None
+codereview_disabled = None
+real_rollback = None
+releaseBranch = None
+server = "codereview.appspot.com"
+server_url_base = None
#######################################################################
# Normally I would split this into multiple files, but it simplifies
# import path headaches to keep it all in one file. Sorry.
+# The different parts of the file are separated by banners like this one.
-import sys
-if __name__ == "__main__":
- print >>sys.stderr, "This is a Mercurial extension and should not be invoked directly."
- sys.exit(2)
+#######################################################################
+# Helpers
-server = "codereview.appspot.com"
-server_url_base = None
-defaultcc = None
-contributors = {}
-missing_codereview = None
-real_rollback = None
-releaseBranch = None
+def RelativePath(path, cwd):
+ n = len(cwd)
+ if path.startswith(cwd) and path[n] == '/':
+ return path[n+1:]
+ return path
+
+def Sub(l1, l2):
+ return [l for l in l1 if l not in l2]
+
+def Add(l1, l2):
+ l = l1 + Sub(l2, l1)
+ l.sort()
+ return l
+
+def Intersect(l1, l2):
+ return [l for l in l1 if l in l2]
#######################################################################
# RE: UNICODE STRING HANDLING
@@ -158,7 +118,7 @@ releaseBranch = None
def typecheck(s, t):
if type(s) != t:
- raise util.Abort("type check failed: %s has type %s != %s" % (repr(s), type(s), t))
+ raise hg_util.Abort("type check failed: %s has type %s != %s" % (repr(s), type(s), t))
# If we have to pass unicode instead of str, ustr does that conversion clearly.
def ustr(s):
@@ -182,12 +142,48 @@ set_mercurial_encoding_to_utf8()
# encoding for all of Python to 'utf-8', not 'ascii'.
def default_to_utf8():
import sys
+ stdout, __stdout__ = sys.stdout, sys.__stdout__
reload(sys) # site.py deleted setdefaultencoding; get it back
+ sys.stdout, sys.__stdout__ = stdout, __stdout__
sys.setdefaultencoding('utf-8')
default_to_utf8()
#######################################################################
+# Status printer for long-running commands
+
+global_status = None
+
+def set_status(s):
+ # print >>sys.stderr, "\t", time.asctime(), s
+ global global_status
+ global_status = s
+
+class StatusThread(threading.Thread):
+ def __init__(self):
+ threading.Thread.__init__(self)
+ def run(self):
+ # pause a reasonable amount of time before
+ # starting to display status messages, so that
+ # most hg commands won't ever see them.
+ time.sleep(30)
+
+ # now show status every 15 seconds
+ while True:
+ time.sleep(15 - time.time() % 15)
+ s = global_status
+ if s is None:
+ continue
+ if s == "":
+ s = "(unknown status)"
+ print >>sys.stderr, time.asctime(), s
+
+def start_status_thread():
+ t = StatusThread()
+ t.setDaemon(True) # allowed to exit if t is still running
+ t.start()
+
+#######################################################################
# Change list parsing.
#
# Change lists are stored in .hg/codereview/cl.nnnnnn
@@ -218,6 +214,7 @@ class CL(object):
self.copied_from = None # None means current user
self.mailed = False
self.private = False
+ self.lgtm = []
def DiskText(self):
cl = self
@@ -262,15 +259,18 @@ class CL(object):
typecheck(s, str)
return s
- def PendingText(self):
+ def PendingText(self, quick=False):
cl = self
s = cl.name + ":" + "\n"
s += Indent(cl.desc, "\t")
s += "\n"
if cl.copied_from:
s += "\tAuthor: " + cl.copied_from + "\n"
- s += "\tReviewer: " + JoinComma(cl.reviewer) + "\n"
- s += "\tCC: " + JoinComma(cl.cc) + "\n"
+ if not quick:
+ s += "\tReviewer: " + JoinComma(cl.reviewer) + "\n"
+ for (who, line) in cl.lgtm:
+ s += "\t\t" + who + ": " + line + "\n"
+ s += "\tCC: " + JoinComma(cl.cc) + "\n"
s += "\tFiles:\n"
for f in cl.files:
s += "\t\t" + f + "\n"
@@ -345,7 +345,7 @@ class CL(object):
uploaded_diff_file = [("data", "data.diff", emptydiff)]
if vcs and self.name != "new":
- form_fields.append(("subject", "diff -r " + vcs.base_rev + " " + getremote(ui, repo, {}).path))
+ form_fields.append(("subject", "diff -r " + vcs.base_rev + " " + ui.expandpath("default")))
else:
# First upload sets the subject for the CL itself.
form_fields.append(("subject", self.Subject()))
@@ -364,7 +364,7 @@ class CL(object):
ui.status(msg + "\n")
set_status("uploaded CL metadata + diffs")
if not response_body.startswith("Issue created.") and not response_body.startswith("Issue updated."):
- raise util.Abort("failed to update issue: " + response_body)
+ raise hg_util.Abort("failed to update issue: " + response_body)
issue = msg[msg.rfind("/")+1:]
self.name = issue
if not self.url:
@@ -389,7 +389,7 @@ class CL(object):
pmsg += " (cc: %s)" % (', '.join(self.cc),)
pmsg += ",\n"
pmsg += "\n"
- repourl = getremote(ui, repo, {}).path
+ repourl = ui.expandpath("default")
if not self.mailed:
pmsg += "I'd like you to review this change to\n" + repourl + "\n"
else:
@@ -542,40 +542,16 @@ def LoadCL(ui, repo, name, web=True):
cl.url = server_url_base + name
cl.web = True
cl.private = d.get('private', False) != False
+ cl.lgtm = []
+ for m in d.get('messages', []):
+ if m.get('approval', False) == True:
+ who = re.sub('@.*', '', m.get('sender', ''))
+ text = re.sub("\n(.|\n)*", '', m.get('text', ''))
+ cl.lgtm.append((who, text))
+
set_status("loaded CL " + name)
return cl, ''
-global_status = None
-
-def set_status(s):
- # print >>sys.stderr, "\t", time.asctime(), s
- global global_status
- global_status = s
-
-class StatusThread(threading.Thread):
- def __init__(self):
- threading.Thread.__init__(self)
- def run(self):
- # pause a reasonable amount of time before
- # starting to display status messages, so that
- # most hg commands won't ever see them.
- time.sleep(30)
-
- # now show status every 15 seconds
- while True:
- time.sleep(15 - time.time() % 15)
- s = global_status
- if s is None:
- continue
- if s == "":
- s = "(unknown status)"
- print >>sys.stderr, time.asctime(), s
-
-def start_status_thread():
- t = StatusThread()
- t.setDaemon(True) # allowed to exit if t is still running
- t.start()
-
class LoadCLThread(threading.Thread):
def __init__(self, ui, repo, dir, f, web):
threading.Thread.__init__(self)
@@ -713,105 +689,6 @@ _change_prolog = """# Change list.
# Multi-line values should be indented.
"""
-#######################################################################
-# Mercurial helper functions
-
-# Get effective change nodes taking into account applied MQ patches
-def effective_revpair(repo):
- try:
- return scmutil.revpair(repo, ['qparent'])
- except:
- return scmutil.revpair(repo, None)
-
-# Return list of changed files in repository that match pats.
-# Warn about patterns that did not match.
-def matchpats(ui, repo, pats, opts):
- matcher = scmutil.match(repo, pats, opts)
- node1, node2 = effective_revpair(repo)
- modified, added, removed, deleted, unknown, ignored, clean = repo.status(node1, node2, matcher, ignored=True, clean=True, unknown=True)
- return (modified, added, removed, deleted, unknown, ignored, clean)
-
-# Return list of changed files in repository that match pats.
-# The patterns came from the command line, so we warn
-# if they have no effect or cannot be understood.
-def ChangedFiles(ui, repo, pats, opts, taken=None):
- taken = taken or {}
- # Run each pattern separately so that we can warn about
- # patterns that didn't do anything useful.
- for p in pats:
- modified, added, removed, deleted, unknown, ignored, clean = matchpats(ui, repo, [p], opts)
- redo = False
- for f in unknown:
- promptadd(ui, repo, f)
- redo = True
- for f in deleted:
- promptremove(ui, repo, f)
- redo = True
- if redo:
- modified, added, removed, deleted, unknown, ignored, clean = matchpats(ui, repo, [p], opts)
- for f in modified + added + removed:
- if f in taken:
- ui.warn("warning: %s already in CL %s\n" % (f, taken[f].name))
- if not modified and not added and not removed:
- ui.warn("warning: %s did not match any modified files\n" % (p,))
-
- # Again, all at once (eliminates duplicates)
- modified, added, removed = matchpats(ui, repo, pats, opts)[:3]
- l = modified + added + removed
- l.sort()
- if taken:
- l = Sub(l, taken.keys())
- return l
-
-# Return list of changed files in repository that match pats and still exist.
-def ChangedExistingFiles(ui, repo, pats, opts):
- modified, added = matchpats(ui, repo, pats, opts)[:2]
- l = modified + added
- l.sort()
- return l
-
-# Return list of files claimed by existing CLs
-def Taken(ui, repo):
- all = LoadAllCL(ui, repo, web=False)
- taken = {}
- for _, cl in all.items():
- for f in cl.files:
- taken[f] = cl
- return taken
-
-# Return list of changed files that are not claimed by other CLs
-def DefaultFiles(ui, repo, pats, opts):
- return ChangedFiles(ui, repo, pats, opts, taken=Taken(ui, repo))
-
-def Sub(l1, l2):
- return [l for l in l1 if l not in l2]
-
-def Add(l1, l2):
- l = l1 + Sub(l2, l1)
- l.sort()
- return l
-
-def Intersect(l1, l2):
- return [l for l in l1 if l in l2]
-
-def getremote(ui, repo, opts):
- # save $http_proxy; creating the HTTP repo object will
- # delete it in an attempt to "help"
- proxy = os.environ.get('http_proxy')
- source = hg.parseurl(ui.expandpath("default"), None)[0]
- try:
- remoteui = hg.remoteui # hg 1.6
- except:
- remoteui = cmdutil.remoteui
- other = hg.repository(remoteui(repo, opts), source)
- if proxy is not None:
- os.environ['http_proxy'] = proxy
- return other
-
-def Incoming(ui, repo, opts):
- _, incoming, _ = findcommonincoming(repo, getremote(ui, repo, opts))
- return incoming
-
desc_re = '^(.+: |(tag )?(release|weekly)\.|fix build|undo CL)'
desc_msg = '''Your CL description appears not to use the standard form.
@@ -833,15 +710,17 @@ Examples:
'''
+def promptyesno(ui, msg):
+ return ui.promptchoice(msg, ["&yes", "&no"], 0) == 0
def promptremove(ui, repo, f):
if promptyesno(ui, "hg remove %s (y/n)?" % (f,)):
- if commands.remove(ui, repo, 'path:'+f) != 0:
+ if hg_commands.remove(ui, repo, 'path:'+f) != 0:
ui.warn("error removing %s" % (f,))
def promptadd(ui, repo, f):
if promptyesno(ui, "hg add %s (y/n)?" % (f,)):
- if commands.add(ui, repo, 'path:'+f) != 0:
+ if hg_commands.add(ui, repo, 'path:'+f) != 0:
ui.warn("error adding %s" % (f,))
def EditCL(ui, repo, cl):
@@ -849,6 +728,18 @@ def EditCL(ui, repo, cl):
s = cl.EditorText()
while True:
s = ui.edit(s, ui.username())
+
+ # We can't trust Mercurial + Python not to die before making the change,
+ # so, by popular demand, just scribble the most recent CL edit into
+ # $(hg root)/last-change so that if Mercurial does die, people
+ # can look there for their work.
+ try:
+ f = open(repo.root+"/last-change", "w")
+ f.write(s)
+ f.close()
+ except:
+ pass
+
clx, line, err = ParseCL(s, cl.name)
if err != '':
if not promptyesno(ui, "error parsing change list: line %d: %s\nre-edit (y/n)?" % (line, err)):
@@ -869,10 +760,14 @@ def EditCL(ui, repo, cl):
# Check file list for files that need to be hg added or hg removed
# or simply aren't understood.
pats = ['path:'+f for f in clx.files]
- modified, added, removed, deleted, unknown, ignored, clean = matchpats(ui, repo, pats, {})
+ changed = hg_matchPattern(ui, repo, *pats, modified=True, added=True, removed=True)
+ deleted = hg_matchPattern(ui, repo, *pats, deleted=True)
+ unknown = hg_matchPattern(ui, repo, *pats, unknown=True)
+ ignored = hg_matchPattern(ui, repo, *pats, ignored=True)
+ clean = hg_matchPattern(ui, repo, *pats, clean=True)
files = []
for f in clx.files:
- if f in modified or f in added or f in removed:
+ if f in changed:
files.append(f)
continue
if f in deleted:
@@ -924,7 +819,7 @@ def CommandLineCL(ui, repo, pats, opts, defaultcc=None):
else:
cl = CL("new")
cl.local = True
- cl.files = ChangedFiles(ui, repo, pats, opts, taken=Taken(ui, repo))
+ cl.files = ChangedFiles(ui, repo, pats, taken=Taken(ui, repo))
if not cl.files:
return None, "no files changed"
if opts.get('reviewer'):
@@ -942,40 +837,56 @@ def CommandLineCL(ui, repo, pats, opts, defaultcc=None):
return None, err
return cl, ""
-# reposetup replaces cmdutil.match with this wrapper,
-# which expands the syntax @clnumber to mean the files
-# in that CL.
-original_match = None
-def ReplacementForCmdutilMatch(repo, pats=None, opts=None, globbed=False, default='relpath'):
- taken = []
- files = []
- pats = pats or []
- opts = opts or {}
+#######################################################################
+# Change list file management
+
+# Return list of changed files in repository that match pats.
+# The patterns came from the command line, so we warn
+# if they have no effect or cannot be understood.
+def ChangedFiles(ui, repo, pats, taken=None):
+ taken = taken or {}
+ # Run each pattern separately so that we can warn about
+ # patterns that didn't do anything useful.
for p in pats:
- if p.startswith('@'):
- taken.append(p)
- clname = p[1:]
- if not GoodCLName(clname):
- raise util.Abort("invalid CL name " + clname)
- cl, err = LoadCL(repo.ui, repo, clname, web=False)
- if err != '':
- raise util.Abort("loading CL " + clname + ": " + err)
- if not cl.files:
- raise util.Abort("no files in CL " + clname)
- files = Add(files, cl.files)
- pats = Sub(pats, taken) + ['path:'+f for f in files]
+ for f in hg_matchPattern(ui, repo, p, unknown=True):
+ promptadd(ui, repo, f)
+ for f in hg_matchPattern(ui, repo, p, removed=True):
+ promptremove(ui, repo, f)
+ files = hg_matchPattern(ui, repo, p, modified=True, added=True, removed=True)
+ for f in files:
+ if f in taken:
+ ui.warn("warning: %s already in CL %s\n" % (f, taken[f].name))
+ if not files:
+ ui.warn("warning: %s did not match any modified files\n" % (p,))
- # work-around for http://selenic.com/hg/rev/785bbc8634f8
- if hgversion >= '1.9' and not hasattr(repo, 'match'):
- repo = repo[None]
+ # Again, all at once (eliminates duplicates)
+ l = hg_matchPattern(ui, repo, *pats, modified=True, added=True, removed=True)
+ l.sort()
+ if taken:
+ l = Sub(l, taken.keys())
+ return l
- return original_match(repo, pats=pats, opts=opts, globbed=globbed, default=default)
+# Return list of changed files in repository that match pats and still exist.
+def ChangedExistingFiles(ui, repo, pats, opts):
+ l = hg_matchPattern(ui, repo, *pats, modified=True, added=True)
+ l.sort()
+ return l
-def RelativePath(path, cwd):
- n = len(cwd)
- if path.startswith(cwd) and path[n] == '/':
- return path[n+1:]
- return path
+# Return list of files claimed by existing CLs
+def Taken(ui, repo):
+ all = LoadAllCL(ui, repo, web=False)
+ taken = {}
+ for _, cl in all.items():
+ for f in cl.files:
+ taken[f] = cl
+ return taken
+
+# Return list of changed files that are not claimed by other CLs
+def DefaultFiles(ui, repo, pats):
+ return ChangedFiles(ui, repo, pats, taken=Taken(ui, repo))
+
+#######################################################################
+# File format checking.
def CheckFormat(ui, repo, files, just_warn=False):
set_status("running gofmt")
@@ -984,7 +895,7 @@ def CheckFormat(ui, repo, files, just_warn=False):
# Check that gofmt run on the list of files does not change them
def CheckGofmt(ui, repo, files, just_warn):
- files = [f for f in files if (f.startswith('src/') or f.startswith('test/bench/')) and f.endswith('.go')]
+ files = gofmt_required(files)
if not files:
return
cwd = os.getcwd()
@@ -996,7 +907,7 @@ def CheckGofmt(ui, repo, files, just_warn):
cmd = subprocess.Popen(["gofmt", "-l"] + files, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=sys.platform != "win32")
cmd.stdin.close()
except:
- raise util.Abort("gofmt: " + ExceptionDetail())
+ raise hg_util.Abort("gofmt: " + ExceptionDetail())
data = cmd.stdout.read()
errors = cmd.stderr.read()
cmd.wait()
@@ -1009,12 +920,12 @@ def CheckGofmt(ui, repo, files, just_warn):
if just_warn:
ui.warn("warning: " + msg + "\n")
else:
- raise util.Abort(msg)
+ raise hg_util.Abort(msg)
return
# Check that *.[chys] files indent using tabs.
def CheckTabfmt(ui, repo, files, just_warn):
- files = [f for f in files if f.startswith('src/') and re.search(r"\.[chys]$", f)]
+ files = [f for f in files if f.startswith('src/') and re.search(r"\.[chys]$", f) and not re.search(r"\.tab\.[ch]$", f)]
if not files:
return
cwd = os.getcwd()
@@ -1038,20 +949,326 @@ def CheckTabfmt(ui, repo, files, just_warn):
if just_warn:
ui.warn("warning: " + msg + "\n")
else:
- raise util.Abort(msg)
+ raise hg_util.Abort(msg)
return
#######################################################################
-# Mercurial commands
+# CONTRIBUTORS file parsing
-# every command must take a ui and and repo as arguments.
-# opts is a dict where you can find other command line flags
-#
-# Other parameters are taken in order from items on the command line that
-# don't start with a dash. If no default value is given in the parameter list,
-# they are required.
-#
+contributorsCache = None
+contributorsURL = None
+
+def ReadContributors(ui, repo):
+ global contributorsCache
+ if contributorsCache is not None:
+ return contributorsCache
+
+ try:
+ if contributorsURL is not None:
+ opening = contributorsURL
+ f = urllib2.urlopen(contributorsURL)
+ else:
+ opening = repo.root + '/CONTRIBUTORS'
+ f = open(repo.root + '/CONTRIBUTORS', 'r')
+ except:
+ ui.write("warning: cannot open %s: %s\n" % (opening, ExceptionDetail()))
+ return
+
+ contributors = {}
+ for line in f:
+ # CONTRIBUTORS is a list of lines like:
+ # Person <email>
+ # Person <email> <alt-email>
+ # The first email address is the one used in commit logs.
+ if line.startswith('#'):
+ continue
+ m = re.match(r"([^<>]+\S)\s+(<[^<>\s]+>)((\s+<[^<>\s]+>)*)\s*$", line)
+ if m:
+ name = m.group(1)
+ email = m.group(2)[1:-1]
+ contributors[email.lower()] = (name, email)
+ for extra in m.group(3).split():
+ contributors[extra[1:-1].lower()] = (name, email)
+
+ contributorsCache = contributors
+ return contributors
+
+def CheckContributor(ui, repo, user=None):
+ set_status("checking CONTRIBUTORS file")
+ user, userline = FindContributor(ui, repo, user, warn=False)
+ if not userline:
+ raise hg_util.Abort("cannot find %s in CONTRIBUTORS" % (user,))
+ return userline
+
+def FindContributor(ui, repo, user=None, warn=True):
+ if not user:
+ user = ui.config("ui", "username")
+ if not user:
+ raise hg_util.Abort("[ui] username is not configured in .hgrc")
+ user = user.lower()
+ m = re.match(r".*<(.*)>", user)
+ if m:
+ user = m.group(1)
+
+ contributors = ReadContributors(ui, repo)
+ if user not in contributors:
+ if warn:
+ ui.warn("warning: cannot find %s in CONTRIBUTORS\n" % (user,))
+ return user, None
+
+ user, email = contributors[user]
+ return email, "%s <%s>" % (user, email)
+
+#######################################################################
+# Mercurial helper functions.
+# Read http://mercurial.selenic.com/wiki/MercurialApi before writing any of these.
+# We use the ui.pushbuffer/ui.popbuffer + hg_commands.xxx tricks for all interaction
+# with Mercurial. It has proved the most stable as they make changes.
+
+hgversion = hg_util.version()
+
+# We require Mercurial 1.9 and suggest Mercurial 2.0.
+# The details of the scmutil package changed then,
+# so allowing earlier versions would require extra band-aids below.
+# Ubuntu 11.10 ships with Mercurial 1.9.1 as the default version.
+hg_required = "1.9"
+hg_suggested = "2.0"
+
+old_message = """
+
+The code review extension requires Mercurial """+hg_required+""" or newer.
+You are using Mercurial """+hgversion+""".
+
+To install a new Mercurial, use
+
+ sudo easy_install mercurial=="""+hg_suggested+"""
+
+or visit http://mercurial.selenic.com/downloads/.
+"""
+
+linux_message = """
+You may need to clear your current Mercurial installation by running:
+
+ sudo apt-get remove mercurial mercurial-common
+ sudo rm -rf /etc/mercurial
+"""
+
+if hgversion < hg_required:
+ msg = old_message
+ if os.access("/etc/mercurial", 0):
+ msg += linux_message
+ raise hg_util.Abort(msg)
+
+from mercurial.hg import clean as hg_clean
+from mercurial import cmdutil as hg_cmdutil
+from mercurial import error as hg_error
+from mercurial import match as hg_match
+from mercurial import node as hg_node
+
+class uiwrap(object):
+ def __init__(self, ui):
+ self.ui = ui
+ ui.pushbuffer()
+ self.oldQuiet = ui.quiet
+ ui.quiet = True
+ self.oldVerbose = ui.verbose
+ ui.verbose = False
+ def output(self):
+ ui = self.ui
+ ui.quiet = self.oldQuiet
+ ui.verbose = self.oldVerbose
+ return ui.popbuffer()
+
+def to_slash(path):
+ if sys.platform == "win32":
+ return path.replace('\\', '/')
+ return path
+
+def hg_matchPattern(ui, repo, *pats, **opts):
+ w = uiwrap(ui)
+ hg_commands.status(ui, repo, *pats, **opts)
+ text = w.output()
+ ret = []
+ prefix = to_slash(os.path.realpath(repo.root))+'/'
+ for line in text.split('\n'):
+ f = line.split()
+ if len(f) > 1:
+ if len(pats) > 0:
+ # Given patterns, Mercurial shows relative to cwd
+ p = to_slash(os.path.realpath(f[1]))
+ if not p.startswith(prefix):
+ print >>sys.stderr, "File %s not in repo root %s.\n" % (p, prefix)
+ else:
+ ret.append(p[len(prefix):])
+ else:
+ # Without patterns, Mercurial shows relative to root (what we want)
+ ret.append(to_slash(f[1]))
+ return ret
+
+def hg_heads(ui, repo):
+ w = uiwrap(ui)
+ hg_commands.heads(ui, repo)
+ return w.output()
+
+noise = [
+ "",
+ "resolving manifests",
+ "searching for changes",
+ "couldn't find merge tool hgmerge",
+ "adding changesets",
+ "adding manifests",
+ "adding file changes",
+ "all local heads known remotely",
+]
+
+def isNoise(line):
+ line = str(line)
+ for x in noise:
+ if line == x:
+ return True
+ return False
+
+def hg_incoming(ui, repo):
+ w = uiwrap(ui)
+ ret = hg_commands.incoming(ui, repo, force=False, bundle="")
+ if ret and ret != 1:
+ raise hg_util.Abort(ret)
+ return w.output()
+
+def hg_log(ui, repo, **opts):
+ for k in ['date', 'keyword', 'rev', 'user']:
+ if not opts.has_key(k):
+ opts[k] = ""
+ w = uiwrap(ui)
+ ret = hg_commands.log(ui, repo, **opts)
+ if ret:
+ raise hg_util.Abort(ret)
+ return w.output()
+
+def hg_outgoing(ui, repo, **opts):
+ w = uiwrap(ui)
+ ret = hg_commands.outgoing(ui, repo, **opts)
+ if ret and ret != 1:
+ raise hg_util.Abort(ret)
+ return w.output()
+
+def hg_pull(ui, repo, **opts):
+ w = uiwrap(ui)
+ ui.quiet = False
+ ui.verbose = True # for file list
+ err = hg_commands.pull(ui, repo, **opts)
+ for line in w.output().split('\n'):
+ if isNoise(line):
+ continue
+ if line.startswith('moving '):
+ line = 'mv ' + line[len('moving '):]
+ if line.startswith('getting ') and line.find(' to ') >= 0:
+ line = 'mv ' + line[len('getting '):]
+ if line.startswith('getting '):
+ line = '+ ' + line[len('getting '):]
+ if line.startswith('removing '):
+ line = '- ' + line[len('removing '):]
+ ui.write(line + '\n')
+ return err
+
+def hg_push(ui, repo, **opts):
+ w = uiwrap(ui)
+ ui.quiet = False
+ ui.verbose = True
+ err = hg_commands.push(ui, repo, **opts)
+ for line in w.output().split('\n'):
+ if not isNoise(line):
+ ui.write(line + '\n')
+ return err
+
+def hg_commit(ui, repo, *pats, **opts):
+ return hg_commands.commit(ui, repo, *pats, **opts)
+
+#######################################################################
+# Mercurial precommit hook to disable commit except through this interface.
+
+commit_okay = False
+
+def precommithook(ui, repo, **opts):
+ if commit_okay:
+ return False # False means okay.
+ ui.write("\ncodereview extension enabled; use mail, upload, or submit instead of commit\n\n")
+ return True
+
+#######################################################################
+# @clnumber file pattern support
+
+# We replace scmutil.match with the MatchAt wrapper to add the @clnumber pattern.
+
+match_repo = None
+match_ui = None
+match_orig = None
+
+def InstallMatch(ui, repo):
+ global match_repo
+ global match_ui
+ global match_orig
+
+ match_ui = ui
+ match_repo = repo
+
+ from mercurial import scmutil
+ match_orig = scmutil.match
+ scmutil.match = MatchAt
+
+def MatchAt(ctx, pats=None, opts=None, globbed=False, default='relpath'):
+ taken = []
+ files = []
+ pats = pats or []
+ opts = opts or {}
+
+ for p in pats:
+ if p.startswith('@'):
+ taken.append(p)
+ clname = p[1:]
+ if clname == "default":
+ files = DefaultFiles(match_ui, match_repo, [])
+ else:
+ if not GoodCLName(clname):
+ raise hg_util.Abort("invalid CL name " + clname)
+ cl, err = LoadCL(match_repo.ui, match_repo, clname, web=False)
+ if err != '':
+ raise hg_util.Abort("loading CL " + clname + ": " + err)
+ if not cl.files:
+ raise hg_util.Abort("no files in CL " + clname)
+ files = Add(files, cl.files)
+ pats = Sub(pats, taken) + ['path:'+f for f in files]
+
+ # work-around for http://selenic.com/hg/rev/785bbc8634f8
+ if not hasattr(ctx, 'match'):
+ ctx = ctx[None]
+ return match_orig(ctx, pats=pats, opts=opts, globbed=globbed, default=default)
+
+#######################################################################
+# Commands added by code review extension.
+
+# As of Mercurial 2.1 the commands are all required to return integer
+# exit codes, whereas earlier versions allowed returning arbitrary strings
+# to be printed as errors. We wrap the old functions to make sure we
+# always return integer exit codes now. Otherwise Mercurial dies
+# with a TypeError traceback (unsupported operand type(s) for &: 'str' and 'int').
+# Introduce a Python decorator to convert old functions to the new
+# stricter convention.
+
+def hgcommand(f):
+ def wrapped(ui, repo, *pats, **opts):
+ err = f(ui, repo, *pats, **opts)
+ if type(err) is int:
+ return err
+ if not err:
+ return 0
+ raise hg_util.Abort(err)
+ return wrapped
+#######################################################################
+# hg change
+
+@hgcommand
def change(ui, repo, *pats, **opts):
"""create, edit or delete a change list
@@ -1074,8 +1291,8 @@ def change(ui, repo, *pats, **opts):
before running hg change -d 123456.
"""
- if missing_codereview:
- return missing_codereview
+ if codereview_disabled:
+ return codereview_disabled
dirty = {}
if len(pats) > 0 and GoodCLName(pats[0]):
@@ -1089,12 +1306,12 @@ def change(ui, repo, *pats, **opts):
if not cl.local and (opts["stdin"] or not opts["stdout"]):
return "cannot change non-local CL " + name
else:
- if repo[None].branch() != "default":
- return "cannot run hg change outside default branch"
name = "new"
cl = CL("new")
+ if repo[None].branch() != "default":
+ return "cannot create CL outside default branch"
dirty[cl] = True
- files = ChangedFiles(ui, repo, pats, opts, taken=Taken(ui, repo))
+ files = ChangedFiles(ui, repo, pats, taken=Taken(ui, repo))
if opts["delete"] or opts["deletelocal"]:
if opts["delete"] and opts["deletelocal"]:
@@ -1162,17 +1379,26 @@ def change(ui, repo, *pats, **opts):
ui.write("CL created: " + cl.url + "\n")
return
+#######################################################################
+# hg code-login (broken?)
+
+@hgcommand
def code_login(ui, repo, **opts):
"""log in to code review server
Logs in to the code review server, saving a cookie in
a file in your home directory.
"""
- if missing_codereview:
- return missing_codereview
+ if codereview_disabled:
+ return codereview_disabled
MySend(None)
+#######################################################################
+# hg clpatch / undo / release-apply / download
+# All concerned with applying or unapplying patches to the repository.
+
+@hgcommand
def clpatch(ui, repo, clname, **opts):
"""import a patch from the code review server
@@ -1187,6 +1413,7 @@ def clpatch(ui, repo, clname, **opts):
return "cannot run hg clpatch outside default branch"
return clpatch_or_undo(ui, repo, clname, opts, mode="clpatch")
+@hgcommand
def undo(ui, repo, clname, **opts):
"""undo the effect of a CL
@@ -1198,6 +1425,7 @@ def undo(ui, repo, clname, **opts):
return "cannot run hg undo outside default branch"
return clpatch_or_undo(ui, repo, clname, opts, mode="undo")
+@hgcommand
def release_apply(ui, repo, clname, **opts):
"""apply a CL to the release branch
@@ -1242,16 +1470,16 @@ def release_apply(ui, repo, clname, **opts):
return "no active release branches"
if c.branch() != releaseBranch:
if c.modified() or c.added() or c.removed():
- raise util.Abort("uncommitted local changes - cannot switch branches")
- err = hg.clean(repo, releaseBranch)
+ raise hg_util.Abort("uncommitted local changes - cannot switch branches")
+ err = hg_clean(repo, releaseBranch)
if err:
return err
try:
err = clpatch_or_undo(ui, repo, clname, opts, mode="backport")
if err:
- raise util.Abort(err)
+ raise hg_util.Abort(err)
except Exception, e:
- hg.clean(repo, "default")
+ hg_clean(repo, "default")
raise e
return None
@@ -1286,14 +1514,10 @@ backportFooter = """
# Implementation of clpatch/undo.
def clpatch_or_undo(ui, repo, clname, opts, mode):
- if missing_codereview:
- return missing_codereview
+ if codereview_disabled:
+ return codereview_disabled
if mode == "undo" or mode == "backport":
- if hgversion < '1.4':
- # Don't have cmdutil.match (see implementation of sync command).
- return "hg is too old to run hg %s - update to 1.4 or newer" % mode
-
# Find revision in Mercurial repository.
# Assume CL number is 7+ decimal digits.
# Otherwise is either change log sequence number (fewer decimal digits),
@@ -1302,11 +1526,8 @@ def clpatch_or_undo(ui, repo, clname, opts, mode):
# sequence numbers get to be 7 digits long.
if re.match('^[0-9]{7,}$', clname):
found = False
- matchfn = scmutil.match(repo, [], {'rev': None})
- def prep(ctx, fns):
- pass
- for ctx in cmdutil.walkchangerevs(repo, matchfn, {'rev': None}, prep):
- rev = repo[ctx.rev()]
+ for r in hg_log(ui, repo, keyword="codereview.appspot.com/"+clname, limit=100, template="{node}\n").split():
+ rev = repo[r]
# Last line with a code review URL is the actual review URL.
# Earlier ones might be part of the CL description.
n = rev2clname(rev)
@@ -1324,7 +1545,7 @@ def clpatch_or_undo(ui, repo, clname, opts, mode):
return "cannot find CL name in revision description"
# Create fresh CL and start with patch that would reverse the change.
- vers = short(rev.node())
+ vers = hg_node.short(rev.node())
cl = CL("new")
desc = str(rev.description())
if mode == "undo":
@@ -1332,7 +1553,7 @@ def clpatch_or_undo(ui, repo, clname, opts, mode):
else:
cl.desc = (backportHeader % (releaseBranch, line1(desc), clname, vers)) + desc + undoFooter
v1 = vers
- v0 = short(rev.parents()[0].node())
+ v0 = hg_node.short(rev.parents()[0].node())
if mode == "undo":
arg = v1 + ":" + v0
else:
@@ -1350,7 +1571,7 @@ def clpatch_or_undo(ui, repo, clname, opts, mode):
# find current hg version (hg identify)
ctx = repo[None]
parents = ctx.parents()
- id = '+'.join([short(p.node()) for p in parents])
+ id = '+'.join([hg_node.short(p.node()) for p in parents])
# if version does not match the patch version,
# try to update the patch line numbers.
@@ -1374,7 +1595,7 @@ def clpatch_or_undo(ui, repo, clname, opts, mode):
try:
cmd = subprocess.Popen(argv, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=None, close_fds=sys.platform != "win32")
except:
- return "hgpatch: " + ExceptionDetail()
+ return "hgpatch: " + ExceptionDetail() + "\nInstall hgpatch with:\n$ go get code.google.com/p/go.codereview/cmd/hgpatch\n"
out, err = cmd.communicate(patch)
if cmd.returncode != 0 and not opts["ignore_hgpatch_failure"]:
@@ -1383,7 +1604,7 @@ def clpatch_or_undo(ui, repo, clname, opts, mode):
cl.files = out.strip().split()
if not cl.files and not opts["ignore_hgpatch_failure"]:
return "codereview issue %s has no changed files" % clname
- files = ChangedFiles(ui, repo, [], opts)
+ files = ChangedFiles(ui, repo, [])
extra = Sub(cl.files, files)
if extra:
ui.warn("warning: these files were listed in the patch but not changed:\n\t" + "\n\t".join(extra) + "\n")
@@ -1457,14 +1678,15 @@ def lineDelta(deltas, n, len):
d = newdelta
return d, ""
+@hgcommand
def download(ui, repo, clname, **opts):
"""download a change from the code review server
Download prints a description of the given change list
followed by its diff, downloaded from the code review server.
"""
- if missing_codereview:
- return missing_codereview
+ if codereview_disabled:
+ return codereview_disabled
cl, vers, patch, err = DownloadCL(ui, repo, clname)
if err != "":
@@ -1473,6 +1695,10 @@ def download(ui, repo, clname, **opts):
ui.write(patch + "\n")
return
+#######################################################################
+# hg file
+
+@hgcommand
def file(ui, repo, clname, pat, *pats, **opts):
"""assign files to or remove files from a change list
@@ -1481,8 +1707,8 @@ def file(ui, repo, clname, pat, *pats, **opts):
The -d option only removes files from the change list.
It does not edit them or remove them from the repository.
"""
- if missing_codereview:
- return missing_codereview
+ if codereview_disabled:
+ return codereview_disabled
pats = tuple([pat] + list(pats))
if not GoodCLName(clname):
@@ -1495,7 +1721,7 @@ def file(ui, repo, clname, pat, *pats, **opts):
if not cl.local:
return "cannot change non-local CL " + clname
- files = ChangedFiles(ui, repo, pats, opts)
+ files = ChangedFiles(ui, repo, pats)
if opts["delete"]:
oldfiles = Intersect(files, cl.files)
@@ -1535,17 +1761,21 @@ def file(ui, repo, clname, pat, *pats, **opts):
d.Flush(ui, repo)
return
+#######################################################################
+# hg gofmt
+
+@hgcommand
def gofmt(ui, repo, *pats, **opts):
"""apply gofmt to modified files
Applies gofmt to the modified files in the repository that match
the given patterns.
"""
- if missing_codereview:
- return missing_codereview
+ if codereview_disabled:
+ return codereview_disabled
files = ChangedExistingFiles(ui, repo, pats, opts)
- files = [f for f in files if f.endswith(".go")]
+ files = gofmt_required(files)
if not files:
return "no modified go files"
cwd = os.getcwd()
@@ -1555,21 +1785,28 @@ def gofmt(ui, repo, *pats, **opts):
if not opts["list"]:
cmd += ["-w"]
if os.spawnvp(os.P_WAIT, "gofmt", cmd + files) != 0:
- raise util.Abort("gofmt did not exit cleanly")
- except error.Abort, e:
+ raise hg_util.Abort("gofmt did not exit cleanly")
+ except hg_error.Abort, e:
raise
except:
- raise util.Abort("gofmt: " + ExceptionDetail())
+ raise hg_util.Abort("gofmt: " + ExceptionDetail())
return
+def gofmt_required(files):
+ return [f for f in files if (not f.startswith('test/') or f.startswith('test/bench/')) and f.endswith('.go')]
+
+#######################################################################
+# hg mail
+
+@hgcommand
def mail(ui, repo, *pats, **opts):
"""mail a change for review
Uploads a patch to the code review server and then sends mail
to the reviewer and CC list asking for a review.
"""
- if missing_codereview:
- return missing_codereview
+ if codereview_disabled:
+ return codereview_disabled
cl, err = CommandLineCL(ui, repo, pats, opts, defaultcc=defaultcc)
if err != "":
@@ -1591,76 +1828,74 @@ def mail(ui, repo, *pats, **opts):
cl.Mail(ui, repo)
+#######################################################################
+# hg p / hg pq / hg ps / hg pending
+
+@hgcommand
+def ps(ui, repo, *pats, **opts):
+ """alias for hg p --short
+ """
+ opts['short'] = True
+ return pending(ui, repo, *pats, **opts)
+
+@hgcommand
+def pq(ui, repo, *pats, **opts):
+ """alias for hg p --quick
+ """
+ opts['quick'] = True
+ return pending(ui, repo, *pats, **opts)
+
+@hgcommand
def pending(ui, repo, *pats, **opts):
"""show pending changes
Lists pending changes followed by a list of unassigned but modified files.
"""
- if missing_codereview:
- return missing_codereview
+ if codereview_disabled:
+ return codereview_disabled
- m = LoadAllCL(ui, repo, web=True)
+ quick = opts.get('quick', False)
+ short = opts.get('short', False)
+ m = LoadAllCL(ui, repo, web=not quick and not short)
names = m.keys()
names.sort()
for name in names:
cl = m[name]
- ui.write(cl.PendingText() + "\n")
+ if short:
+ ui.write(name + "\t" + line1(cl.desc) + "\n")
+ else:
+ ui.write(cl.PendingText(quick=quick) + "\n")
- files = DefaultFiles(ui, repo, [], opts)
+ if short:
+ return
+ files = DefaultFiles(ui, repo, [])
if len(files) > 0:
s = "Changed files not in any CL:\n"
for f in files:
s += "\t" + f + "\n"
ui.write(s)
-def reposetup(ui, repo):
- global original_match
- if original_match is None:
- start_status_thread()
- original_match = scmutil.match
- scmutil.match = ReplacementForCmdutilMatch
- RietveldSetup(ui, repo)
-
-def CheckContributor(ui, repo, user=None):
- set_status("checking CONTRIBUTORS file")
- user, userline = FindContributor(ui, repo, user, warn=False)
- if not userline:
- raise util.Abort("cannot find %s in CONTRIBUTORS" % (user,))
- return userline
-
-def FindContributor(ui, repo, user=None, warn=True):
- if not user:
- user = ui.config("ui", "username")
- if not user:
- raise util.Abort("[ui] username is not configured in .hgrc")
- user = user.lower()
- m = re.match(r".*<(.*)>", user)
- if m:
- user = m.group(1)
+#######################################################################
+# hg submit
- if user not in contributors:
- if warn:
- ui.warn("warning: cannot find %s in CONTRIBUTORS\n" % (user,))
- return user, None
-
- user, email = contributors[user]
- return email, "%s <%s>" % (user, email)
+def need_sync():
+ raise hg_util.Abort("local repository out of date; must sync before submit")
+@hgcommand
def submit(ui, repo, *pats, **opts):
"""submit change to remote repository
Submits change to remote repository.
Bails out if the local repository is not in sync with the remote one.
"""
- if missing_codereview:
- return missing_codereview
+ if codereview_disabled:
+ return codereview_disabled
# We already called this on startup but sometimes Mercurial forgets.
set_mercurial_encoding_to_utf8()
- repo.ui.quiet = True
- if not opts["no_incoming"] and Incoming(ui, repo, opts):
- return "local repository out of date; must sync before submit"
+ if not opts["no_incoming"] and hg_incoming(ui, repo):
+ need_sync()
cl, err = CommandLineCL(ui, repo, pats, opts, defaultcc=defaultcc)
if err != "":
@@ -1706,60 +1941,59 @@ def submit(ui, repo, *pats, **opts):
cl.Mail(ui, repo)
# submit changes locally
- date = opts.get('date')
- if date:
- opts['date'] = util.parsedate(date)
- typecheck(opts['date'], str)
- opts['message'] = cl.desc.rstrip() + "\n\n" + about
- typecheck(opts['message'], str)
-
- if opts['dryrun']:
- print "NOT SUBMITTING:"
- print "User: ", userline
- print "Message:"
- print Indent(opts['message'], "\t")
- print "Files:"
- print Indent('\n'.join(cl.files), "\t")
- return "dry run; not submitted"
+ message = cl.desc.rstrip() + "\n\n" + about
+ typecheck(message, str)
set_status("pushing " + cl.name + " to remote server")
- m = match.exact(repo.root, repo.getcwd(), cl.files)
- node = repo.commit(ustr(opts['message']), ustr(userline), opts.get('date'), m)
- if not node:
- return "nothing changed"
+ if hg_outgoing(ui, repo):
+ raise hg_util.Abort("local repository corrupt or out-of-phase with remote: found outgoing changes")
+
+ old_heads = len(hg_heads(ui, repo).split())
+
+ global commit_okay
+ commit_okay = True
+ ret = hg_commit(ui, repo, *['path:'+f for f in cl.files], message=message, user=userline)
+ commit_okay = False
+ if ret:
+ return "nothing changed"
+ node = repo["-1"].node()
# push to remote; if it fails for any reason, roll back
try:
- log = repo.changelog
- rev = log.rev(node)
- parents = log.parentrevs(rev)
- if (rev-1 not in parents and
- (parents == (nullrev, nullrev) or
- len(log.heads(log.node(parents[0]))) > 1 and
- (parents[1] == nullrev or len(log.heads(log.node(parents[1]))) > 1))):
- # created new head
- raise util.Abort("local repository out of date; must sync before submit")
-
- # push changes to remote.
- # if it works, we're committed.
- # if not, roll back
- other = getremote(ui, repo, opts)
- r = repo.push(other, False, None)
- if r == 0:
- raise util.Abort("local repository out of date; must sync before submit")
+ new_heads = len(hg_heads(ui, repo).split())
+ if old_heads != new_heads and not (old_heads == 0 and new_heads == 1):
+ # Created new head, so we weren't up to date.
+ need_sync()
+
+ # Push changes to remote. If it works, we're committed. If not, roll back.
+ try:
+ hg_push(ui, repo)
+ except hg_error.Abort, e:
+ if e.message.find("push creates new heads") >= 0:
+ # Remote repository had changes we missed.
+ need_sync()
+ raise
except:
real_rollback()
raise
- # we're committed. upload final patch, close review, add commit message
- changeURL = short(node)
- url = other.url()
- m = re.match("^https?://([^@/]+@)?([^.]+)\.googlecode\.com/hg/?", url)
+ # We're committed. Upload final patch, close review, add commit message.
+ changeURL = hg_node.short(node)
+ url = ui.expandpath("default")
+ m = re.match("(^https?://([^@/]+@)?([^.]+)\.googlecode\.com/hg/?)" + "|" +
+ "(^https?://([^@/]+@)?code\.google\.com/p/([^/.]+)(\.[^./]+)?/?)", url)
if m:
- changeURL = "http://code.google.com/p/%s/source/detail?r=%s" % (m.group(2), changeURL)
+ if m.group(1): # prj.googlecode.com/hg/ case
+ changeURL = "http://code.google.com/p/%s/source/detail?r=%s" % (m.group(3), changeURL)
+ elif m.group(4) and m.group(7): # code.google.com/p/prj.subrepo/ case
+ changeURL = "http://code.google.com/p/%s/source/detail?r=%s&repo=%s" % (m.group(6), changeURL, m.group(7)[1:])
+ elif m.group(4): # code.google.com/p/prj/ case
+ changeURL = "http://code.google.com/p/%s/source/detail?r=%s" % (m.group(6), changeURL)
+ else:
+ print >>sys.stderr, "URL: ", url
else:
print >>sys.stderr, "URL: ", url
- pmsg = "*** Submitted as " + changeURL + " ***\n\n" + opts['message']
+ pmsg = "*** Submitted as " + changeURL + " ***\n\n" + message
# When posting, move reviewers to CC line,
# so that the issue stops showing up in their "My Issues" page.
@@ -1768,53 +2002,39 @@ def submit(ui, repo, *pats, **opts):
if not cl.copied_from:
EditDesc(cl.name, closed=True, private=cl.private)
cl.Delete(ui, repo)
-
+
c = repo[None]
if c.branch() == releaseBranch and not c.modified() and not c.added() and not c.removed():
ui.write("switching from %s to default branch.\n" % releaseBranch)
- err = hg.clean(repo, "default")
+ err = hg_clean(repo, "default")
if err:
return err
return None
+#######################################################################
+# hg sync
+
+@hgcommand
def sync(ui, repo, **opts):
"""synchronize with remote repository
Incorporates recent changes from the remote repository
into the local repository.
"""
- if missing_codereview:
- return missing_codereview
+ if codereview_disabled:
+ return codereview_disabled
if not opts["local"]:
- ui.status = sync_note
- ui.note = sync_note
- other = getremote(ui, repo, opts)
- modheads = repo.pull(other)
- err = commands.postincoming(ui, repo, modheads, True, "tip")
+ err = hg_pull(ui, repo, update=True)
if err:
return err
- commands.update(ui, repo, rev="default")
sync_changes(ui, repo)
-def sync_note(msg):
- # we run sync (pull -u) in verbose mode to get the
- # list of files being updated, but that drags along
- # a bunch of messages we don't care about.
- # omit them.
- if msg == 'resolving manifests\n':
- return
- if msg == 'searching for changes\n':
- return
- if msg == "couldn't find merge tool hgmerge\n":
- return
- sys.stdout.write(msg)
-
def sync_changes(ui, repo):
# Look through recent change log descriptions to find
# potential references to http://.*/our-CL-number.
# Double-check them by looking at the Rietveld log.
- def Rev(rev):
+ for rev in hg_log(ui, repo, limit=100, template="{node}\n").split():
desc = repo[rev].description().strip()
for clname in re.findall('(?m)^http://(?:[^\n]+)/([0-9]+)$', desc):
if IsLocalCL(ui, repo, clname) and IsRietveldSubmitted(ui, clname, repo[rev].hex()):
@@ -1827,28 +2047,10 @@ def sync_changes(ui, repo):
EditDesc(cl.name, closed=True, private=cl.private)
cl.Delete(ui, repo)
- if hgversion < '1.4':
- get = util.cachefunc(lambda r: repo[r].changeset())
- changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, [], get, {'rev': None})
- n = 0
- for st, rev, fns in changeiter:
- if st != 'iter':
- continue
- n += 1
- if n > 100:
- break
- Rev(rev)
- else:
- matchfn = scmutil.match(repo, [], {'rev': None})
- def prep(ctx, fns):
- pass
- for ctx in cmdutil.walkchangerevs(repo, matchfn, {'rev': None}, prep):
- Rev(ctx.rev())
-
# Remove files that are not modified from the CLs in which they appear.
all = LoadAllCL(ui, repo, web=False)
- changed = ChangedFiles(ui, repo, [], {})
- for _, cl in all.items():
+ changed = ChangedFiles(ui, repo, [])
+ for cl in all.values():
extra = Sub(cl.files, changed)
if extra:
ui.warn("Removing unmodified files from CL %s:\n" % (cl.name,))
@@ -1863,13 +2065,17 @@ def sync_changes(ui, repo):
ui.warn("CL %s has no files; delete locally with hg change -D %s\n" % (cl.name, cl.name))
return
+#######################################################################
+# hg upload
+
+@hgcommand
def upload(ui, repo, name, **opts):
"""upload diffs to the code review server
Uploads the current modifications for a given change to the server.
"""
- if missing_codereview:
- return missing_codereview
+ if codereview_disabled:
+ return codereview_disabled
repo.ui.quiet = True
cl, err = LoadCL(ui, repo, name, web=True)
@@ -1881,6 +2087,9 @@ def upload(ui, repo, name, **opts):
print "%s%s\n" % (server_url_base, cl.name)
return
+#######################################################################
+# Table of commands, supplied to Mercurial for installation.
+
review_opts = [
('r', 'reviewer', '', 'add reviewer'),
('', 'cc', '', 'add cc'),
@@ -1939,13 +2148,26 @@ cmdtable = {
),
"^pending|p": (
pending,
+ [
+ ('s', 'short', False, 'show short result form'),
+ ('', 'quick', False, 'do not consult codereview server'),
+ ],
+ "[FILE ...]"
+ ),
+ "^ps": (
+ ps,
+ [],
+ "[FILE ...]"
+ ),
+ "^pq": (
+ pq,
[],
"[FILE ...]"
),
"^mail": (
mail,
review_opts + [
- ] + commands.walkopts,
+ ] + hg_commands.walkopts,
"[-r reviewer] [--cc cc] [change# | file ...]"
),
"^release-apply": (
@@ -1961,8 +2183,7 @@ cmdtable = {
submit,
review_opts + [
('', 'no_incoming', None, 'disable initial incoming check (for testing)'),
- ('n', 'dryrun', None, 'make change only locally (for testing)'),
- ] + commands.walkopts + commands.commitopts + commands.commitopts2,
+ ] + hg_commands.walkopts + hg_commands.commitopts + hg_commands.commitopts2,
"[-r reviewer] [--cc cc] [change# | file ...]"
),
"^sync": (
@@ -1987,10 +2208,77 @@ cmdtable = {
),
}
+#######################################################################
+# Mercurial extension initialization
+
+def norollback(*pats, **opts):
+ """(disabled when using this extension)"""
+ raise hg_util.Abort("codereview extension enabled; use undo instead of rollback")
+
+codereview_init = False
+
+def reposetup(ui, repo):
+ global codereview_disabled
+ global defaultcc
+
+ # reposetup gets called both for the local repository
+ # and also for any repository we are pulling or pushing to.
+ # Only initialize the first time.
+ global codereview_init
+ if codereview_init:
+ return
+ codereview_init = True
+
+ # Read repository-specific options from lib/codereview/codereview.cfg or codereview.cfg.
+ root = ''
+ try:
+ root = repo.root
+ except:
+ # Yes, repo might not have root; see issue 959.
+ codereview_disabled = 'codereview disabled: repository has no root'
+ return
+
+ repo_config_path = ''
+ p1 = root + '/lib/codereview/codereview.cfg'
+ p2 = root + '/codereview.cfg'
+ if os.access(p1, os.F_OK):
+ repo_config_path = p1
+ else:
+ repo_config_path = p2
+ try:
+ f = open(repo_config_path)
+ for line in f:
+ if line.startswith('defaultcc:'):
+ defaultcc = SplitCommaSpace(line[len('defaultcc:'):])
+ if line.startswith('contributors:'):
+ global contributorsURL
+ contributorsURL = line[len('contributors:'):].strip()
+ except:
+ codereview_disabled = 'codereview disabled: cannot open ' + repo_config_path
+ return
+
+ remote = ui.config("paths", "default", "")
+ if remote.find("://") < 0:
+ raise hg_util.Abort("codereview: default path '%s' is not a URL" % (remote,))
+
+ InstallMatch(ui, repo)
+ RietveldSetup(ui, repo)
+
+ # Disable the Mercurial commands that might change the repository.
+ # Only commands in this extension are supposed to do that.
+ ui.setconfig("hooks", "precommit.codereview", precommithook)
+
+ # Rollback removes an existing commit. Don't do that either.
+ global real_rollback
+ real_rollback = repo.rollback
+ repo.rollback = norollback
+
#######################################################################
# Wrappers around upload.py for interacting with Rietveld
+from HTMLParser import HTMLParser
+
# HTML form parser
class FormParser(HTMLParser):
def __init__(self):
@@ -2066,7 +2354,7 @@ def fix_json(x):
for k in todel:
del x[k]
else:
- raise util.Abort("unknown type " + str(type(x)) + " in fix_json")
+ raise hg_util.Abort("unknown type " + str(type(x)) + " in fix_json")
if type(x) is str:
x = x.replace('\r\n', '\n')
return x
@@ -2269,68 +2557,13 @@ def PostMessage(ui, issue, message, reviewers=None, cc=None, send_mail=True, sub
class opt(object):
pass
-def nocommit(*pats, **opts):
- """(disabled when using this extension)"""
- raise util.Abort("codereview extension enabled; use mail, upload, or submit instead of commit")
-
-def nobackout(*pats, **opts):
- """(disabled when using this extension)"""
- raise util.Abort("codereview extension enabled; use undo instead of backout")
-
-def norollback(*pats, **opts):
- """(disabled when using this extension)"""
- raise util.Abort("codereview extension enabled; use undo instead of rollback")
-
def RietveldSetup(ui, repo):
- global defaultcc, upload_options, rpc, server, server_url_base, force_google_account, verbosity, contributors
- global missing_codereview
-
- repo_config_path = ''
- # Read repository-specific options from lib/codereview/codereview.cfg
- try:
- repo_config_path = repo.root + '/lib/codereview/codereview.cfg'
- f = open(repo_config_path)
- for line in f:
- if line.startswith('defaultcc: '):
- defaultcc = SplitCommaSpace(line[10:])
- except:
- # If there are no options, chances are good this is not
- # a code review repository; stop now before we foul
- # things up even worse. Might also be that repo doesn't
- # even have a root. See issue 959.
- if repo_config_path == '':
- missing_codereview = 'codereview disabled: repository has no root'
- else:
- missing_codereview = 'codereview disabled: cannot open ' + repo_config_path
- return
-
- # Should only modify repository with hg submit.
- # Disable the built-in Mercurial commands that might
- # trip things up.
- cmdutil.commit = nocommit
- global real_rollback
- real_rollback = repo.rollback
- repo.rollback = norollback
- # would install nobackout if we could; oh well
-
- try:
- f = open(repo.root + '/CONTRIBUTORS', 'r')
- except:
- raise util.Abort("cannot open %s: %s" % (repo.root+'/CONTRIBUTORS', ExceptionDetail()))
- for line in f:
- # CONTRIBUTORS is a list of lines like:
- # Person <email>
- # Person <email> <alt-email>
- # The first email address is the one used in commit logs.
- if line.startswith('#'):
- continue
- m = re.match(r"([^<>]+\S)\s+(<[^<>\s]+>)((\s+<[^<>\s]+>)*)\s*$", line)
- if m:
- name = m.group(1)
- email = m.group(2)[1:-1]
- contributors[email.lower()] = (name, email)
- for extra in m.group(3).split():
- contributors[extra[1:-1].lower()] = (name, email)
+ global force_google_account
+ global rpc
+ global server
+ global server_url_base
+ global upload_options
+ global verbosity
if not ui.verbose:
verbosity = 0
@@ -2381,7 +2614,7 @@ def RietveldSetup(ui, repo):
# answer when comparing release-branch.r99 with
# release-branch.r100. If we do ten releases a year
# that gives us 4 years before we have to worry about this.
- raise util.Abort('tags.sort needs to be fixed for release-branch.r100')
+ raise hg_util.Abort('tags.sort needs to be fixed for release-branch.r100')
tags.sort()
for t in tags:
if t.startswith('release-branch.'):
@@ -2990,7 +3223,7 @@ class VersionControlSystem(object):
unused, filename = line.split(':', 1)
# On Windows if a file has property changes its filename uses '\'
# instead of '/'.
- filename = filename.strip().replace('\\', '/')
+ filename = to_slash(filename.strip())
files[filename] = self.GetBaseFile(filename)
return files
@@ -3098,6 +3331,7 @@ class VersionControlSystem(object):
return False
return not mimetype.startswith("text/")
+
class FakeMercurialUI(object):
def __init__(self):
self.quiet = True
@@ -3105,6 +3339,19 @@ class FakeMercurialUI(object):
def write(self, *args, **opts):
self.output += ' '.join(args)
+ def copy(self):
+ return self
+ def status(self, *args, **opts):
+ pass
+
+ def readconfig(self, *args, **opts):
+ pass
+ def expandpath(self, *args, **opts):
+ return global_ui.expandpath(*args, **opts)
+ def configitems(self, *args, **opts):
+ return global_ui.configitems(*args, **opts)
+ def config(self, *args, **opts):
+ return global_ui.config(*args, **opts)
use_hg_shell = False # set to True to shell out to hg always; slower
@@ -3115,6 +3362,7 @@ class MercurialVCS(VersionControlSystem):
super(MercurialVCS, self).__init__(options)
self.ui = ui
self.repo = repo
+ self.status = None
# Absolute path to repository (we can be in a subdir)
self.repo_dir = os.path.normpath(repo.root)
# Compute the subdir
@@ -3128,7 +3376,11 @@ class MercurialVCS(VersionControlSystem):
if not err and mqparent != "":
self.base_rev = mqparent
else:
- self.base_rev = RunShell(["hg", "parents", "-q"]).split(':')[1].strip()
+ out = RunShell(["hg", "parents", "-q"], silent_ok=True).strip()
+ if not out:
+ # No revisions; use 0 to mean a repository with nothing.
+ out = "0:0"
+ self.base_rev = out.split(':')[1].strip()
def _GetRelPath(self, filename):
"""Get relative path of a file according to the current directory,
given its logical path in the repo."""
@@ -3173,6 +3425,33 @@ class MercurialVCS(VersionControlSystem):
unknown_files.append(fn)
return unknown_files
+ def get_hg_status(self, rev, path):
+ # We'd like to use 'hg status -C path', but that is buggy
+ # (see http://mercurial.selenic.com/bts/issue3023).
+ # Instead, run 'hg status -C' without a path
+ # and skim the output for the path we want.
+ if self.status is None:
+ if use_hg_shell:
+ out = RunShell(["hg", "status", "-C", "--rev", rev])
+ else:
+ fui = FakeMercurialUI()
+ ret = hg_commands.status(fui, self.repo, *[], **{'rev': [rev], 'copies': True})
+ if ret:
+ raise hg_util.Abort(ret)
+ out = fui.output
+ self.status = out.splitlines()
+ for i in range(len(self.status)):
+ # line is
+ # A path
+ # M path
+ # etc
+ line = to_slash(self.status[i])
+ if line[2:] == path:
+ if i+1 < len(self.status) and self.status[i+1][:2] == ' ':
+ return self.status[i:i+2]
+ return self.status[i:i+1]
+ raise hg_util.Abort("no status for " + path)
+
def GetBaseFile(self, filename):
set_status("inspecting " + filename)
# "hg status" and "hg cat" both take a path relative to the current subdir
@@ -3182,20 +3461,7 @@ class MercurialVCS(VersionControlSystem):
new_content = None
is_binary = False
oldrelpath = relpath = self._GetRelPath(filename)
- # "hg status -C" returns two lines for moved/copied files, one otherwise
- if use_hg_shell:
- out = RunShell(["hg", "status", "-C", "--rev", self.base_rev, relpath])
- else:
- fui = FakeMercurialUI()
- ret = commands.status(fui, self.repo, *[relpath], **{'rev': [self.base_rev], 'copies': True})
- if ret:
- raise util.Abort(ret)
- out = fui.output
- out = out.splitlines()
- # HACK: strip error message about missing file/directory if it isn't in
- # the working copy
- if out[0].startswith('%s: ' % relpath):
- out = out[1:]
+ out = self.get_hg_status(self.base_rev, relpath)
status, what = out[0].split(' ', 1)
if len(out) > 1 and status == "A" and what == relpath:
oldrelpath = out[1].strip()
@@ -3246,7 +3512,7 @@ def SplitPatch(data):
# When a file is modified, paths use '/' between directories, however
# when a property is modified '\' is used on Windows. Make them the same
# otherwise the file shows up twice.
- temp_filename = temp_filename.strip().replace('\\', '/')
+ temp_filename = to_slash(temp_filename.strip())
if temp_filename != filename:
# File has property changes but no modifications, create a new diff.
new_filename = temp_filename
diff --git a/lib/codereview/test.sh b/lib/codereview/test.sh
new file mode 100755
index 000000000..13f2b9cda
--- /dev/null
+++ b/lib/codereview/test.sh
@@ -0,0 +1,198 @@
+#!/bin/bash
+# Copyright 2011 The Go Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style
+# license that can be found in the LICENSE file.
+
+# Test the code review plugin.
+# Assumes a local Rietveld is running using the App Engine SDK
+# at http://localhost:7777/
+#
+# dev_appserver.py -p 7777 $HOME/pub/rietveld
+
+codereview_script=$(pwd)/codereview.py
+server=localhost:7777
+master=/tmp/go.test
+clone1=/tmp/go.test1
+clone2=/tmp/go.test2
+export HGEDITOR=true
+
+must() {
+ if ! "$@"; then
+ echo "$@" failed >&2
+ exit 1
+ fi
+}
+
+not() {
+ if "$@"; then
+ false
+ else
+ true
+ fi
+}
+
+status() {
+ echo '+++' "$@" >&2
+}
+
+firstcl() {
+ hg pending | sed 1q | tr -d ':'
+}
+
+# Initial setup.
+status Create repositories.
+rm -rf $master $clone1 $clone2
+mkdir $master
+cd $master
+must hg init .
+echo Initial state >file
+must hg add file
+must hg ci -m 'first commit' file
+must hg clone $master $clone1
+must hg clone $master $clone2
+
+echo "
+[ui]
+username=Grace R Emlin <gre@golang.org>
+[extensions]
+codereview=$codereview_script
+[codereview]
+server=$server
+" >>$clone1/.hg/hgrc
+cp $clone1/.hg/hgrc $clone2/.hg/hgrc
+
+status Codereview should be disabled.
+cd $clone1
+must hg status
+must not hg pending
+
+status Enabling code review.
+must mkdir lib lib/codereview
+must touch lib/codereview/codereview.cfg
+
+status Code review should work even without CONTRIBUTORS.
+must hg pending
+
+status Add CONTRIBUTORS.
+echo 'Grace R Emlin <gre@golang.org>' >CONTRIBUTORS
+must hg add lib/codereview/codereview.cfg CONTRIBUTORS
+
+status First submit.
+must hg submit -r gre@golang.org -m codereview \
+ lib/codereview/codereview.cfg CONTRIBUTORS
+
+status Should see change in other client.
+cd $clone2
+must hg pull -u
+must test -f lib/codereview/codereview.cfg
+must test -f CONTRIBUTORS
+
+test_clpatch() {
+ # The email address must be test@example.com to match
+ # the test code review server's default user.
+ # Clpatch will check.
+
+ cd $clone1
+ # Tried to use UTF-8 here to test that, but dev_appserver.py crashes. Ha ha.
+ if false; then
+ status Using UTF-8.
+ name="Grácè T Emlïn <test@example.com>"
+ else
+ status Using ASCII.
+ name="Grace T Emlin <test@example.com>"
+ fi
+ echo "$name" >>CONTRIBUTORS
+ cat .hg/hgrc | sed "s/Grace.*/$name/" >/tmp/x && mv /tmp/x .hg/hgrc
+ echo '
+Reviewer: gre@golang.org
+Description:
+ CONTRIBUTORS: add $name
+Files:
+ CONTRIBUTORS
+' | must hg change -i
+ num=$(hg pending | sed 1q | tr -d :)
+
+ status Patch CL.
+ cd $clone2
+ must hg clpatch $num
+ must [ "$num" = "$(firstcl)" ]
+ must hg submit $num
+
+ status Issue should be open with no reviewers.
+ must curl http://$server/api/$num >/tmp/x
+ must not grep '"closed":true' /tmp/x
+ must grep '"reviewers":\[\]' /tmp/x
+
+ status Sync should close issue.
+ cd $clone1
+ must hg sync
+ must curl http://$server/api/$num >/tmp/x
+ must grep '"closed":true' /tmp/x
+ must grep '"reviewers":\[\]' /tmp/x
+ must [ "$(firstcl)" = "" ]
+}
+
+test_reviewer() {
+ status Submit without reviewer should fail.
+ cd $clone1
+ echo dummy >dummy
+ must hg add dummy
+ echo '
+Description:
+ no reviewer
+Files:
+ dummy
+' | must hg change -i
+ num=$(firstcl)
+ must not hg submit $num
+ must hg revert dummy
+ must rm dummy
+ must hg change -d $num
+}
+
+test_linearity() {
+ status Linearity of changes.
+ cd $clone1
+ echo file1 >file1
+ must hg add file1
+ echo '
+Reviewer: gre@golang.org
+Description: file1
+Files: file1
+ ' | must hg change -i
+ must hg submit $(firstcl)
+
+ cd $clone2
+ echo file2 >file2
+ must hg add file2
+ echo '
+Reviewer: gre@golang.org
+Description: file2
+Files: file2
+ ' | must hg change -i
+ must not hg submit $(firstcl)
+ must hg sync
+ must hg submit $(firstcl)
+}
+
+test_restrict() {
+ status Cannot use hg ci.
+ cd $clone1
+ echo file1a >file1a
+ hg add file1a
+ must not hg ci -m commit file1a
+ must rm file1a
+ must hg revert file1a
+
+ status Cannot use hg rollback.
+ must not hg rollback
+
+ status Cannot use hg backout
+ must not hg backout -r -1
+}
+
+test_reviewer
+test_clpatch
+test_linearity
+test_restrict
+status ALL TESTS PASSED.
diff --git a/lib/godoc/example.html b/lib/godoc/example.html
new file mode 100644
index 000000000..ede31d61f
--- /dev/null
+++ b/lib/godoc/example.html
@@ -0,0 +1,15 @@
+<div id="example_{{.Name}}" class="toggle">
+ <div class="collapsed">
+ <p class="exampleHeading toggleButton">▹ <span class="text">Example{{example_suffix .Name}}</span></p>
+ </div>
+ <div class="expanded">
+ <p class="exampleHeading toggleButton">▾ <span class="text">Example{{example_suffix .Name}}</span></p>
+ {{with .Doc}}<p>{{html .}}</p>{{end}}
+ <p>Code:</p>
+ <pre class="code">{{.Code}}</pre>
+ {{with .Output}}
+ <p>Output:</p>
+ <pre class="output">{{html .}}</pre>
+ {{end}}
+ </div>
+</div>
diff --git a/lib/godoc/godoc.html b/lib/godoc/godoc.html
index 671160d5a..fd6032927 100644
--- a/lib/godoc/godoc.html
+++ b/lib/godoc/godoc.html
@@ -1,69 +1,72 @@
<!DOCTYPE html>
<html>
<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
-{{with .Title}}
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+{{with .Tabtitle}}
<title>{{html .}} - The Go Programming Language</title>
{{else}}
<title>The Go Programming Language</title>
{{end}}
-<link rel="stylesheet" href="/doc/all.css" type="text/css" media="all" charset="utf-8">
-<!--[if lt IE 8]>
-<link rel="stylesheet" href="/doc/ie.css" type="text/css">
-<![endif]-->
+<link type="text/css" rel="stylesheet" href="/doc/style.css">
<script type="text/javascript" src="/doc/godocs.js"></script>
+{{if .SearchBox}}
+<link rel="search" type="application/opensearchdescription+xml" title="godoc" href="/opensearch.xml" />
+{{end}}
</head>
<body>
-<div id="container">
- <div id="topnav">
- <h1 id="title">The Go Programming Language</h1>
- <div id="nav-main">
- <ul>
- <li><a href="/">Home</a></li><li><a href="/doc/install.html">Getting Started</a></li><li><a href="/doc/docs.html">Documentation</a></li><li><a href="/doc/contrib.html">Contributing</a></li><li><a href="/doc/community.html">Community</a></li>
- </ul>
- <div class="quickref">
- <form method="GET" action="/search">
- {{range .PkgRoots}}
- <a href="/pkg/{{html .}}">{{html .}}</a> <span class="sep">|</span>
- {{else}}
- References:
- {{end}}
- <a href="/pkg/">Packages</a> <span class="sep">|</span>
- <a href="/cmd/">Commands</a> <span class="sep">|</span>
- <a href="/doc/go_spec.html">Specification</a>
- {{if .SearchBox}}
- <input id="search" type="search" name="q" value="{{with .Query}}{{html .}}{{end}}" class="{{if not .Query}}inactive{{end}}" placeholder="code search" results="0" />
- {{end}}
- </form>
- </div>
- </div>
- <a id="logo-box" href="/"></a>
- </div>
- <div id="content">
- <!-- Menu is HTML-escaped elsewhere -->
- {{with .Menu}}
- <div id="menu">
- {{printf "%s" .}}
- </div>
- {{end}}
- {{with .Title}}
- <h1 id="generatedHeader">{{html .}}</h1>
- {{end}}
- {{with .Subtitle}}
- <span class="subtitle">{{html .}}</span>
- {{end}}
+<div id="topbar"><div class="container{{if .Title}} wide{{end}}">
+
+<form method="GET" action="/search">
+<div id="menu">
+<a href="/doc/">Documents</a>
+<a href="/ref/">References</a>
+<a href="/pkg/">Packages</a>
+<a href="/project/">The Project</a>
+<a href="/help/">Help</a>
+<input type="text" id="search" name="q" class="inactive" value="Search">
+</div>
+<div id="heading"><a href="/">The Go Programming Language</a></div>
+</form>
+
+</div></div>
- <!-- The Table of Contents is automatically inserted in this <div>.
- Do not delete this <div>. -->
- <div id="nav"></div>
+<div id="page"{{if .Title}} class="wide"{{end}}>
+
+{{with .Title}}
+ <div id="plusone"><g:plusone size="small" annotation="none"></g:plusone></div>
+ <h1>{{html .}}</h1>
+{{end}}
+{{with .Subtitle}}
+ <h2>{{html .}}</h2>
+{{end}}
+
+{{/* The Table of Contents is automatically inserted in this <div>.
+ Do not delete this <div>. */}}
+<div id="nav"></div>
+
+{{/* Content is HTML-escaped elsewhere */}}
+{{printf "%s" .Content}}
- <!-- Content is HTML-escaped elsewhere -->
- {{printf "%s" .Content}}
- </div>
- <div id="site-info">
- <p>Build version {{html .Version}}. Except as noted, this content is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 License</a>.</p>
- </div>
</div>
+
+<div id="footer">
+Build version {{html .Version}}.<br>
+Except as <a href="http://code.google.com/policies.html#restrictions">noted</a>,
+the content of this page is licensed under the
+Creative Commons Attribution 3.0 License,
+and code is licensed under a <a href="/LICENSE">BSD license</a>.<br>
+<a href="/doc/tos.html">Terms of Service</a> |
+<a href="http://www.google.com/intl/en/privacy/privacy-policy.html">Privacy Policy</a>
+</div>
+
</body>
+<script type="text/javascript">
+ (function() {
+ var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
+ po.src = 'https://apis.google.com/js/plusone.js';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
+ })();
+</script>
</html>
+
diff --git a/lib/godoc/opensearch.xml b/lib/godoc/opensearch.xml
new file mode 100644
index 000000000..1b652db37
--- /dev/null
+++ b/lib/godoc/opensearch.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
+ <ShortName>godoc</ShortName>
+ <Description>The Go Programming Language</Description>
+ <Tags>go golang</Tags>
+ <Contact />
+ <Url type="text/html" template="{{.BaseURL}}/search?q={searchTerms}" />
+ <Image height="15" width="16" type="image/x-icon">/favicon.ico</Image>
+ <OutputEncoding>UTF-8</OutputEncoding>
+ <InputEncoding>UTF-8</InputEncoding>
+</OpenSearchDescription>
diff --git a/lib/godoc/package.html b/lib/godoc/package.html
index 7a89d780c..41677a69d 100644
--- a/lib/godoc/package.html
+++ b/lib/godoc/package.html
@@ -3,85 +3,161 @@
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
-{{with .PAst}}
- <pre>{{node_html . $.FSet}}</pre>
-{{end}}
{{with .PDoc}}
- <!-- PackageName is printed as title by the top-level template -->
- {{if $.IsPkg}}
- <p><code>import "{{html .ImportPath}}"</code></p>
- {{end}}
- {{comment_html .Doc}}
{{if $.IsPkg}}
+ <div id="short-nav">
+ <dl>
+ <dd><code>import "{{html .ImportPath}}"</code></dd>
+ </dl>
+ <dl>
+ <dd><a href="#overview" class="overviewLink">Overview</a></dd>
+ <dd><a href="#index">Index</a></dd>
+ {{if $.Examples}}
+ <dd><a href="#examples">Examples</a></dd>
+ {{end}}
+ {{if $.Dirs}}
+ <dd><a href="#subdirectories">Subdirectories</a></dd>
+ {{end}}
+ </dl>
+ </div>
+ <!-- The package's Name is printed as title by the top-level template -->
+ <div id="overview" class="toggleVisible">
+ <div class="collapsed">
+ <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
+ </div>
+ <div class="expanded">
+ <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
+ {{comment_html .Doc}}
+ </div>
+ </div>
+ {{example_html "" $.Examples $.FSet}}
+
+ <h2 id="index">Index</h2>
+ <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
+ <div id="manual-nav">
+ <dl>
+ {{if .Consts}}
+ <dd><a href="#constants">Constants</a></dd>
+ {{end}}
+ {{if .Vars}}
+ <dd><a href="#variables">Variables</a></dd>
+ {{end}}
+ {{range .Funcs}}
+ {{$name_html := html .Name}}
+ <dd><a href="#{{$name_html}}">{{node_html .Decl $.FSet}}</a></dd>
+ {{end}}
+ {{range .Types}}
+ {{$tname_html := html .Name}}
+ <dd><a href="#{{$tname_html}}">type {{$tname_html}}</a></dd>
+ {{range .Funcs}}
+ {{$name_html := html .Name}}
+ <dd>&nbsp; &nbsp; <a href="#{{$name_html}}">{{node_html .Decl $.FSet}}</a></dd>
+ {{end}}
+ {{range .Methods}}
+ {{$name_html := html .Name}}
+ <dd>&nbsp; &nbsp; <a href="#{{$tname_html}}.{{$name_html}}">{{node_html .Decl $.FSet}}</a></dd>
+ {{end}}
+ {{end}}
+ {{if .Bugs}}
+ <dd><a href="#bugs">Bugs</a></dd>
+ {{end}}
+ </dl>
+
+ {{if $.Examples}}
+ <h4 id="examples">Examples</h4>
+ <dl>
+ {{range $.Examples}}
+ <dd><a class="exampleLink" href="#example_{{.Name}}">{{example_name .Name}}</a></dd>
+ {{end}}
+ </dl>
+ {{end}}
+
{{with .Filenames}}
- <p>
<h4>Package files</h4>
+ <p>
<span style="font-size:90%">
{{range .}}
- <a href="/{{.|srcLink}}">{{.|filename|html}}</a>
+ <a href="{{.|srcLink|html}}">{{.|filename|html}}</a>
{{end}}
</span>
</p>
{{end}}
- {{end}}
- {{with .Consts}}
- <h2 id="Constants">Constants</h2>
- {{range .}}
- {{comment_html .Doc}}
- <pre>{{node_html .Decl $.FSet}}</pre>
+
+ {{with .Consts}}
+ <h2 id="constants">Constants</h2>
+ {{range .}}
+ <pre>{{node_html .Decl $.FSet}}</pre>
+ {{comment_html .Doc}}
+ {{end}}
{{end}}
- {{end}}
- {{with .Vars}}
- <h2 id="Variables">Variables</h2>
- {{range .}}
- {{comment_html .Doc}}
- <pre>{{node_html .Decl $.FSet}}</pre>
+ {{with .Vars}}
+ <h2 id="variables">Variables</h2>
+ {{range .}}
+ <pre>{{node_html .Decl $.FSet}}</pre>
+ {{comment_html .Doc}}
+ {{end}}
{{end}}
- {{end}}
- {{with .Funcs}}
- {{range .}}
+ {{range .Funcs}}
{{/* Name is a string - no need for FSet */}}
{{$name_html := html .Name}}
- <h2 id="{{$name_html}}">func <a href="/{{posLink_url .Decl $.FSet}}">{{$name_html}}</a></h2>
- <p><code>{{node_html .Decl $.FSet}}</code></p>
+ <h2 id="{{$name_html}}">func <a href="{{posLink_url .Decl $.FSet}}">{{$name_html}}</a></h2>
+ <pre>{{node_html .Decl $.FSet}}</pre>
{{comment_html .Doc}}
+ {{example_html .Name $.Examples $.FSet}}
{{end}}
- {{end}}
- {{with .Types}}
- {{range .}}
- {{$tname_html := node_html .Type.Name $.FSet}}
- <h2 id="{{$tname_html}}">type <a href="/{{posLink_url .Decl $.FSet}}">{{$tname_html}}</a></h2>
+ {{range .Types}}
+ {{$tname := .Name}}
+ {{$tname_html := html .Name}}
+ <h2 id="{{$tname_html}}">type <a href="{{posLink_url .Decl $.FSet}}">{{$tname_html}}</a></h2>
+ <pre>{{node_html .Decl $.FSet}}</pre>
{{comment_html .Doc}}
- <p><pre>{{node_html .Decl $.FSet}}</pre></p>
+
{{range .Consts}}
- {{comment_html .Doc}}
<pre>{{node_html .Decl $.FSet}}</pre>
+ {{comment_html .Doc}}
{{end}}
+
{{range .Vars}}
- {{comment_html .Doc}}
<pre>{{node_html .Decl $.FSet}}</pre>
+ {{comment_html .Doc}}
{{end}}
- {{range .Factories}}
+
+ {{example_html $tname $.Examples $.FSet}}
+
+ {{range .Funcs}}
{{$name_html := html .Name}}
- <h3 id="{{$tname_html}}.{{$name_html}}">func <a href="/{{posLink_url .Decl $.FSet}}">{{$name_html}}</a></h3>
- <p><code>{{node_html .Decl $.FSet}}</code></p>
+ <h3 id="{{$name_html}}">func <a href="{{posLink_url .Decl $.FSet}}">{{$name_html}}</a></h3>
+ <pre>{{node_html .Decl $.FSet}}</pre>
{{comment_html .Doc}}
+ {{example_html .Name $.Examples $.FSet}}
{{end}}
+
{{range .Methods}}
{{$name_html := html .Name}}
- <h3 id="{{$tname_html}}.{{$name_html}}">func ({{node_html .Recv $.FSet}}) <a href="/{{posLink_url .Decl $.FSet}}">{{$name_html}}</a></h3>
- <p><code>{{node_html .Decl $.FSet}}</code></p>
+ <h3 id="{{$tname_html}}.{{$name_html}}">func ({{html .Recv}}) <a href="{{posLink_url .Decl $.FSet}}">{{$name_html}}</a></h3>
+ <pre>{{node_html .Decl $.FSet}}</pre>
{{comment_html .Doc}}
+ {{$name := printf "%s_%s" $tname .Name}}
+ {{example_html $name $.Examples $.FSet}}
{{end}}
{{end}}
+ </div>
+ {{else}} {{/* not a package; is a command */}}
+ {{comment_html .Doc}}
{{end}}
+
{{with .Bugs}}
- <h2 id="Bugs">Bugs</h2>
+ <h2 id="bugs">Bugs</h2>
{{range .}}
{{comment_html .}}
{{end}}
{{end}}
{{end}}
+
+{{with .PAst}}
+ <pre>{{node_html . $.FSet}}</pre>
+{{end}}
+
{{with .PList}}
<h2>Other packages</h2>
<p>
@@ -91,32 +167,46 @@
{{end}}
</p>
{{end}}
+
{{with .Dirs}}
- <p class="detail">
- Need more packages? The
- <a href="http://godashboard.appspot.com/package">Package Dashboard</a>
- provides a list of <a href="/cmd/goinstall/">goinstallable</a> packages.
- </p>
{{/* DirList entries are numbers and strings - no need for FSet */}}
- <h2 id="Subdirectories">Subdirectories</h2>
- <p>
- <table class="layout">
- <tr>
- <th align="left" colspan="{{html .MaxHeight}}">Name</th>
- <td width="25">&nbsp;</td>
- <th align="left">Synopsis</th>
- </tr>
+ {{if $.PDoc}}
+ <h2 id="subdirectories">Subdirectories</h2>
+ {{else}}
+ <div class="pkgGopher">
+ <img class="gopher" src="/doc/gopher/pkg.png"/>
+ </div>
+ {{end}}
+ <table class="dir">
<tr>
- <th align="left"><a href="..">..</a></th>
+ <th>Name</th>
+ <th>&nbsp;&nbsp;&nbsp;&nbsp;</th>
+ <th style="text-align: left; width: auto">Synopsis</th>
</tr>
- {{range .List}}
+ {{if not $.DirFlat}}
<tr>
- {{repeat `<td width="25"></td>` .Depth}}
- <td align="left" colspan="{{html .Height}}"><a href="{{html .Path}}">{{html .Name}}</a></td>
- <td></td>
- <td align="left">{{html .Synopsis}}</td>
+ <td><a href="..">..</a></td>
</tr>
{{end}}
+ {{range .List}}
+ {{if $.DirFlat}}
+ {{if .HasPkg}}
+ <tr>
+ <td><a href="{{html .Path}}">{{html .Path}}</a></td>
+ <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
+ <td style="width: auto">{{html .Synopsis}}</td>
+ </tr>
+ {{end}}
+ {{else}}
+ <tr>
+ <td>{{repeat `&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;` .Depth}}<a href="{{html .Path}}">{{html .Name}}</a></td>
+ <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
+ <td style="width: auto">{{html .Synopsis}}</td>
+ </tr>
+ {{end}}
+ {{end}}
</table>
- </p>
+ {{if $.PDoc}}{{else}}
+ <p>Need more packages? Take a look at the <a href="http://godashboard.appspot.com/">Go Project Dashboard</a>.</p>
+ {{end}}
{{end}}
diff --git a/lib/godoc/package.txt b/lib/godoc/package.txt
index 179b33493..3f3c396f0 100644
--- a/lib/godoc/package.txt
+++ b/lib/godoc/package.txt
@@ -4,12 +4,12 @@
*/}}{{with .PDoc}}{{if $.IsPkg}}PACKAGE
-package {{.PackageName}}
-import "{{.ImportPath}}"
+package {{.Name}}
+ import "{{.ImportPath}}"
{{else}}COMMAND DOCUMENTATION
-{{end}}{{.Doc}}{{/*
+{{end}}{{comment_text .Doc " " "\t"}}{{/*
---------------------------------------
@@ -17,7 +17,7 @@ import "{{.ImportPath}}"
CONSTANTS
{{range .}}{{node .Decl $.FSet}}
-{{.Doc}}{{end}}
+{{comment_text .Doc " " "\t"}}{{end}}
{{end}}{{/*
---------------------------------------
@@ -26,7 +26,7 @@ CONSTANTS
VARIABLES
{{range .}}{{node .Decl $.FSet}}
-{{.Doc}}{{end}}
+{{comment_text .Doc " " "\t"}}{{end}}
{{end}}{{/*
---------------------------------------
@@ -35,7 +35,7 @@ VARIABLES
FUNCTIONS
{{range .}}{{node .Decl $.FSet}}
-{{.Doc}}
+{{comment_text .Doc " " "\t"}}
{{end}}{{end}}{{/*
---------------------------------------
@@ -44,15 +44,15 @@ FUNCTIONS
TYPES
{{range .}}{{node .Decl $.FSet}}
-{{.Doc}}
+{{comment_text .Doc " " "\t"}}
{{range .Consts}}{{node .Decl $.FSet}}
-{{.Doc}}
+{{comment_text .Doc " " "\t"}}
{{end}}{{range .Vars}}{{node .Decl $.FSet}}
-{{.Doc}}
-{{end}}{{range .Factories}}{{node .Decl $.FSet}}
-{{.Doc}}
+{{comment_text .Doc " " "\t"}}
+{{end}}{{range .Funcs}}{{node .Decl $.FSet}}
+{{comment_text .Doc " " "\t"}}
{{end}}{{range .Methods}}{{node .Decl $.FSet}}
-{{.Doc}}
+{{comment_text .Doc " " "\t"}}
{{end}}{{end}}{{end}}{{/*
---------------------------------------
@@ -60,7 +60,7 @@ TYPES
*/}}{{with .Bugs}}
BUGS
-{{range .}}{{.}}
+{{range .}}{{comment_text . " " "\t"}}
{{end}}{{end}}{{end}}{{/*
---------------------------------------
@@ -76,7 +76,8 @@ OTHER PACKAGES
*/}}{{with .Dirs}}
SUBDIRECTORIES
-
-{{range .List}}
- {{.Name}}{{end}}
-{{end}}
+{{if $.DirFlat}}{{range .List}}{{if .HasPkg}}
+ {{.Path}}{{end}}{{end}}
+{{else}}{{range .List}}
+ {{repeat `. ` .Depth}}{{.Name}}{{end}}
+{{end}}{{end}}
diff --git a/lib/godoc/search.html b/lib/godoc/search.html
index 36c34f54d..5b54d7126 100644
--- a/lib/godoc/search.html
+++ b/lib/godoc/search.html
@@ -17,6 +17,17 @@
{{end}}
</p>
{{end}}
+{{with .Pak}}
+ <h2 id="Packages">Package {{html $.Query}}</h2>
+ <p>
+ <table class="layout">
+ {{range .}}
+ {{$pkg_html := pkgLink .Pak.Path | html}}
+ <tr><td><a href="/{{$pkg_html}}">{{$pkg_html}}</a></td></tr>
+ {{end}}
+ </table>
+ </p>
+{{end}}
{{with .Hit}}
{{with .Decls}}
<h2 id="Global">Package-level declarations</h2>
@@ -26,8 +37,8 @@
{{range .Files}}
{{$src_html := srcLink .File.Path | html}}
{{range .Groups}}
- {{range .Infos}}
- <a href="/{{$src_html}}?h={{$query_url}}#L{{infoLine .}}">{{$src_html}}:{{infoLine .}}</a>
+ {{range .}}
+ <a href="{{$src_html}}?h={{$query_url}}#L{{infoLine .}}">{{$src_html}}:{{infoLine .}}</a>
{{infoSnippet_html .}}
{{end}}
{{end}}
@@ -41,16 +52,16 @@
<h3 id="Local_{{$pkg_html}}">package <a href="/{{$pkg_html}}">{{html .Pak.Name}}</a></h3>
{{range .Files}}
{{$src_html := srcLink .File.Path | html}}
- <a href="/{{$src_html}}?h={{$query_url}}">{{$src_html}}</a>
+ <a href="{{$src_html}}?h={{$query_url}}">{{$src_html}}</a>
<table class="layout">
{{range .Groups}}
<tr>
<td width="25"></td>
- <th align="left" valign="top">{{infoKind_html .Kind}}</th>
+ <th align="left" valign="top">{{index . 0 | infoKind_html}}</th>
<td align="left" width="4"></td>
<td>
- {{range .Infos}}
- <a href="/{{$src_html}}?h={{$query_url}}#L{{infoLine .}}">{{infoLine .}}</a>
+ {{range .}}
+ <a href="{{$src_html}}?h={{$query_url}}#L{{infoLine .}}">{{infoLine .}}</a>
{{end}}
</td>
</tr>
@@ -75,14 +86,14 @@
{{$src_html := srcLink .Filename | html}}
<tr>
<td align="left" valign="top">
- <a href="/{{$src_html}}?h={{$query_url}}">{{$src_html}}</a>:
+ <a href="{{$src_html}}?h={{$query_url}}">{{$src_html}}</a>:
</td>
<td align="left" width="4"></td>
<th align="left" valign="top">{{len .Lines}}</th>
<td align="left" width="4"></td>
<td align="left">
{{range .Lines}}
- <a href="/{{$src_html}}?h={{$query_url}}#L{{html .}}">{{html .}}</a>
+ <a href="{{$src_html}}?h={{$query_url}}#L{{html .}}">{{html .}}</a>
{{end}}
{{if not $.Complete}}
...
diff --git a/lib/godoc/search.txt b/lib/godoc/search.txt
index 1dd64afdb..5251a388e 100644
--- a/lib/godoc/search.txt
+++ b/lib/godoc/search.txt
@@ -1,33 +1,40 @@
QUERY
{{.Query}}
-{{with .Alert}}
-{{.}}
+
+{{with .Alert}}{{.}}
{{end}}{{/* .Alert */}}{{/*
---------------------------------------
-*/}}{{with .Alt}}
-DID YOU MEAN
+*/}}{{with .Alt}}DID YOU MEAN
+
{{range .Alts}} {{.}}
-{{end}}{{end}}{{/* .Alts */}}{{/*
+{{end}}
+{{end}}{{/* .Alt */}}{{/*
+
+---------------------------------------
+
+*/}}{{with .Pak}}PACKAGE {{$.Query}}
+
+{{range .}} {{pkgLink .Pak.Path}}
+{{end}}
+{{end}}{{/* .Pak */}}{{/*
---------------------------------------
-*/}}{{with .Hit}}{{with .Decls}}
-PACKAGE-LEVEL DECLARATIONS
+*/}}{{with .Hit}}{{with .Decls}}PACKAGE-LEVEL DECLARATIONS
{{range .}}package {{.Pak.Name}}
-{{range $file := .Files}}{{range .Groups}}{{range .Infos}} {{srcLink $file.File.Path}}:{{infoLine .}}{{end}}
+{{range $file := .Files}}{{range .Groups}}{{range .}} {{srcLink $file.File.Path}}:{{infoLine .}}{{end}}
{{end}}{{end}}{{/* .Files */}}
{{end}}{{end}}{{/* .Decls */}}{{/*
---------------------------------------
-*/}}{{with .Others}}
-LOCAL DECLARATIONS AND USES
+*/}}{{with .Others}}LOCAL DECLARATIONS AND USES
{{range .}}package {{.Pak.Name}}
-{{range $file := .Files}}{{range .Groups}}{{range .Infos}} {{srcLink $file.File.Path}}:{{infoLine .}}
+{{range $file := .Files}}{{range .Groups}}{{range .}} {{srcLink $file.File.Path}}:{{infoLine .}}
{{end}}{{end}}{{end}}{{/* .Files */}}
{{end}}{{end}}{{/* .Others */}}{{end}}{{/* .Hit */}}{{/*
diff --git a/lib/time/README b/lib/time/README
new file mode 100644
index 000000000..d83e0addf
--- /dev/null
+++ b/lib/time/README
@@ -0,0 +1,10 @@
+The zoneinfo.zip archive contains time zone files compiled using
+the code and data maintained as part of the IANA Time Zone Database.
+The IANA asserts that the database is in the public domain.
+
+For more information, see
+http://www.iana.org/time-zones
+ftp://ftp.iana.org/tz/code/tz-link.htm
+http://tools.ietf.org/html/draft-lear-iana-timezone-database-05
+
+To rebuild the archive, read and run update.bash.
diff --git a/lib/time/update.bash b/lib/time/update.bash
new file mode 100755
index 000000000..ef7fdc79b
--- /dev/null
+++ b/lib/time/update.bash
@@ -0,0 +1,50 @@
+#!/bin/sh
+# Copyright 2012 The Go Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style
+# license that can be found in the LICENSE file.
+
+# This script rebuilds the time zone files using files
+# downloaded from the ICANN/IANA distribution.
+
+# Versions to use.
+CODE=2011i
+DATA=2011n
+
+set -e
+rm -rf work
+mkdir work
+cd work
+mkdir zoneinfo
+curl -O http://www.iana.org/time-zones/repository/releases/tzcode$CODE.tar.gz
+curl -O http://www.iana.org/time-zones/repository/releases/tzdata$DATA.tar.gz
+tar xzf tzcode$CODE.tar.gz
+tar xzf tzdata$DATA.tar.gz
+
+# Turn off 64-bit output in time zone files.
+# We don't need those until 2037.
+perl -p -i -e 's/pass <= 2/pass <= 1/' zic.c
+
+make CFLAGS=-DSTD_INSPIRED AWK=awk TZDIR=zoneinfo posix_only
+
+# America/Los_Angeles should not be bigger than 1100 bytes.
+# If it is, we probably failed to disable the 64-bit output, which
+# triples the size of the files.
+size=$(ls -l zoneinfo/America/Los_Angeles | awk '{print $5}')
+if [ $size -gt 1200 ]; then
+ echo 'zone file too large; 64-bit edit failed?' >&2
+ exit 2
+fi
+
+cd zoneinfo
+rm -f ../../zoneinfo.zip
+zip -0 -r ../../zoneinfo.zip *
+cd ../..
+
+echo
+if [ "$1" == "-work" ]; then
+ echo Left workspace behind in work/.
+else
+ rm -rf work
+fi
+echo New time zone files in zoneinfo.zip.
+
diff --git a/lib/time/zoneinfo.zip b/lib/time/zoneinfo.zip
new file mode 100644
index 000000000..b54213239
--- /dev/null
+++ b/lib/time/zoneinfo.zip
Binary files differ