summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2020-02-19 15:50:00 -0500
committerMike Frysinger <vapier@google.com>2020-02-19 23:44:10 +0000
commitf81c72ed7727ca408d1859a86c56b532a8de8d59 (patch)
tree9cdd3f23feed26c922528e8d1db86c3ebde03cc8
parent77b4397a7376fe52fe0725ed538891c89da161ed (diff)
downloadgit-repo-f81c72ed7727ca408d1859a86c56b532a8de8d59.tar.gz
project: set core.repositoryFormatVersion=1 when using extensions
When using extensions, make sure we set the git repo format version so git knows to check the extension compatibility. We can add a helper to the Project API to simplify this and make it foolproof. Change-Id: I9ab6c32d92fe2b8e5df6e2b080ca71556332e909 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/256035 Tested-by: Mike Frysinger <vapier@google.com> Reviewed-by: Jonathan Nieder <jrn@google.com>
-rw-r--r--project.py22
-rw-r--r--subcmds/sync.py3
2 files changed, 21 insertions, 4 deletions
diff --git a/project.py b/project.py
index 3a7ac9e8..5bead641 100644
--- a/project.py
+++ b/project.py
@@ -2186,6 +2186,24 @@ class Project(object):
2186 return result 2186 return result
2187 2187
2188# Direct Git Commands ## 2188# Direct Git Commands ##
2189 def EnableRepositoryExtension(self, key, value='true', version=1):
2190 """Enable git repository extension |key| with |value|.
2191
2192 Args:
2193 key: The extension to enabled. Omit the "extensions." prefix.
2194 value: The value to use for the extension.
2195 version: The minimum git repository version needed.
2196 """
2197 # Make sure the git repo version is new enough already.
2198 found_version = self.config.GetInt('core.repositoryFormatVersion')
2199 if found_version is None:
2200 found_version = 0
2201 if found_version < version:
2202 self.config.SetString('core.repositoryFormatVersion', str(version))
2203
2204 # Enable the extension!
2205 self.config.SetString('extensions.%s' % (key,), value)
2206
2189 def _CheckForImmutableRevision(self): 2207 def _CheckForImmutableRevision(self):
2190 try: 2208 try:
2191 # if revision (sha or tag) is not present then following function 2209 # if revision (sha or tag) is not present then following function
@@ -2314,7 +2332,7 @@ class Project(object):
2314 if clone_filter: 2332 if clone_filter:
2315 git_require((2, 19, 0), fail=True, msg='partial clones') 2333 git_require((2, 19, 0), fail=True, msg='partial clones')
2316 cmd.append('--filter=%s' % clone_filter) 2334 cmd.append('--filter=%s' % clone_filter)
2317 self.config.SetString('extensions.partialclone', self.remote.name) 2335 self.EnableRepositoryExtension('partialclone', self.remote.name)
2318 2336
2319 if depth: 2337 if depth:
2320 cmd.append('--depth=%s' % depth) 2338 cmd.append('--depth=%s' % depth)
@@ -2630,7 +2648,7 @@ class Project(object):
2630 # Enable per-worktree config file support if possible. This is more a 2648 # Enable per-worktree config file support if possible. This is more a
2631 # nice-to-have feature for users rather than a hard requirement. 2649 # nice-to-have feature for users rather than a hard requirement.
2632 if self.use_git_worktrees and git_require((2, 19, 0)): 2650 if self.use_git_worktrees and git_require((2, 19, 0)):
2633 self.config.SetString('extensions.worktreeConfig', 'true') 2651 self.EnableRepositoryExtension('worktreeConfig')
2634 2652
2635 # If we have a separate directory to hold refs, initialize it as well. 2653 # If we have a separate directory to hold refs, initialize it as well.
2636 if self.objdir != self.gitdir: 2654 if self.objdir != self.gitdir:
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 49867a97..eada76a7 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -576,8 +576,7 @@ later is required to fix a server side protocol bug.
576 print('%s: Shared project %s found, disabling pruning.' % 576 print('%s: Shared project %s found, disabling pruning.' %
577 (project.relpath, project.name)) 577 (project.relpath, project.name))
578 if git_require((2, 7, 0)): 578 if git_require((2, 7, 0)):
579 project.config.SetString('core.repositoryFormatVersion', '1') 579 project.EnableRepositoryExtension('preciousObjects')
580 project.config.SetString('extensions.preciousObjects', 'true')
581 else: 580 else:
582 # This isn't perfect, but it's the best we can do with old git. 581 # This isn't perfect, but it's the best we can do with old git.
583 print('%s: WARNING: shared projects are unreliable when using old ' 582 print('%s: WARNING: shared projects are unreliable when using old '