]> Cypherpunks repositories - gostls13.git/commitdiff
codereview: support for subrepositories
authorRuss Cox <rsc@golang.org>
Wed, 25 Jan 2012 19:32:10 +0000 (14:32 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 25 Jan 2012 19:32:10 +0000 (14:32 -0500)
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/5564054

lib/codereview/codereview.py

index 3dbbb72606a970ced1f66afbe6024daa51c79656..6d69d7e2bcb9f0c7658d8db27247c743c70f3bd0 100644 (file)
@@ -955,14 +955,23 @@ def CheckTabfmt(ui, repo, files, just_warn):
 #######################################################################
 # CONTRIBUTORS file parsing
 
-contributors = {}
+contributorsCache = None
+contributorsURL = None
 
 def ReadContributors(ui, repo):
-       global contributors
+       global contributorsCache
+       if contributorsCache is not None:
+               return contributorsCache
+
        try:
-               f = open(repo.root + '/CONTRIBUTORS', 'r')
+               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" % (repo.root+'/CONTRIBUTORS', ExceptionDetail()))
+               ui.write("warning: cannot open %s: %s\n" % (opening, ExceptionDetail()))
                return
 
        for line in f:
@@ -980,6 +989,9 @@ def ReadContributors(ui, repo):
                        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)
@@ -997,6 +1009,7 @@ def FindContributor(ui, repo, user=None, warn=True):
        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,))
@@ -2163,27 +2176,35 @@ def reposetup(ui, repo):
        global codereview_disabled
        global defaultcc
        
+       # 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 = ''
-       # Read repository-specific options from lib/codereview/codereview.cfg
+       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:
-               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:])
+                       if line.startswith('defaultcc:'):
+                               defaultcc = SplitCommaSpace(line[len('defaultcc:'):])
+                       if line.startswith('contributors:'):
+                               global contributorsURL
+                               contributorsURL = line[len('contributors:'):].strip()
        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 == '':
-                       codereview_disabled = 'codereview disabled: repository has no root'
-               else:
-                       codereview_disabled = 'codereview disabled: cannot open ' + repo_config_path
+               codereview_disabled = 'codereview disabled: cannot open ' + repo_config_path
                return
 
        InstallMatch(ui, repo)
-       ReadContributors(ui, repo)
        RietveldSetup(ui, repo)
 
        # Disable the Mercurial commands that might change the repository.
@@ -3298,7 +3319,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."""