in playground/tree-sitter/build.py [0:0]
def parse_git_source(dep_info: Dict) -> tuple[str, str]:
"""Parse git source information from dependency."""
source: str = dep_info["source"]
# An example git string: "git+https://github.com/danieltrt/tree-sitter-go.git?rev=ea5ceb716012db8813a2c05fab23c3a020988724#ea5ceb716012db8813a2c05fab23c3a020988724"
# So we first remove the "git+" prefix and remove the "#" part if it exists.
source = source.removeprefix("git+").split("#")[0].strip()
if "?" not in source:
raise ValueError(f"Expecting ? in git source string: {source}")
git_url, query_string = source.split("?", 1)
params = urllib.parse.parse_qs(query_string)
rev = (
params.get("rev", [None])[0]
or params.get("branch", [None])[0]
or params.get("tag", [None])[0]
)
if not rev:
raise ValueError(f"Missing rev/branch/tag information in git source: {source}")
return git_url, rev