mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
[git_cache] support ssh url
Paths containing ':' characters are illegal only on Windows platforms. So, ssh_url like git@github.com:chromium/chromium.git will generate runtime exception on Windows. We replace ':' with '__' to avoid exceptions in the ssh form of git_url case. R=ddoman@chromium.org Bug: 329781388 Change-Id: Ia4db6a0927b40b521477e5d90addb4056c2c8ef8 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5369296 Auto-Submit: 吴金立 <wujinli.cn@gmail.com> Reviewed-by: Aravind Vasudevan <aravindvasudev@google.com> Commit-Queue: Joanna Wang <jojwang@chromium.org>
This commit is contained in:
@@ -176,6 +176,8 @@ class Mirror(object):
|
||||
# Use the same dir for authenticated URLs and unauthenticated URLs.
|
||||
norm_url = norm_url.replace('googlesource.com/a/', 'googlesource.com/')
|
||||
|
||||
norm_url = norm_url.replace(':', '__')
|
||||
|
||||
return norm_url.replace('-', '--').replace('/', '-').lower()
|
||||
|
||||
@staticmethod
|
||||
@@ -183,6 +185,12 @@ class Mirror(object):
|
||||
"""Convert a cache dir path to its corresponding url."""
|
||||
netpath = re.sub(r'\b-\b', '/',
|
||||
os.path.basename(path)).replace('--', '-')
|
||||
|
||||
netpath = netpath.replace('__', ':')
|
||||
|
||||
if netpath.startswith('git@'):
|
||||
return netpath
|
||||
|
||||
return 'https://%s' % netpath
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -309,6 +309,14 @@ class MirrorTest(unittest.TestCase):
|
||||
'https://chromium.googlesource.com/a/chromium/src.git'),
|
||||
'chromium.googlesource.com-chromium-src')
|
||||
|
||||
def test_ssh_url_in_UrlToCacheDir_and_CacheDirToUrl(self):
|
||||
ssh_url = "git@github.com:chromium/chromium.git"
|
||||
self.assertEqual(git_cache.Mirror.UrlToCacheDir(ssh_url),
|
||||
"git@github.com__chromium-chromium")
|
||||
self.assertEqual(
|
||||
git_cache.Mirror.CacheDirToUrl(
|
||||
git_cache.Mirror.UrlToCacheDir(ssh_url)), ssh_url[:-4])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.basicConfig(
|
||||
|
||||
Reference in New Issue
Block a user