feat: Abstract HTTP and SSH protocal from mega to git-internal#12
Conversation
Signed-off-by: allure <1550220889@qq.com>
There was a problem hiding this comment.
Pull Request Overview
This PR extracts Git smart protocol handling from the Mega monorepo into git-internal, creating a transport-agnostic and reusable implementation. The refactoring decouples HTTP and SSH transport logic from business logic through trait-based abstractions.
Key Changes:
- Introduced
RepositoryAccessandAuthenticationServicetraits to abstract storage and authentication - Created transport-specific handlers (
HttpGitHandlerandSshGitHandler) that wrap the core protocol logic - Implemented
SmartProtocolcontaining transport-agnostic Git protocol operations
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/protocol/core.rs | Defines core traits (RepositoryAccess, AuthenticationService) and GitProtocol struct for transport-agnostic protocol handling |
| src/protocol/smart.rs | Implements SmartProtocol with Git operations (info-refs, upload-pack, receive-pack) |
| src/protocol/http.rs | HTTP transport adapter with request parsing and Git-specific content type handling |
| src/protocol/ssh.rs | SSH transport adapter with command parsing utilities |
| src/protocol/pack.rs | Pack generation and unpacking logic using RepositoryAccess trait |
| src/protocol/types.rs | Protocol error types, service types, capabilities, and constants |
| src/protocol/utils.rs | Utility functions for packet-line parsing and formatting |
| src/protocol/mod.rs | Module exports for public API |
| src/config.rs | Configuration structs for pack and LFS settings |
| src/lib.rs | Updated exports to expose protocol module |
| docs/PROTOCOL_ABSTRACTION.md | Comprehensive documentation of the protocol abstraction design |
| Cargo.toml | Added async/network dependencies (async-trait, futures, russh, etc.) |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
genedna
left a comment
There was a problem hiding this comment.
- 升级
russh到0.54.6最新版本 - 修改
cargo clippy检查的错误:
warning: use of deprecated method `sha1::digest::generic_array::GenericArray::<T, N>::as_slice`: please upgrade to generic-array 1.x
--> src/hash.rs:111:28
|
111 | SHA1::from_bytes(h.as_slice())
| ^^^^^^^^
|
= note: `#[warn(deprecated)]` on by default|
|
||
| let refs = self | ||
| .repo_storage | ||
| .get_repository_refs(repo_path) |
There was a problem hiding this comment.
不需要再引入存储层,需要在定义trait的时候加上想要的数据
Signed-off-by: allure <1550220889@qq.com>
| Capability::ServerOption(option) => write!(f, "server-option={}", option), | ||
| Capability::SessionId(id) => write!(f, "session-id={}", id), | ||
| Capability::PackfileUris(uris) => write!(f, "packfile-uris={}", uris), | ||
| Capability::Lfs => write!(f, "lfs"), |
There was a problem hiding this comment.
请根据这个文档更新capabilities: https://git-scm.com/docs/protocol-capabilities
| /// Update a single reference | ||
| async fn update_reference( | ||
| &self, | ||
| repo_path: &str, |
There was a problem hiding this comment.
请移mr 中所有repo_path 字段,因为其和monrepo 相关
| &mut self, | ||
| repo_path: &str, | ||
| request_stream: Pin<Box<dyn Stream<Item = Result<Bytes, ProtocolError>> + Send>>, | ||
| ) -> Result<Pin<Box<dyn Stream<Item = Result<Bytes, ProtocolError>> + Send>>, ProtocolError> |
|
|
||
| /// Handle git info-refs request | ||
| pub async fn info_refs( | ||
| &mut self, |
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
src/protocol/smart.rs:1
- Comments in test code are written in Chinese. For consistency and accessibility, comments should be in English, especially in an open-source project.
use std::pin::Pin;
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| } | ||
|
|
||
| /// Side-band types for multiplexed data streams | ||
| pub enum SideBind { |
There was a problem hiding this comment.
Corrected spelling of 'SideBind' to 'SideBand'. The correct terminology in Git protocol documentation is 'side-band', not 'side-bind'.
|
|
||
| #[tokio::test] | ||
| async fn test_pack_roundtrip_encode_decode() { | ||
| // 构造两个 Blob |
There was a problem hiding this comment.
Comments in test code are written in Chinese. For consistency and accessibility, comments should be in English.
|
|
||
| pub fn build_smart_reply( | ||
| transport_protocol: TransportProtocol, | ||
| ref_list: &Vec<String>, |
There was a problem hiding this comment.
Parameter should be &[String] instead of &Vec<String>. Taking a reference to Vec is less idiomatic than using a slice, which is more flexible and performs the same.
| ref_list: &Vec<String>, | |
| ref_list: &[String], |
Signed-off-by: allure <1550220889@qq.com>
feat: Abstract HTTP and SSH protocal from mega to git-internal
link #10
This PR extracts the Git smart protocol handling from the Mega monorepo into
git-internal, making it transport-agnostic and reusable. It resolves the tight coupling of HTTP and SSH logic with the business system.Key Changes:
Introduced Core Abstractions:
RepositoryAccesstrait: Decouples repository storage and business logic from the protocol layer.AuthenticationServicetrait: Abstracts authentication logic for both HTTP and SSH.Created Transport-Specific Handlers:
HttpGitHandler: Manages all HTTP-specific Git operations (info/refs,upload-pack,receive-pack).SshGitHandler: Manages SSH-based Git commands (git-upload-pack,git-receive-pack).Established a Transport-Agnostic Protocol Core: The
GitProtocolstruct contains the core protocol logic and operates on the new traits, allowing it to be used with any transport or backend.