Clone or update a repository at the config's pinned ``commit`` SHA. Full clones (no ``--depth``) are required: the pinned ``test_commits`` are often older than any reasonable shallow-clone window, and a missed SHA used to silently fall back to ``git diff HEAD~1 HEAD`` — producing be
(config: dict, repos_dir: Path | None = None)
| 64 | |
| 65 | |
| 66 | def clone_or_update(config: dict, repos_dir: Path | None = None) -> Path: |
| 67 | """Clone or update a repository at the config's pinned ``commit`` SHA. |
| 68 | |
| 69 | Full clones (no ``--depth``) are required: the pinned ``test_commits`` are |
| 70 | often older than any reasonable shallow-clone window, and a missed SHA |
| 71 | used to silently fall back to ``git diff HEAD~1 HEAD`` — producing |
| 72 | benchmark numbers tied to whatever upstream HEAD looked like that day. |
| 73 | |
| 74 | Every subprocess call's exit status is checked; failures raise |
| 75 | ``RuntimeError`` so reproducibility issues surface immediately instead of |
| 76 | yielding garbage results. |
| 77 | """ |
| 78 | repos_dir = repos_dir or DEFAULT_REPOS |
| 79 | repos_dir.mkdir(parents=True, exist_ok=True) |
| 80 | repo_path = repos_dir / config["name"] |
| 81 | |
| 82 | if repo_path.exists(): |
| 83 | proc = subprocess.run( |
| 84 | ["git", "fetch", "--all", "--tags"], |
| 85 | cwd=str(repo_path), |
| 86 | capture_output=True, |
| 87 | text=True, |
| 88 | ) |
| 89 | if proc.returncode != 0: |
| 90 | raise RuntimeError( |
| 91 | f"git fetch failed in {repo_path}: {proc.stderr.strip()}" |
| 92 | ) |
| 93 | else: |
| 94 | proc = subprocess.run( |
| 95 | ["git", "clone", config["url"], str(repo_path)], |
| 96 | capture_output=True, |
| 97 | text=True, |
| 98 | ) |
| 99 | if proc.returncode != 0: |
| 100 | raise RuntimeError( |
| 101 | f"git clone failed for {config['url']}: {proc.stderr.strip()}" |
| 102 | ) |
| 103 | |
| 104 | commit = config.get("commit", "HEAD") |
| 105 | if commit != "HEAD": |
| 106 | proc = subprocess.run( |
| 107 | ["git", "checkout", commit], |
| 108 | cwd=str(repo_path), |
| 109 | capture_output=True, |
| 110 | text=True, |
| 111 | ) |
| 112 | if proc.returncode != 0: |
| 113 | raise RuntimeError( |
| 114 | f"git checkout {commit} failed in {repo_path}: " |
| 115 | f"{proc.stderr.strip()}" |
| 116 | ) |
| 117 | |
| 118 | return repo_path |
| 119 | |
| 120 | |
| 121 | def write_csv(results: list[dict], path: Path) -> None: |