summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
Diffstat (limited to 'project.py')
-rw-r--r--project.py46
1 files changed, 41 insertions, 5 deletions
diff --git a/project.py b/project.py
index 5a7a6ca8..679dccc1 100644
--- a/project.py
+++ b/project.py
@@ -1728,9 +1728,8 @@ class Project(object):
1728 remote = self.GetRemote(self.remote.name) 1728 remote = self.GetRemote(self.remote.name)
1729 bundle_url = remote.url + '/clone.bundle' 1729 bundle_url = remote.url + '/clone.bundle'
1730 bundle_url = GitConfig.ForUser().UrlInsteadOf(bundle_url) 1730 bundle_url = GitConfig.ForUser().UrlInsteadOf(bundle_url)
1731 if GetSchemeFromUrl(bundle_url) in ('persistent-http', 'persistent-https'): 1731 if GetSchemeFromUrl(bundle_url) not in (
1732 bundle_url = bundle_url[len('persistent-'):] 1732 'http', 'https', 'persistent-http', 'persistent-https'):
1733 if GetSchemeFromUrl(bundle_url) not in ('http', 'https'):
1734 return False 1733 return False
1735 1734
1736 bundle_dst = os.path.join(self.gitdir, 'clone.bundle') 1735 bundle_dst = os.path.join(self.gitdir, 'clone.bundle')
@@ -1779,9 +1778,11 @@ class Project(object):
1779 os.remove(tmpPath) 1778 os.remove(tmpPath)
1780 if 'http_proxy' in os.environ and 'darwin' == sys.platform: 1779 if 'http_proxy' in os.environ and 'darwin' == sys.platform:
1781 cmd += ['--proxy', os.environ['http_proxy']] 1780 cmd += ['--proxy', os.environ['http_proxy']]
1782 cookiefile = GitConfig.ForUser().GetString('http.cookiefile') 1781 cookiefile = self._GetBundleCookieFile(srcUrl)
1783 if cookiefile: 1782 if cookiefile:
1784 cmd += ['--cookie', cookiefile] 1783 cmd += ['--cookie', cookiefile]
1784 if srcUrl.startswith('persistent-'):
1785 srcUrl = srcUrl[len('persistent-'):]
1785 cmd += [srcUrl] 1786 cmd += [srcUrl]
1786 1787
1787 if IsTrace(): 1788 if IsTrace():
@@ -1804,7 +1805,7 @@ class Project(object):
1804 return False 1805 return False
1805 1806
1806 if os.path.exists(tmpPath): 1807 if os.path.exists(tmpPath):
1807 if curlret == 0 and os.stat(tmpPath).st_size > 16: 1808 if curlret == 0 and self._IsValidBundle(tmpPath):
1808 os.rename(tmpPath, dstPath) 1809 os.rename(tmpPath, dstPath)
1809 return True 1810 return True
1810 else: 1811 else:
@@ -1813,6 +1814,41 @@ class Project(object):
1813 else: 1814 else:
1814 return False 1815 return False
1815 1816
1817 def _IsValidBundle(self, path):
1818 try:
1819 with open(path) as f:
1820 if f.read(16) == '# v2 git bundle\n':
1821 return True
1822 else:
1823 print("Invalid clone.bundle file; ignoring.", file=sys.stderr)
1824 return False
1825 except OSError:
1826 return False
1827
1828 def _GetBundleCookieFile(self, url):
1829 if url.startswith('persistent-'):
1830 try:
1831 p = subprocess.Popen(
1832 ['git-remote-persistent-https', '-print_config', url],
1833 stdin=subprocess.PIPE, stdout=subprocess.PIPE,
1834 stderr=subprocess.PIPE)
1835 prefix = 'http.cookiefile='
1836 for line in p.stdout:
1837 line = line.strip()
1838 if line.startswith(prefix):
1839 return line[len(prefix):]
1840 if p.wait():
1841 line = iter(p.stderr).next()
1842 if ' -print_config' in line:
1843 pass # Persistent proxy doesn't support -print_config.
1844 else:
1845 print(line + p.stderr.read(), file=sys.stderr)
1846 except OSError as e:
1847 if e.errno == errno.ENOENT:
1848 pass # No persistent proxy.
1849 raise
1850 return GitConfig.ForUser().GetString('http.cookiefile')
1851
1816 def _Checkout(self, rev, quiet=False): 1852 def _Checkout(self, rev, quiet=False):
1817 cmd = ['checkout'] 1853 cmd = ['checkout']
1818 if quiet: 1854 if quiet: