summaryrefslogtreecommitdiffstats
path: root/git_config.py
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2009-04-18 14:45:51 -0700
committerShawn O. Pearce <sop@google.com>2009-04-18 14:45:51 -0700
commitaccc56d82b902e7c7a22401db710958fcb1c7b58 (patch)
tree3c3d233fe188315df9d87ddc247672a92167a3f5 /git_config.py
parentdb45da12089bf131579d100ff7990cbc18d07325 (diff)
downloadgit-repo-accc56d82b902e7c7a22401db710958fcb1c7b58.tar.gz
Speed up 'repo start' by removing some forks
Its quite common for most projects to be matching the current manifest revision, as most developers only modify one or two projects at any one time. We can speed up `repo start foo` (that impacts the entire client) by performing most of the branch creation and switch operations in pure Python, and thus avoid 4 forks per project. Signed-off-by: Shawn O. Pearce <sop@google.com>
Diffstat (limited to 'git_config.py')
-rw-r--r--git_config.py48
1 files changed, 44 insertions, 4 deletions
diff --git a/git_config.py b/git_config.py
index 78069c5d..7aad80d2 100644
--- a/git_config.py
+++ b/git_config.py
@@ -57,6 +57,7 @@ class GitConfig(object):
57 self.file = file 57 self.file = file
58 self.defaults = defaults 58 self.defaults = defaults
59 self._cache_dict = None 59 self._cache_dict = None
60 self._section_dict = None
60 self._remotes = {} 61 self._remotes = {}
61 self._branches = {} 62 self._branches = {}
62 self._pickle = os.path.join( 63 self._pickle = os.path.join(
@@ -168,6 +169,33 @@ class GitConfig(object):
168 self._branches[b.name] = b 169 self._branches[b.name] = b
169 return b 170 return b
170 171
172 def HasSection(self, section, subsection = ''):
173 """Does at least one key in section.subsection exist?
174 """
175 try:
176 return subsection in self._sections[section]
177 except KeyError:
178 return False
179
180 @property
181 def _sections(self):
182 d = self._section_dict
183 if d is None:
184 d = {}
185 for name in self._cache.keys():
186 p = name.split('.')
187 if 2 == len(p):
188 section = p[0]
189 subsect = ''
190 else:
191 section = p[0]
192 subsect = '.'.join(p[1:-1])
193 if section not in d:
194 d[section] = set()
195 d[section].add(subsect)
196 self._section_dict = d
197 return d
198
171 @property 199 @property
172 def _cache(self): 200 def _cache(self):
173 if self._cache_dict is None: 201 if self._cache_dict is None:
@@ -443,11 +471,23 @@ class Branch(object):
443 def Save(self): 471 def Save(self):
444 """Save this branch back into the configuration. 472 """Save this branch back into the configuration.
445 """ 473 """
446 self._Set('merge', self.merge) 474 if self._config.HasSection('branch', self.name):
447 if self.remote: 475 if self.remote:
448 self._Set('remote', self.remote.name) 476 self._Set('remote', self.remote.name)
477 else:
478 self._Set('remote', None)
479 self._Set('merge', self.merge)
480
449 else: 481 else:
450 self._Set('remote', None) 482 fd = open(self._config.file, 'ab')
483 try:
484 fd.write('[branch "%s"]\n' % self.name)
485 if self.remote:
486 fd.write('\tremote = %s\n' % self.remote.name)
487 if self.merge:
488 fd.write('\tmerge = %s\n' % self.merge)
489 finally:
490 fd.close()
451 491
452 def _Set(self, key, value): 492 def _Set(self, key, value):
453 key = 'branch.%s.%s' % (self.name, key) 493 key = 'branch.%s.%s' % (self.name, key)