Chromium Code Reviews| Index: gclient_scm.py |
| diff --git a/gclient_scm.py b/gclient_scm.py |
| index 3a9e90ed6d55c5558464ddd0720f5eac12effab5..f18e360671847a6097708cf87c77652e0adc8803 100644 |
| --- a/gclient_scm.py |
| +++ b/gclient_scm.py |
| @@ -398,6 +398,19 @@ class GitWrapper(SCMWrapper): |
| # Switch over to the new upstream |
| self._Run(['remote', 'set-url', 'origin', url], options) |
| self._FetchAndReset(revision, file_list, options) |
| + |
| + # If we switched from a cached git repo to an uncached one or vice versa, |
| + # set up the objects link and pack appropriately. |
| + altfile = os.path.join( |
| + self.checkout_path, '.git', 'objects', 'info', 'alternates') |
| + if self.cache_dir: |
| + with open(altfile, 'wa') as f: |
| + f.write(os.path.join(url, 'objects')) |
| + self._Run(['repack', '-ad'], options) |
| + self._Run(['repack', '-adl'], options) |
| + elif os.path.exists(altfile): |
| + self._Run(['repack', '-a'], options) |
| + os.remove(altfile) |
|
iannucci
2013/07/12 23:32:10
Actually, we should do this in the non-switch case
|
| return |
| if not self._IsValidGitRepo(): |
| @@ -753,19 +766,32 @@ class GitWrapper(SCMWrapper): |
| filter_fn = lambda l: '[up to date]' not in l |
| with self.cache_locks[folder]: |
| gclient_utils.safe_makedirs(self.cache_dir) |
| + do_fetch = True |
| if not os.path.exists(os.path.join(folder, 'config')): |
| + do_fetch = False |
| gclient_utils.rmtree(folder) |
| - self._Run(['clone'] + v + ['-c', 'core.deltaBaseCacheLimit=2g', |
| - '--progress', '--mirror', url, folder], |
| + cmd = ['clone'] + v + ['-c', 'core.deltaBaseCacheLimit=2g', |
| + '--progress', '--mirror'] |
| + if os.path.exists(self.checkout_path): |
| + cmd += ['--reference', os.path.abspath(self.checkout_path)] |
| + self._Run(cmd + [url, folder], |
| options, git_filter=True, filter_fn=filter_fn, |
| cwd=self.cache_dir) |
| - else: |
| + |
| + # If the clone has an object dependency on the existing repo, break it |
| + # with repack and remove the linkage. |
| + cache_alt_file = os.path.join(folder, 'objects', 'info', 'alternates') |
| + if os.path.exists(cache_alt_file): |
| + self._Run(['repack', '-a'], options, cwd=folder) |
| + os.remove(cache_alt_file) |
| + |
| + if do_fetch: |
| # For now, assert that host/path/to/repo.git is identical. We may want |
| # to relax this restriction in the future to allow for smarter cache |
| # repo update schemes (such as pulling the same repo, but from a |
| # different host). |
| existing_url = self._Capture(['config', 'remote.origin.url'], |
| - cwd=folder) |
| + cwd=folder) |
| assert self._NormalizeGitURL(existing_url) == self._NormalizeGitURL(url) |
| # Would normally use `git remote update`, but it doesn't support |