From db58954c8cb36dd41e245a982f978a1f19b16af6 Mon Sep 17 00:00:00 2001 From: Dirk Pranke Date: Fri, 12 Apr 2019 21:07:01 +0000 Subject: [PATCH] Use the same git-cache bucket for authenticated and unauthenticated repos. We should only be maintaining one cache bundle per repo, but it turns out that we've had two in the past due to GoB supporting two different paths to the repo, and users were getting stale bundles as a result. This CL fixes things so that we should only get a single bundle per repo. Bug: 935084 Change-Id: I0d6713280a2abbc20e35ff87e7be115870dd5140 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1566431 Reviewed-by: Andrii Shyshkalov Commit-Queue: Dirk Pranke --- git_cache.py | 4 ++++ tests/git_cache_test.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/git_cache.py b/git_cache.py index f17f466da..4e67767dc 100755 --- a/git_cache.py +++ b/git_cache.py @@ -264,6 +264,10 @@ class Mirror(object): norm_url = parsed.netloc + parsed.path if norm_url.endswith('.git'): norm_url = norm_url[:-len('.git')] + + # Use the same dir for authenticated URLs and unauthenticated URLs. + norm_url = norm_url.replace('googlesource.com/a/', 'googlesource.com/') + return norm_url.replace('-', '--').replace('/', '-').lower() @staticmethod diff --git a/tests/git_cache_test.py b/tests/git_cache_test.py index a09214597..afa2b4612 100755 --- a/tests/git_cache_test.py +++ b/tests/git_cache_test.py @@ -166,6 +166,18 @@ class GitCacheDirTest(unittest.TestCase): os.environ[name] = val +class MirrorTest(unittest.TestCase): + def test_same_cache_for_authenticated_and_unauthenticated_urls(self): + # GoB can fetch a repo via two different URLs; if the url contains '/a/' + # it forces authenticated access instead of allowing anonymous access, + # even in the case where a repo is public. We want this in order to make + # sure bots are authenticated and get the right quotas. However, we + # only want to maintain a single cache for the repo. + self.assertEqual(git_cache.Mirror.UrlToCacheDir( + 'https://chromium.googlesource.com/a/chromium/src.git'), + 'chromium.googlesource.com-chromium-src') + + if __name__ == '__main__': sys.exit(coverage_utils.covered_main(( os.path.join(DEPOT_TOOLS_ROOT, 'git_cache.py')