Chromium Code Reviews| Index: git_cache.py |
| diff --git a/git_cache.py b/git_cache.py |
| index 88c55e611dbb9f2fbd5d997a649f76edde7facd8..39edad90beddb59d1afe8bd780f8c9fac3656f9d 100755 |
| --- a/git_cache.py |
| +++ b/git_cache.py |
| @@ -26,6 +26,7 @@ except NameError: |
| class WinErr(Exception): |
| pass |
| + |
| class LockError(Exception): |
| pass |
| @@ -135,6 +136,30 @@ class Mirror(object): |
| self.mirror_path = os.path.join(self.GetCachePath(), self.basedir) |
| self.print = print_func or print |
| + @classmethod |
| + def from_repo(cls, path=None): |
| + """Returns Mirror if path is in a cached repo, else None.""" |
| + args = ['-C', path] if path else [] |
| + args = [cls.git_exe] + args + ['rev-parse', '--git-dir'] |
| + git_path = subprocess.check_output(args).strip() |
| + alt_path = os.path.join(git_path, 'objects', 'info', 'alternates') |
| + |
| + if os.path.exists(alt_path): |
| + with open(alt_path, 'rb') as alt: |
| + mirror_path = alt.read().strip() |
| + mirror_path = os.path.dirname(mirror_path) |
| + cache_path = os.path.dirname(mirror_path) |
| + if os.path.exists(mirror_path): |
| + url = subprocess.check_output( |
| + [cls.git_exe, '-C', mirror_path, 'config', 'remote.origin.url'] |
| + ).strip() |
| + |
| + # TODO(iannucci): cache_path should NOT be a class attribute. Maybe |
| + # a `default_cache_path`, but not the actual path. |
| + cls.SetCachePath(cache_path) |
| + |
| + return cls(url) |
| + |
| @staticmethod |
| def UrlToCacheDir(url): |
| """Convert a git url to a normalized form for the cache dir path.""" |
| @@ -206,7 +231,7 @@ class Mirror(object): |
| refspec = '+refs/%s/*:refs/%s/*' % (ref, ref) |
| self.RunGit(['config', '--add', 'remote.origin.fetch', refspec], cwd=cwd) |
| - def bootstrap_repo(self, directory): |
| + def bootstrap_repo(self, directory, verbose): |
| """Bootstrap the repo from Google Stroage if possible. |
| Requires 7z on Windows and Unzip on Linux/Mac. |
| @@ -242,8 +267,10 @@ from Google Storage, please ensure unzip is present on your system. |
| # Download zip file to a temporary directory. |
| try: |
| tempdir = tempfile.mkdtemp() |
| - self.print('Downloading %s' % latest_checkout) |
| - code, out, err = gsutil.check_call('cp', latest_checkout, tempdir) |
| + if not verbose: |
|
agable
2014/04/18 00:17:08
print if *not* verbose??
iannucci
2014/04/28 21:05:28
Yeah, otherwise this doubles up with the gsutil ou
|
| + self.print('Downloading %s' % latest_checkout) |
| + code, out, err = gsutil.check_call('cp', latest_checkout, tempdir, |
| + verbose=verbose) |
| if code: |
| self.print('%s\n%s' % (out, err)) |
| return False |
| @@ -270,7 +297,7 @@ from Google Storage, please ensure unzip is present on your system. |
| return os.path.isfile(os.path.join(self.mirror_path, 'config')) |
| def populate(self, depth=None, shallow=False, bootstrap=False, |
| - verbose=False): |
| + verbose=False, fetch_specs=()): |
|
agable
2014/04/18 00:17:08
None
iannucci
2014/04/28 21:05:28
Er... why? it's iterable and immutable... that's s
|
| if shallow and not depth: |
| depth = 10000 |
| gclient_utils.safe_makedirs(self.GetCachePath()) |
| @@ -291,7 +318,8 @@ from Google Storage, please ensure unzip is present on your system. |
| gclient_utils.rmtree(self.mirror_path) |
| tempdir = tempfile.mkdtemp( |
| suffix=self.basedir, dir=self.GetCachePath()) |
| - bootstrapped = not depth and bootstrap and self.bootstrap_repo(tempdir) |
| + bootstrapped = (not depth and bootstrap and |
| + self.bootstrap_repo(tempdir, verbose)) |
| if not bootstrapped: |
| self.RunGit(['init', '--bare'], cwd=tempdir) |
| else: |
| @@ -303,7 +331,7 @@ from Google Storage, please ensure unzip is present on your system. |
| rundir = tempdir or self.mirror_path |
| self.config(rundir) |
| fetch_cmd = ['fetch'] + v + d + ['origin'] |
| - fetch_specs = subprocess.check_output( |
| + fetch_specs = fetch_specs or subprocess.check_output( |
| [self.git_exe, 'config', '--get-all', 'remote.origin.fetch'], |
| cwd=rundir).strip().splitlines() |
| for spec in fetch_specs: |