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')