Browse Source

[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>
Jinli Wu 1 year ago
parent
commit
89588ed8f2
2 changed files with 16 additions and 0 deletions
  1. 8 0
      git_cache.py
  2. 8 0
      tests/git_cache_test.py

+ 8 - 0
git_cache.py

@@ -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

+ 8 - 0
tests/git_cache_test.py

@@ -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(