diff options
| author | Dave Borowitz <dborowitz@google.com> | 2013-06-03 15:05:07 -0700 |
|---|---|---|
| committer | Dave Borowitz <dborowitz@google.com> | 2013-06-04 00:12:15 +0000 |
| commit | 74c1f3d5e6ce819797795a2931cc32a9ed5535cb (patch) | |
| tree | 6fb625b630c36318fbfbdf815efecb1a4801459f /project.py | |
| parent | 91f3ba5a3f6e3c76577b94c0a6c31974d5a3f077 (diff) | |
| download | git-repo-74c1f3d5e6ce819797795a2931cc32a9ed5535cb.tar.gz | |
Read cookie file from git-remote-persistent-https if applicable
git-remote-persistent-https proxy implementations may pass cookie file
configuration to git-remote-https. When fetching bundles for
persistent-http(s) URLs, use the -print_config flag (if supported) to
extract this information from the proxy binary and pass it to curl,
overriding http.cookiefile from .gitconfig.
This adds a few ms overhead per clone.bundle fetch, which should be
acceptable since it happens only on the initial clone, which takes
much longer anyway.
Change-Id: I03be8ebaf8d3005855d33998cd8ecd412e8ec287
Diffstat (limited to 'project.py')
| -rw-r--r-- | project.py | 33 |
1 files changed, 29 insertions, 4 deletions
| @@ -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(): |
| @@ -1824,6 +1825,30 @@ class Project(object): | |||
| 1824 | except OSError: | 1825 | except OSError: |
| 1825 | return False | 1826 | return False |
| 1826 | 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 | |||
| 1827 | def _Checkout(self, rev, quiet=False): | 1852 | def _Checkout(self, rev, quiet=False): |
| 1828 | cmd = ['checkout'] | 1853 | cmd = ['checkout'] |
| 1829 | if quiet: | 1854 | if quiet: |
