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

Side by Side Diff: git_cache.py

Issue 187283005: Be more aggressive about breaking locks (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 6 years, 9 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
« 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 import errno 8 import errno
9 import logging 9 import logging
10 import optparse 10 import optparse
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 if len(args) > 1 or (len(args) == 0 and not options.all): 236 if len(args) > 1 or (len(args) == 0 and not options.all):
237 parser.error('git cache unlock takes exactly one repo url, or --all') 237 parser.error('git cache unlock takes exactly one repo url, or --all')
238 238
239 if not options.all: 239 if not options.all:
240 url = args[0] 240 url = args[0]
241 repo_dirs = [os.path.join(options.cache_dir, UrlToCacheDir(url))] 241 repo_dirs = [os.path.join(options.cache_dir, UrlToCacheDir(url))]
242 else: 242 else:
243 repo_dirs = [os.path.join(options.cache_dir, path) 243 repo_dirs = [os.path.join(options.cache_dir, path)
244 for path in os.listdir(options.cache_dir) 244 for path in os.listdir(options.cache_dir)
245 if os.path.isdir(os.path.join(options.cache_dir, path))] 245 if os.path.isdir(os.path.join(options.cache_dir, path))]
246 repo_dirs.extend([os.path.join(options.cache_dir,
247 lockfile.replace('.lock', ''))
248 for lockfile in os.listdir(options.cache_dir)
249 if os.path.isfile(os.path.join(options.cache_dir,
250 lockfile))
251 and lockfile.endswith('.lock')
252 and os.path.join(options.cache_dir, lockfile)
253 not in repo_dirs])
246 lockfiles = [repo_dir + '.lock' for repo_dir in repo_dirs 254 lockfiles = [repo_dir + '.lock' for repo_dir in repo_dirs
247 if os.path.exists(repo_dir + '.lock')] 255 if os.path.exists(repo_dir + '.lock')]
248 256
249 if not options.force: 257 if not options.force:
250 parser.error('git cache unlock requires -f|--force to do anything. ' 258 parser.error('git cache unlock requires -f|--force to do anything. '
251 'Refusing to unlock the following repo caches: ' 259 'Refusing to unlock the following repo caches: '
252 ', '.join(lockfiles)) 260 ', '.join(lockfiles))
253 261
254 unlocked = [] 262 unlocked = []
255 untouched = [] 263 untouched = []
256 for repo_dir in repo_dirs: 264 for repo_dir in repo_dirs:
257 lf = Lockfile(repo_dir) 265 lf = Lockfile(repo_dir)
266 config_lock = os.path.join(repo_dir, 'config.lock')
267 unlocked = False
268 if os.path.exists(config_lock):
269 os.remove(config_lock)
270 unlocked = True
258 if lf.break_lock(): 271 if lf.break_lock():
259 config_lock = os.path.join(repo_dir, 'config.lock') 272 unlocked = True
260 if os.path.exists(config_lock): 273
261 os.remove(config_lock) 274 if unlocked:
262 unlocked.append(repo_dir) 275 unlocked.append(repo_dir)
263 else: 276 else:
264 untouched.append(repo_dir) 277 untouched.append(repo_dir)
265 278
266 if unlocked: 279 if unlocked:
267 logging.info('Broke locks on these caches: %s' % unlocked) 280 logging.info('Broke locks on these caches: %s' % unlocked)
268 if untouched: 281 if untouched:
269 logging.debug('Did not touch these caches: %s' % untouched) 282 logging.debug('Did not touch these caches: %s' % untouched)
270 283
271 284
272 class OptionParser(optparse.OptionParser): 285 class OptionParser(optparse.OptionParser):
(...skipping 28 matching lines...) Expand all
301 return options, args 314 return options, args
302 315
303 316
304 def main(argv): 317 def main(argv):
305 dispatcher = subcommand.CommandDispatcher(__name__) 318 dispatcher = subcommand.CommandDispatcher(__name__)
306 return dispatcher.execute(OptionParser(), argv) 319 return dispatcher.execute(OptionParser(), argv)
307 320
308 321
309 if __name__ == '__main__': 322 if __name__ == '__main__':
310 sys.exit(main(sys.argv[1:])) 323 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