Skip to content

Commit 7732b82

Browse files
committed
v0.42.19: HP-20 resolve view URLs for Git upload-pack
Signed-off-by: Eli Ma <eli@patch.sh>
1 parent 0c8d3c3 commit 7732b82

13 files changed

Lines changed: 1766 additions & 53 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.42.18"
3+
version = "0.42.19"
44
edition = "2024"
55
license = "MIT OR Apache-2.0"
66
description = "Monorepo engine and Git hosting server for AI agents: trunk-based storage, Git Smart HTTP, Git LFS, OCI registry, and Agent Session Capture"

‎docs/plan/plan-20261002.md‎

Lines changed: 19 additions & 18 deletions
Large diffs are not rendered by default.

‎docs/refactoring/protocol.md‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,11 @@ SSH 和 HTTP 最终共用 `SmartSession` 与 `src/ceres/protocol/smart.rs` 中
264264
- `transport_protocol`:`Http` 或 `Ssh`
265265
- `auth`
266266
- `capabilities`
267+
- `view`:`Option<ResolvedView>`,视图 URL 经第 3 层解析后为 `Some`,其余会话为 `None`;`new` / `from_state` 签名不变。
267268

268-
`repo_handler_with_commands` 会根据 repo path 选择 repo handler:
269+
`repo_handler_with_commands` 先看 `view`,再根据 repo path 选择 repo handler:
269270

271+
- 如果 `view` 为 `Some`,使用 `ViewRepo`:用解析时取得的配置快照构造,在读取 `state.storage.config()` 前返回,不看 repo path。
270272
- 如果 path 位于 `config.monorepo.import_dir` 下,使用 `ImportRepo`。
271273
- 否则使用 `Monorepo`。
272274

@@ -499,6 +501,12 @@ SSH `git-lfs-authenticate` 与 `git-lfs-transfer` 对视图路径写一行 `ERR
499501

500502
本卡 `integration_git_ssh` 中的原始 SSH 请求和 git 客户端沿用该 target 既有 storage-only 用例的宿主回环方式:宿主 `ssh` 和 git 经 `127.0.0.1` 连接。请求与应答字节不取决于执行位置;宿主 git 只断言 `not found`、`returned error: 403`、`remote error: view not found`、`remote error: view URLs are read-only` 四种稳定子串。此执行位置按[设计 §7.4 的 HP-18 例外](history-projection.md#74-测试计划)登记。
501503

504+
### 视图 URL 入口第 3 层(HP-20)
505+
506+
定位符通过认证后才解析;HTTP `git_info_refs` 在认证分支之后、v2 能力宣告短路之前解析,HTTP `git_upload_pack` 在 `check_upload_pack_access` 与读取请求体之间解析,SSH `exec_request` 在 `check_upload_pack_access` 之后、v2 短路之前解析。未认证请求不查视图表。具体顺序及应答见[设计 §6.1「入口分层」「认证先于解析」「逐请求解析」和「错误契约」](history-projection.md#61-url-与路由决策)。
507+
508+
HTTP 每个请求解析一次;SSH 每个 exec 解析一次,`ResolvedView` 随通道状态中的 `SmartSession` 保存。该 exec 内的各条协议命令各建一个 `ViewRepo`,共用 exec 时取得的配置快照。
509+
502510
### SSH upload-pack 可能把二进制 ACK/pack 数据当 UTF-8 发送
503511

504512
`handle_upload_pack` 当前:
@@ -654,6 +662,8 @@ SSH 中 `git-lfs-transfer` 返回明确 unsupported failure,`git-lfs-authentic
654662
655663
单元格取值只能是:`cargo:<exact_fn>`、`smoke:<case>`、`DEFER-GM-*`、或 `N/A+理由`。本表是唯一完整矩阵;`integration.md` 只保留 target 索引与回链。
656664

