Skip to content

Commit 3a9e570

Browse files
committed
Shorten external git repos
1 parent 27c0f78 commit 3a9e570

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

rs/extensions.bzl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,15 @@ def _spoke_repo(hub_name, name, version):
3434
s = s.replace("+", "-")
3535
return s
3636

37+
def _git_repo_remote_name(remote):
38+
scheme_separator = remote.find("://")
39+
if scheme_separator != -1:
40+
remote = remote[scheme_separator + len("://"):]
41+
42+
return remote.replace("/", "_").replace(":", "_").replace("@", "_")
43+
3744
def _external_repo_for_git_source(hub_name, remote, commit):
38-
return hub_name + "__" + remote.replace("/", "_").replace(":", "_").replace("@", "_") + "_" + commit
45+
return hub_name + "__" + _git_repo_remote_name(remote) + "_" + commit[:8]
3946

4047
def _git_crate_purl(name, version, remote, commit):
4148
return "pkg:cargo/%s@%s?vcs_url=git+%s@%s" % (name, version, remote, commit)
@@ -883,6 +890,14 @@ def _crate_impl(mctx):
883890
"workspace_cargo_toml": annotation.workspace_cargo_toml,
884891
}
885892
git_repos[repo_name] = git_repo
893+
elif git_repo["remote"] != remote or git_repo["commit"] != commit:
894+
fail("Git crates from %s at %s and %s at %s produce the same repository name %s" % (
895+
git_repo["remote"],
896+
git_repo["commit"],
897+
remote,
898+
commit,
899+
repo_name,
900+
))
886901

887902
strip_prefix = package.get("strip_prefix")
888903
if strip_prefix == None:

0 commit comments

Comments
 (0)