summaryrefslogtreecommitdiffstats
path: root/git_config.py
diff options
context:
space:
mode:
Diffstat (limited to 'git_config.py')
-rw-r--r--git_config.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/git_config.py b/git_config.py
index 13fbda24..5fb61d21 100644
--- a/git_config.py
+++ b/git_config.py
@@ -59,18 +59,23 @@ ID_RE = re.compile(r'^[0-9a-f]{40}$')
59 59
60REVIEW_CACHE = dict() 60REVIEW_CACHE = dict()
61 61
62
62def IsChange(rev): 63def IsChange(rev):
63 return rev.startswith(R_CHANGES) 64 return rev.startswith(R_CHANGES)
64 65
66
65def IsId(rev): 67def IsId(rev):
66 return ID_RE.match(rev) 68 return ID_RE.match(rev)
67 69
70
68def IsTag(rev): 71def IsTag(rev):
69 return rev.startswith(R_TAGS) 72 return rev.startswith(R_TAGS)
70 73
74
71def IsImmutable(rev): 75def IsImmutable(rev):
72 return IsChange(rev) or IsId(rev) or IsTag(rev) 76 return IsChange(rev) or IsId(rev) or IsTag(rev)
73 77
78
74def _key(name): 79def _key(name):
75 parts = name.split('.') 80 parts = name.split('.')
76 if len(parts) < 2: 81 if len(parts) < 2:
@@ -79,6 +84,7 @@ def _key(name):
79 parts[-1] = parts[-1].lower() 84 parts[-1] = parts[-1].lower()
80 return '.'.join(parts) 85 return '.'.join(parts)
81 86
87
82class GitConfig(object): 88class GitConfig(object):
83 _ForUser = None 89 _ForUser = None
84 90
@@ -392,6 +398,7 @@ _master_keys = set()
392_ssh_master = True 398_ssh_master = True
393_master_keys_lock = None 399_master_keys_lock = None
394 400
401
395def init_ssh(): 402def init_ssh():
396 """Should be called once at the start of repo to init ssh master handling. 403 """Should be called once at the start of repo to init ssh master handling.
397 404
@@ -401,6 +408,7 @@ def init_ssh():
401 assert _master_keys_lock is None, "Should only call init_ssh once" 408 assert _master_keys_lock is None, "Should only call init_ssh once"
402 _master_keys_lock = _threading.Lock() 409 _master_keys_lock = _threading.Lock()
403 410
411
404def _open_ssh(host, port=None): 412def _open_ssh(host, port=None):
405 global _ssh_master 413 global _ssh_master
406 414
@@ -479,6 +487,7 @@ def _open_ssh(host, port=None):
479 finally: 487 finally:
480 _master_keys_lock.release() 488 _master_keys_lock.release()
481 489
490
482def close_ssh(): 491def close_ssh():
483 global _master_keys_lock 492 global _master_keys_lock
484 493
@@ -503,15 +512,18 @@ def close_ssh():
503 # We're done with the lock, so we can delete it. 512 # We're done with the lock, so we can delete it.
504 _master_keys_lock = None 513 _master_keys_lock = None
505 514
515
506URI_SCP = re.compile(r'^([^@:]*@?[^:/]{1,}):') 516URI_SCP = re.compile(r'^([^@:]*@?[^:/]{1,}):')
507URI_ALL = re.compile(r'^([a-z][a-z+-]*)://([^@/]*@?[^/]*)/') 517URI_ALL = re.compile(r'^([a-z][a-z+-]*)://([^@/]*@?[^/]*)/')
508 518
519
509def GetSchemeFromUrl(url): 520def GetSchemeFromUrl(url):
510 m = URI_ALL.match(url) 521 m = URI_ALL.match(url)
511 if m: 522 if m:
512 return m.group(1) 523 return m.group(1)
513 return None 524 return None
514 525
526
515@contextlib.contextmanager 527@contextlib.contextmanager
516def GetUrlCookieFile(url, quiet): 528def GetUrlCookieFile(url, quiet):
517 if url.startswith('persistent-'): 529 if url.startswith('persistent-'):
@@ -552,6 +564,7 @@ def GetUrlCookieFile(url, quiet):
552 cookiefile = os.path.expanduser(cookiefile) 564 cookiefile = os.path.expanduser(cookiefile)
553 yield cookiefile, None 565 yield cookiefile, None
554 566
567
555def _preconnect(url): 568def _preconnect(url):
556 m = URI_ALL.match(url) 569 m = URI_ALL.match(url)
557 if m: 570 if m:
@@ -572,9 +585,11 @@ def _preconnect(url):
572 585
573 return False 586 return False
574 587
588
575class Remote(object): 589class Remote(object):
576 """Configuration options related to a remote. 590 """Configuration options related to a remote.
577 """ 591 """
592
578 def __init__(self, config, name): 593 def __init__(self, config, name):
579 self._config = config 594 self._config = config
580 self.name = name 595 self.name = name
@@ -735,6 +750,7 @@ class Remote(object):
735class Branch(object): 750class Branch(object):
736 """Configuration options related to a single branch. 751 """Configuration options related to a single branch.
737 """ 752 """
753
738 def __init__(self, config, name): 754 def __init__(self, config, name):
739 self._config = config 755 self._config = config
740 self.name = name 756 self.name = name