665+
同一格需要多个用例时,各取值以 `、` 分隔,每个取值仍须是上述形式之一。
666+
657667
| 用户命令 | HTTP | SSH | Auth | Repo-shape |
658668
|---|---|---|---|---|
659669
| ls-remote | smoke:HTTP_ls-remote | smoke:SSH_ls-remote | N/A+只读广告默认匿名 | N/A+Monorepo根路径;ImportRepo见DEFER-GM-01 |
@@ -675,7 +685,9 @@ SSH 中 `git-lfs-transfer` 返回明确 unsupported failure,`git-lfs-authentic
675685
| missing-repo 客户端失败 | DEFER-GM-05 | DEFER-GM-05 | N/A+空仓广告语义 | N/A+原DEFER-IT-12→DEFER-GM-05由GM-11B收口 |
676686
| 视图 receive-pack 拒绝 | cargo:integration_git_ssh_view_layer2_git_client_read_only | cargo:integration_git_ssh_view_layer2_ssh_read_only | cargo:layer2_receive_pack_forbidden_before_auth_and_body | N/A+视图前缀固定只读 |
677687
| 视图 LFS 404 | cargo:layer2_lfs_not_found | cargo:integration_git_ssh_view_layer2_ssh_lfs_rejected | cargo:layer2_lfs_not_found | N/A+视图前缀不进入 LFS 命名空间 |
678-
| 未知或已禁用的视图 | cargo:layer2_disabled_not_found | cargo:integration_git_ssh_view_layer2_ssh_not_found | cargo:layer2_disabled_not_found | cargo:layer2_enabled_unregistered_not_found |
688+
| 未知或已禁用的视图 | cargo:layer2_disabled_not_found、cargo:integration_git_cli_view_layer3_http_unknown | cargo:integration_git_ssh_view_layer2_ssh_not_found、cargo:integration_git_ssh_view_layer3_unknown | cargo:layer2_disabled_not_found、cargo:layer3_before_resolve_auth | cargo:layer2_enabled_unregistered_not_found |
689+
| 视图 ls-remote | cargo:integration_git_cli_view_layer3_http_ls_remote | cargo:integration_git_ssh_view_layer3_ls_remote | cargo:layer3_before_resolve_auth | N/A+视图只有 ViewRepo 一种形态 |
690+
| 未就绪的视图 | cargo:integration_git_cli_view_layer3_http_unready | cargo:integration_git_ssh_view_layer3_unready | cargo:layer3_before_resolve_auth | N/A+视图只有 ViewRepo 一种形态 |
679691

680692
#### GAP 映射(plan-20260803)
681693

‎src/ceres/protocol/mod.rs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ use crate::{
1616
api_service::state::ProtocolApiState,
1717
pack::{
1818
RepoHandler, import_repo::ImportRepo, monorepo::Monorepo,
19-
path_policy::check_import_repo_leaf, push_chain,
19+
path_policy::check_import_repo_leaf, push_chain, view_repo::ViewRepo,
2020
},
2121
},
2222
common::{
2323
errors::{MegaError, ProtocolError},
2424
utils::{canonicalize_mono_ref_path, is_full_hex_object_id, is_protocol_zero_id},
2525
},
26+
contract::git_protocol::ResolvedView,
2627
};
2728

2829
pub mod import_refs;
@@ -52,6 +53,7 @@ pub struct SmartSession {
5253
pub capabilities: HashSet<Capability>,
5354
/// Authoritative repository object hash kind (`MonoConfig.object_hash_kind()`).
5455
pub hash_kind: HashKind,
56+
pub(crate) view: Option<ResolvedView>,
5557
}
5658

5759
#[derive(Debug, PartialEq, Clone, Copy, Default)]
@@ -173,6 +175,7 @@ impl SmartSession {
173175
},
174176
capabilities: HashSet::new(),
175177
hash_kind: HashKind::Sha1,
178+
view: None,
176179
}
177180
}
178181

@@ -236,6 +239,15 @@ impl SmartSession {
236239
state: &ProtocolApiState,
237240
commands: Vec<RefCommand>,
238241
) -> Result<Arc<dyn RepoHandler>, ProtocolError> {
242+
if let Some(view) = &self.view {
243+
return Ok(Arc::new(ViewRepo::new(
244+
state.storage.clone(),
245+
view.config.clone(),
246+
state.storage.view_projection_service(),
247+
view.filter_pk,
248+
view.filter_id.clone(),
249+
)) as Arc<dyn RepoHandler>);
250+
}
239251
let config = state.storage.config();
240252
let import_dir = config.monorepo.import_dir.clone();
241253

‎src/contract/git_protocol/http.rs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::{
2121
config::PushAuth,
2222
contract::git_protocol::{
2323
InfoRefsParams, check_push_permission, check_upload_pack_access, lookup_push_token,
24-
receive_pack_requires_http_auth,
24+
path::ViewLocator, receive_pack_requires_http_auth, resolve_view_target,
2525
},
2626
};
2727

@@ -43,6 +43,7 @@ pub async fn git_info_refs(
4343
state: &ProtocolApiState,
4444
params: InfoRefsParams,
4545
repo_path: std::path::PathBuf,
46+
view: Option<ViewLocator>,
4647
headers: &http::HeaderMap,
4748
) -> Result<Response<Body>, ProtocolError> {
4849
let service_name = params
@@ -61,6 +62,9 @@ pub async fn git_info_refs(
6162
{
6263
return auth_failed();
6364
}
65+
if let Some(locator) = &view {
66+
session.view = Some(resolve_view_target(state, locator).await?);
67+
}
6468
}
6569
ServiceType::ReceivePack => {
6670
if receive_pack_requires_http_auth(&state.storage.config().git)
@@ -227,6 +231,7 @@ pub async fn git_upload_pack(
227231
state: &ProtocolApiState,
228232
req: Request<Body>,
229233
repo_path: std::path::PathBuf,
234+
view: Option<ViewLocator>,
230235
) -> Result<Response<Body>, ProtocolError> {
231236
let mut pack_protocol = SmartSession::from_state(
232237
repo_path,
@@ -236,6 +241,9 @@ pub async fn git_upload_pack(
236241
)?;
237242
let _ = git_http_auth(state, &mut pack_protocol, req.headers()).await?;
238243
check_upload_pack_access(&state.storage.config().git, &pack_protocol.auth).await?;
244+
if let Some(locator) = &view {
245+
pack_protocol.view = Some(resolve_view_target(state, locator).await?);
246+
}
239247
let upload_request = collect_body_data(req.into_body(), "upload-pack").await?;
240248
tracing::debug!("Receive bytes: <-------- {:?}", upload_request);
241249

0 commit comments

Comments
 (0)