Skip to content

Commit eb9dafd

Browse files
genednaclaude
andcommitted
v0.40.4: canonicalize legacy ImportRepo alias paths (FU-15, #26, #27)
- Migration m20260923_000200_canonicalize_import_repo_paths rewrites every git_repo row whose repo_path is not canonical (pre-TP-08 double or trailing slashes, `.` segments) to the canonical path, keeping repo_id. Rows are judged on their own path, independent of monorepo.import_dir. - One transaction; LOCK TABLE git_repo IN SHARE ROW EXCLUSIVE MODE before the scan so a concurrent insert is either seen or waits. - A canonical path already taken by another row (split identity) leaves the alias untouched; uncanonicalizable paths are left too. Both are counted, with WARNs carrying only repo_id (and the canonical path); startup logs one summary line. - docs/deploy-trunk.md 9.2: the migration, the counts, and handling of collisions and invalid rows (DEFER-FU-10). - Plan: ADR-FU-10 item 3 child check excludes rows whose canonical form equals the target; FU-16/FU-17 carry the test obligation. Plan: docs/plan/plan-20260923.md (FU-15). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Eli Ma <eli@patch.sh>
1 parent 3f9553a commit eb9dafd

7 files changed

Lines changed: 690 additions & 15 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mega2"
3-
version = "0.40.3"
3+
version = "0.40.4"
44
edition = "2024"
55
# Two [[bin]] targets exist; keep `cargo run -p mega2` unambiguous.
66
default-run = "mega2"

‎docs/deploy-trunk.md‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,52 @@ git -c transfer.fsckObjects=true -c fetch.fsck.skipList="$PWD/mega2-fsck-skiplis
275275

276276
本地 `git fsck` 同样可加 `-c fsck.skipList=<同一文件>`。skip list 只豁免列出的对象,其余对象仍按严格规则校验。
277277

278+
### 9.2 升级时的 ImportRepo 别名路径规范化
279+
280+
升级到 `0.40.4` 后的首次启动执行一次迁移 `m20260923_000200_canonicalize_import_repo_paths`:`git_repo` 中 `repo_path` 不是规范形式的行,即 TP-08 之前写入的旧别名(重复斜杠、尾斜杠、`.` 段,例如 `/third-party//foo/`),改写为规范路径(`/third-party/foo`),`repo_id` 及其 ref 与对象行不变。迁移按行本身判定,与 `monorepo.import_dir` 无关,非默认的 import 根同样覆盖;整个改写在一个事务内完成,重复执行无变化,无需配置。协议层的 TP-08 规范化保持不变,旧别名 URL 仍命中同一仓库(回归用例 `import_repo_alias_*`,[`plan-20260923.md`](plan/plan-20260923.md) FU-15)。
281+
282+
启动日志输出一行汇总:
283+
284+
```text
285+
canonicalized ImportRepo alias paths rewritten=<N> collisions=<M> invalid=<K>
286+
```
287+
288+
| 计数 | 含义 |
289+
|---|---|
290+
| `rewritten` | 已改写为规范路径的别名行数。 |
291+
| `collisions` | 规范路径已被另一行占用而保留原样的别名行数:同一仓库已分裂为两个 `repo_id`。每行另有一条 WARN,只含 `repo_id` 与规范路径。 |
292+
| `invalid` | 路径无法规范化(例如含 `..` 段或 `\`)而保留原样的行数,每行另有一条 WARN,只含 `repo_id`。 |
293+
294+
两个计数都为 0 时无需任何操作。
295+
296+
`collisions` 不为 0 时,同一仓库已分裂为两个 `repo_id`(升级前即已如此,迁移不改变它):
297+
298+
- Git 请求(clone / fetch / push)一律按规范路径解析,命中占用规范路径的那一行;
299+
- Web / API 按路径前缀查找仓库时取最长的已存路径:别名以 `/` 或 `/.` 结尾时,规范路径之下的文件、tag、commit 的查询与写入仍落到别名那一行;
300+
- 后续版本的 ImportRepo 清理按规范路径精确查找仓库:不删除这类别名行,也不把它们算作子仓(计划 ADR-FU-10 第 3 条、`DEFER-FU-10`)。
301+
302+
处理步骤:
303+
304+
1. 用 WARN 中的 `repo_id` 与规范路径对照两行及其 ref:
305+
306+
```sql
307+
SELECT id, repo_path, created_at, updated_at FROM git_repo
308+
WHERE id = <WARN 中的 repo_id> OR repo_path = '<WARN 中的规范路径>';
309+
SELECT repo_id, ref_name, ref_git_id FROM import_refs
310+
WHERE repo_id IN (<两个 id>) ORDER BY ref_name, repo_id;
311+
```
312+
313+
2. 不要手工改写或删除两行中的任何一行:自动合并尚未提供(计划 `DEFER-FU-10`),请附上述查询结果提交 issue。别名行的数据不会被迁移删除。
314+
315+
`invalid` 不为 0 时,计入的行没有规范形式,因此也没有对应的规范行:协议层对这类路径的请求一律拒绝(TP-08 规范化失败),升级前后都不被服务,迁移不改动它们。按 WARN 中的 `repo_id` 查看:
316+
317+
```sql
318+
SELECT id, repo_path, created_at, updated_at FROM git_repo WHERE id = <WARN 中的 repo_id>;
319+
SELECT ref_name, ref_git_id FROM import_refs WHERE repo_id = <同一 id> ORDER BY ref_name;
320+
```
321+
322+
需要其中的内容时同样不要手工改写该行,请附查询结果提交 issue。
323+
278324
## 10. storage-only OCI Distribution(`/v2`)
279325

280326
架构与端点事实源:[`refactoring/oci.md`](./refactoring/oci.md)(plan-20260902)。本节只覆盖运维启用与 `docker login` 认证语义。

0 commit comments

Comments
 (0)