Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(876)

Unified Diff: git_cache.py

Issue 240203005: Implement git-drover. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: address feedback Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « git-drover ('k') | git_common.py » ('j') | git_drover.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_cache.py
diff --git a/git_cache.py b/git_cache.py
index 52e42c59274781f580491428b67afa4d6bf66280..9b7082ba9b660b0f8ec7d153d12ae02fea017277 100755
--- a/git_cache.py
+++ b/git_cache.py
@@ -28,6 +28,7 @@ except NameError:
class WinErr(Exception):
pass
+
class LockError(Exception):
pass
@@ -151,6 +152,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."""
@@ -222,7 +247,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."""
python_fallback = False
@@ -248,8 +273,10 @@ class Mirror(object):
# 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:
+ 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
@@ -287,7 +314,7 @@ class Mirror(object):
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=()):
if shallow and not depth:
depth = 10000
gclient_utils.safe_makedirs(self.GetCachePath())
@@ -308,7 +335,8 @@ class Mirror(object):
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:
@@ -320,7 +348,7 @@ class Mirror(object):
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:
« no previous file with comments | « git-drover ('k') | git_common.py » ('j') | git_drover.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698