| Index: repo
|
| ===================================================================
|
| --- repo (revision 109734)
|
| +++ repo (working copy)
|
| @@ -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 @@
|
| 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 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 @@
|
| 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 @@
|
| 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,7 +341,63 @@
|
| 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 @@
|
| 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):
|
|
|