From accc56d82b902e7c7a22401db710958fcb1c7b58 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 18 Apr 2009 14:45:51 -0700 Subject: 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 --- git_config.py | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'git_config.py') 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): self.file = file self.defaults = defaults self._cache_dict = None + self._section_dict = None self._remotes = {} self._branches = {} self._pickle = os.path.join( @@ -168,6 +169,33 @@ class GitConfig(object): self._branches[b.name] = b return b + def HasSection(self, section, subsection = ''): + """Does at least one key in section.subsection exist? + """ + try: + return subsection in self._sections[section] + except KeyError: + return False + + @property + def _sections(self): + d = self._section_dict + if d is None: + d = {} + for name in self._cache.keys(): + p = name.split('.') + if 2 == len(p): + section = p[0] + subsect = '' + else: + section = p[0] + subsect = '.'.join(p[1:-1]) + if section not in d: + d[section] = set() + d[section].add(subsect) + self._section_dict = d + return d + @property def _cache(self): if self._cache_dict is None: @@ -443,11 +471,23 @@ class Branch(object): def Save(self): """Save this branch back into the configuration. """ - self._Set('merge', self.merge) - if self.remote: - self._Set('remote', self.remote.name) + if self._config.HasSection('branch', self.name): + if self.remote: + self._Set('remote', self.remote.name) + else: + self._Set('remote', None) + self._Set('merge', self.merge) + else: - self._Set('remote', None) + fd = open(self._config.file, 'ab') + try: + fd.write('[branch "%s"]\n' % self.name) + if self.remote: + fd.write('\tremote = %s\n' % self.remote.name) + if self.merge: + fd.write('\tmerge = %s\n' % self.merge) + finally: + fd.close() def _Set(self, key, value): key = 'branch.%s.%s' % (self.name, key) -- cgit v1.2.3-54-g00ecf