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

Side by Side Diff: git_cache.py

Issue 352543003: Have git cache bootstrap repo if repo is corrupt (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """A git command for managing a local cache of git repositories.""" 6 """A git command for managing a local cache of git repositories."""
7 7
8 from __future__ import print_function 8 from __future__ import print_function
9 import errno 9 import errno
10 import logging 10 import logging
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 self.print( 303 self.print(
304 'Extracting bootstrap zipfile %s failed.\n' 304 'Extracting bootstrap zipfile %s failed.\n'
305 'Resuming normal operations.' % filename) 305 'Resuming normal operations.' % filename)
306 return False 306 return False
307 return True 307 return True
308 308
309 def exists(self): 309 def exists(self):
310 return os.path.isfile(os.path.join(self.mirror_path, 'config')) 310 return os.path.isfile(os.path.join(self.mirror_path, 'config'))
311 311
312 def populate(self, depth=None, shallow=False, bootstrap=False, 312 def populate(self, depth=None, shallow=False, bootstrap=False,
313 verbose=False, ignore_lock=False): 313 verbose=False, ignore_lock=False, recurse=False):
314 assert self.GetCachePath() 314 assert self.GetCachePath()
315 if shallow and not depth: 315 if shallow and not depth:
316 depth = 10000 316 depth = 10000
317 gclient_utils.safe_makedirs(self.GetCachePath()) 317 gclient_utils.safe_makedirs(self.GetCachePath())
318 318
319 v = [] 319 v = []
320 if verbose: 320 if verbose:
321 v = ['-v', '--progress'] 321 v = ['-v', '--progress']
322 322
323 d = [] 323 d = []
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 rundir = tempdir or self.mirror_path 367 rundir = tempdir or self.mirror_path
368 self.config(rundir) 368 self.config(rundir)
369 fetch_cmd = ['fetch'] + v + d + ['origin'] 369 fetch_cmd = ['fetch'] + v + d + ['origin']
370 fetch_specs = subprocess.check_output( 370 fetch_specs = subprocess.check_output(
371 [self.git_exe, 'config', '--get-all', 'remote.origin.fetch'], 371 [self.git_exe, 'config', '--get-all', 'remote.origin.fetch'],
372 cwd=rundir).strip().splitlines() 372 cwd=rundir).strip().splitlines()
373 for spec in fetch_specs: 373 for spec in fetch_specs:
374 try: 374 try:
375 self.RunGit(fetch_cmd + [spec], cwd=rundir, retry=True) 375 self.RunGit(fetch_cmd + [spec], cwd=rundir, retry=True)
376 except subprocess.CalledProcessError: 376 except subprocess.CalledProcessError:
377 if spec == '+refs/heads/*:refs/heads/*':
378 if not recurse:
379 # We definitely want to fail if the main refspec fails to fetch.
380 raise
381 # The cache is corrupt, bootstrap it.
agable 2014/06/24 00:49:37 What does recursion have to do with it? And nothin
Ryan Tseng 2014/06/24 01:02:10 Oops, that was supposed to default to recurse=True
382 os.remove(config_file)
383 self.populate(depth, shallow, True, verbose, ignore_lock, False)
377 logging.warn('Fetch of %s failed' % spec) 384 logging.warn('Fetch of %s failed' % spec)
378 if tempdir: 385 if tempdir:
379 os.rename(tempdir, self.mirror_path) 386 os.rename(tempdir, self.mirror_path)
380 finally: 387 finally:
381 if not ignore_lock: 388 if not ignore_lock:
382 lockfile.unlock() 389 lockfile.unlock()
383 390
384 def update_bootstrap(self, prune=False): 391 def update_bootstrap(self, prune=False):
385 # The files are named <git number>.zip 392 # The files are named <git number>.zip
386 gen_number = subprocess.check_output( 393 gen_number = subprocess.check_output(
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 return options, args 602 return options, args
596 603
597 604
598 def main(argv): 605 def main(argv):
599 dispatcher = subcommand.CommandDispatcher(__name__) 606 dispatcher = subcommand.CommandDispatcher(__name__)
600 return dispatcher.execute(OptionParser(), argv) 607 return dispatcher.execute(OptionParser(), argv)
601 608
602 609
603 if __name__ == '__main__': 610 if __name__ == '__main__':
604 sys.exit(main(sys.argv[1:])) 611 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698