feat(pack): add raw advertise refs and stateless protocol support

- Add raw flag to AdvertiseRefsRequest to enable raw pkt-line output
- Implement advertise_refs_raw function that calls git upload-pack/receive-pack with --advertise-refs
- Add stateless flag to GitProtocolFeatures for HTTP smart protocol support
- Modify upload_pack and receive_pack to accept stateless parameter
- Update command construction to include --stateless-rpc flag when enabled
- Add raw_data field to AdvertiseRefsResponse for raw output
- Update pack cache key computation to include raw service differentiation
- Initialize raw field to false in all request creation calls
This commit is contained in:
zhenyi
2026-06-08 21:46:31 +08:00
parent eeb4d9f902
commit ab32e8826e
8 changed files with 99 additions and 16 deletions
+10 -4
View File
@@ -47,8 +47,12 @@ impl pack_service_server::PackService for GitksService {
};
if let Some(ref pc) = self.pack_cache {
let protocol = inner.service.clone();
if let Ok(digest) = pc.disk_cache().compute_info_refs_key(&repo, &protocol) {
let protocol_key = if inner.raw {
format!("{}:raw", inner.service)
} else {
inner.service.clone()
};
if let Ok(digest) = pc.disk_cache().compute_info_refs_key(&repo, &protocol_key) {
if let Some(cached) = pc.lookup_info_refs::<AdvertiseRefsResponse>(&digest) {
tracing::info!(%repo, refs = cached.references.len(), "advertise_refs done (cached)");
m.record("ok");
@@ -119,6 +123,7 @@ impl pack_service_server::PackService for GitksService {
}
};
tracing::info!(%repo, "upload-pack streaming started");
let stateless = first.protocol.as_ref().is_some_and(|p| p.stateless);
let (tx, rx) = tokio::sync::mpsc::channel(16);
tx.send(Ok(first))
@@ -132,7 +137,7 @@ impl pack_service_server::PackService for GitksService {
}
});
let result = gb.upload_pack(ReceiverStream::new(rx)).await?;
let result = gb.upload_pack(stateless, ReceiverStream::new(rx)).await?;
m.record("ok");
Ok(tonic::Response::new(result))
}
@@ -188,6 +193,7 @@ impl pack_service_server::PackService for GitksService {
}
};
tracing::info!(%repo, "receive-pack streaming started");
let stateless = first.protocol.as_ref().is_some_and(|p| p.stateless);
let (tx, rx) = tokio::sync::mpsc::channel(16);
tx.send(Ok(first))
@@ -201,7 +207,7 @@ impl pack_service_server::PackService for GitksService {
}
});
let result = gb.receive_pack(ReceiverStream::new(rx)).await?;
let result = gb.receive_pack(stateless, ReceiverStream::new(rx)).await?;
m.record("ok");
Ok(tonic::Response::new(result))
}