summaryrefslogtreecommitdiffstats
path: root/git_config.py
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2015-08-19 23:36:35 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-08-19 23:36:35 +0000
commit7c9263bce09725227dc518ee298b350becbdf26e (patch)
treec2547dbfca738c2da6763fb5fe59195f4ee10658 /git_config.py
parentdab9e99f0f6d4f82e0e61b37396f7c0915a8d508 (diff)
parent0745bb26571e0cf097baebd48761b8cd743ec7fc (diff)
downloadgit-repo-7c9263bce09725227dc518ee298b350becbdf26e.tar.gz
Merge "Support smart-sync through persistent-http[s]"
Diffstat (limited to 'git_config.py')
-rw-r--r--git_config.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/git_config.py b/git_config.py
index 8ded7c25..0379181a 100644
--- a/git_config.py
+++ b/git_config.py
@@ -15,6 +15,8 @@
15 15
16from __future__ import print_function 16from __future__ import print_function
17 17
18import contextlib
19import errno
18import json 20import json
19import os 21import os
20import re 22import re
@@ -502,6 +504,43 @@ def GetSchemeFromUrl(url):
502 return m.group(1) 504 return m.group(1)
503 return None 505 return None
504 506
507@contextlib.contextmanager
508def GetUrlCookieFile(url, quiet):
509 if url.startswith('persistent-'):
510 try:
511 p = subprocess.Popen(
512 ['git-remote-persistent-https', '-print_config', url],
513 stdin=subprocess.PIPE, stdout=subprocess.PIPE,
514 stderr=subprocess.PIPE)
515 try:
516 cookieprefix = 'http.cookiefile='
517 proxyprefix = 'http.proxy='
518 cookiefile = None
519 proxy = None
520 for line in p.stdout:
521 line = line.strip()
522 if line.startswith(cookieprefix):
523 cookiefile = line[len(cookieprefix):]
524 if line.startswith(proxyprefix):
525 proxy = line[len(proxyprefix):]
526 # Leave subprocess open, as cookie file may be transient.
527 if cookiefile or proxy:
528 yield cookiefile, proxy
529 return
530 finally:
531 p.stdin.close()
532 if p.wait():
533 err_msg = p.stderr.read()
534 if ' -print_config' in err_msg:
535 pass # Persistent proxy doesn't support -print_config.
536 elif not quiet:
537 print(err_msg, file=sys.stderr)
538 except OSError as e:
539 if e.errno == errno.ENOENT:
540 pass # No persistent proxy.
541 raise
542 yield GitConfig.ForUser().GetString('http.cookiefile'), None
543
505def _preconnect(url): 544def _preconnect(url):
506 m = URI_ALL.match(url) 545 m = URI_ALL.match(url)
507 if m: 546 if m: