From ad39056fb91820be9f99d8b00a54be961c0a453f Mon Sep 17 00:00:00 2001 From: "jeffbailey@chromium.org" Date: Sat, 12 Nov 2011 00:37:07 +0000 Subject: [PATCH] Update version of repo. Most importantly this takes repo from the current canonical upstream. The Chromium mirror is out of date. Review URL: http://codereview.chromium.org/8540026 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@109742 0039d316-1c4b-4281-b951-d872f2087c98 --- repo | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 94 insertions(+), 11 deletions(-) diff --git a/repo b/repo index 5fbb39600..0e7798338 100755 --- a/repo +++ b/repo @@ -2,7 +2,7 @@ ## repo default configuration ## -REPO_URL='http://git.chromium.org/external/repo.git' +REPO_URL='https://code.google.com/p/git-repo/' REPO_REV='stable' # Copyright (C) 2008 Google Inc. @@ -28,7 +28,7 @@ if __name__ == '__main__': del magic # increment this whenever we make important changes to this script -VERSION = (1, 11) +VERSION = (1, 13) # increment this if the MAINTAINER_KEYS block is modified KEYRING_VERSION = (1,0) @@ -91,6 +91,7 @@ import re import readline import subprocess import sys +import urllib2 home_dot_repo = os.path.expanduser('~/.repoconfig') gpg_dir = os.path.join(home_dot_repo, 'gnupg') @@ -187,10 +188,6 @@ def _Init(args): else: can_verify = True - if not opt.quiet: - print >>sys.stderr, 'Getting repo ...' - print >>sys.stderr, ' from %s' % url - dst = os.path.abspath(os.path.join(repodir, S_repo)) _Clone(url, dst, opt.quiet) @@ -300,15 +297,42 @@ def _SetConfig(local, name, value): raise CloneFailure() -def _Fetch(local, quiet, *args): +def _InitHttp(): + handlers = [] + + mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() + try: + import netrc + n = netrc.netrc() + for host in n.hosts: + p = n.hosts[host] + mgr.add_password(None, 'http://%s/' % host, p[0], p[2]) + mgr.add_password(None, 'https://%s/' % host, p[0], p[2]) + except: + pass + handlers.append(urllib2.HTTPBasicAuthHandler(mgr)) + + if 'http_proxy' in os.environ: + url = os.environ['http_proxy'] + handlers.append(urllib2.ProxyHandler({'http': url, 'https': url})) + if 'REPO_CURL_VERBOSE' in os.environ: + handlers.append(urllib2.HTTPHandler(debuglevel=1)) + handlers.append(urllib2.HTTPSHandler(debuglevel=1)) + urllib2.install_opener(urllib2.build_opener(*handlers)) + +def _Fetch(url, local, src, quiet): + if not quiet: + print >>sys.stderr, 'Get %s' % url + cmd = [GIT, 'fetch'] if quiet: cmd.append('--quiet') err = subprocess.PIPE else: err = None - cmd.extend(args) - cmd.append('origin') + cmd.append(src) + cmd.append('+refs/heads/*:refs/remotes/origin/*') + cmd.append('refs/tags/*:refs/tags/*') proc = subprocess.Popen(cmd, cwd = local, stderr = err) if err: @@ -317,6 +341,62 @@ def _Fetch(local, quiet, *args): if proc.wait() != 0: raise CloneFailure() +def _DownloadBundle(url, local, quiet): + if not url.endswith('/'): + url += '/' + url += 'clone.bundle' + + proc = subprocess.Popen( + [GIT, 'config', '--get-regexp', 'url.*.insteadof'], + cwd = local, + stdout = subprocess.PIPE) + for line in proc.stdout: + m = re.compile(r'^url\.(.*)\.insteadof (.*)$').match(line) + if m: + new_url = m.group(1) + old_url = m.group(2) + if url.startswith(old_url): + url = new_url + url[len(old_url):] + break + proc.stdout.close() + proc.wait() + + if not url.startswith('http:') and not url.startswith('https:'): + return False + + dest = open(os.path.join(local, '.git', 'clone.bundle'), 'w+b') + try: + try: + r = urllib2.urlopen(url) + except urllib2.HTTPError, e: + if e.code == 404: + return False + print >>sys.stderr, 'fatal: Cannot get %s' % url + print >>sys.stderr, 'fatal: HTTP error %s' % e.code + raise CloneFailure() + except urllib2.URLError, e: + print >>sys.stderr, 'fatal: Cannot get %s' % url + print >>sys.stderr, 'fatal: error %s' % e.reason + raise CloneFailure() + try: + if not quiet: + print >>sys.stderr, 'Get %s' % url + while True: + buf = r.read(8192) + if buf == '': + return True + dest.write(buf) + finally: + r.close() + finally: + dest.close() + +def _ImportBundle(local): + path = os.path.join(local, '.git', 'clone.bundle') + try: + _Fetch(local, local, path, True) + finally: + os.remove(path) def _Clone(url, local, quiet): """Clones a git repository to a new subdirectory of repodir @@ -344,11 +424,14 @@ def _Clone(url, local, quiet): print >>sys.stderr, 'fatal: could not create %s' % local raise CloneFailure() + _InitHttp() _SetConfig(local, 'remote.origin.url', url) _SetConfig(local, 'remote.origin.fetch', '+refs/heads/*:refs/remotes/origin/*') - _Fetch(local, quiet) - _Fetch(local, quiet, '--tags') + if _DownloadBundle(url, local, quiet): + _ImportBundle(local) + else: + _Fetch(url, local, 'origin', quiet) def _Verify(cwd, branch, quiet):