Commit c3eb3fa3 authored by Ryan Tseng's avatar Ryan Tseng Committed by Commit Bot

git_cache: Remove locks

These aren't in use, and the original problem they were
meant to solve has been solved at the gclient.py layer 
using resource locking:
  https://codereview.chromium.org/2049583003

Bug: 773008
Change-Id: I6609f39d7f15604e0bb3d742a41c4f9fec87a57a
Reviewed-on: https://chromium-review.googlesource.com/707728Reviewed-by: 's avatarAaron Gable <agable@chromium.org>
Reviewed-by: 's avatarRobbie Iannucci <iannucci@chromium.org>
Commit-Queue: Ryan Tseng <hinoka@chromium.org>
parent 27db3f2c
......@@ -1308,10 +1308,6 @@ it or fix the checkout.
if cache_dir:
cache_dir = os.path.join(self.root_dir, cache_dir)
cache_dir = os.path.abspath(cache_dir)
# If running on a bot, force break any stale git cache locks.
if os.path.exists(cache_dir) and os.environ.get('CHROME_HEADLESS'):
subprocess2.check_call(['git', 'cache', 'unlock', '--cache-dir',
cache_dir, '--force', '--all'])
gclient_scm.GitWrapper.cache_dir = cache_dir
git_cache.Mirror.SetCachePath(cache_dir)
......@@ -2354,16 +2350,11 @@ def CMDsync(parser, args):
parser.add_option('--no_bootstrap', '--no-bootstrap',
action='store_true',
help='Don\'t bootstrap from Google Storage.')
parser.add_option('--ignore_locks', action='store_true',
help='GIT ONLY - Ignore cache locks.')
parser.add_option('--break_repo_locks', action='store_true',
help='GIT ONLY - Forcibly remove repo locks (e.g. '
'index.lock). This should only be used if you know for '
'certain that this invocation of gclient is the only '
'thing operating on the git repos (e.g. on a bot).')
parser.add_option('--lock_timeout', type='int', default=5000,
help='GIT ONLY - Deadline (in seconds) to wait for git '
'cache lock to become available. Default is %default.')
# TODO(agable): Remove these when the oldest CrOS release milestone is M56.
parser.add_option('-t', '--transitive', action='store_true',
help='DEPRECATED: This is a no-op.')
......
......@@ -855,10 +855,7 @@ class GitWrapper(SCMWrapper):
depth = None
mirror.populate(verbose=options.verbose,
bootstrap=not getattr(options, 'no_bootstrap', False),
depth=depth,
ignore_lock=getattr(options, 'ignore_locks', False),
lock_timeout=getattr(options, 'lock_timeout', 0))
mirror.unlock()
depth=depth)
def _Clone(self, revision, url, options):
"""Clone a git repository from the given URL.
......
This diff is collapsed.
......@@ -331,7 +331,7 @@ def gclient_sync(
os.close(fd)
args = ['sync', '--verbose', '--reset', '--force',
'--ignore_locks', '--output-json', gclient_output_file,
'--output-json', gclient_output_file,
'--nohooks', '--noprehooks', '--delete_unversioned_trees']
if with_branch_heads:
args += ['--with_branch_heads']
......@@ -470,36 +470,9 @@ def is_broken_repo_dir(repo_dir):
return not path.exists(os.path.join(repo_dir, '.git', 'config'))
def _maybe_break_locks(checkout_path):
"""This removes all .lock files from this repo's .git directory.
In particular, this will cleanup index.lock files, as well as ref lock
files.
"""
git_dir = os.path.join(checkout_path, '.git')
for dirpath, _, filenames in os.walk(git_dir):
for filename in filenames:
if filename.endswith('.lock'):
to_break = os.path.join(dirpath, filename)
print 'breaking lock: %s' % to_break
try:
os.remove(to_break)
except OSError as ex:
print 'FAILED to break lock: %s: %s' % (to_break, ex)
raise
def git_checkout(solutions, revisions, shallow, refs, git_cache_dir,
cleanup_dir):
build_dir = os.getcwd()
# Before we do anything, break all git_cache locks.
if path.isdir(git_cache_dir):
git('cache', 'unlock', '-vv', '--force', '--all',
'--cache-dir', git_cache_dir)
for item in os.listdir(git_cache_dir):
filename = os.path.join(git_cache_dir, item)
if item.endswith('.lock'):
raise Exception('%s exists after cache unlock' % filename)
first_solution = True
for sln in solutions:
# Just in case we're hitting a different git server than the one from
......@@ -516,7 +489,7 @@ def git_checkout(solutions, revisions, shallow, refs, git_cache_dir,
shallow = False
sln_dir = path.join(build_dir, name)
s = ['--shallow'] if shallow else []
populate_cmd = (['cache', 'populate', '--ignore_locks', '-v',
populate_cmd = (['cache', 'populate', '-v',
'--cache-dir', git_cache_dir] + s + [url])
for ref in refs:
populate_cmd.extend(['--ref', ref])
......@@ -544,18 +517,6 @@ def git_checkout(solutions, revisions, shallow, refs, git_cache_dir,
refspec = '%s:%s' % (ref, ref.lstrip('+'))
git('fetch', 'origin', refspec, cwd=sln_dir)
# Windows sometimes has trouble deleting files.
# This can make git commands that rely on locks fail.
# Try a few times in case Windows has trouble again (and again).
if sys.platform.startswith('win'):
tries = 3
while tries:
try:
_maybe_break_locks(sln_dir)
break
except Exception:
tries -= 1
revision = get_target_revision(name, url, revisions) or 'HEAD'
force_revision(sln_dir, revision)
done = True
......
......@@ -231,20 +231,6 @@ class BotUpdateUnittests(unittest.TestCase):
gclient_sync_cmd = args
self.assertTrue('--break_repo_locks' in gclient_sync_cmd)
def testGitCheckoutBreaksLocks(self):
self.overrideSetupForWindows()
path = '/b/build/slave/foo/build/.git'
lockfile = 'index.lock'
removed = []
old_os_walk = os.walk
old_os_remove = os.remove
setattr(os, 'walk', lambda _: [(path, None, [lockfile])])
setattr(os, 'remove', removed.append)
bot_update.ensure_checkout(**self.params)
setattr(os, 'walk', old_os_walk)
setattr(os, 'remove', old_os_remove)
self.assertTrue(os.path.join(path, lockfile) in removed)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment