Skip to content

feat: Abstract HTTP and SSH protocal from mega to git-internal#12

Merged
benjamin-747 merged 3 commits into
libra-tools:mainfrom
AllureCurtain:feat/protocal
Oct 24, 2025
Merged

feat: Abstract HTTP and SSH protocal from mega to git-internal#12
benjamin-747 merged 3 commits into
libra-tools:mainfrom
AllureCurtain:feat/protocal

Conversation

@AllureCurtain

Copy link
Copy Markdown
Contributor

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:

    • RepositoryAccess trait: Decouples repository storage and business logic from the protocol layer.
    • AuthenticationService trait: 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 GitProtocol struct contains the core protocol logic and operates on the new traits, allowing it to be used with any transport or backend.

Signed-off-by: allure <1550220889@qq.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 RepositoryAccess and AuthenticationService traits to abstract storage and authentication
  • Created transport-specific handlers (HttpGitHandler and SshGitHandler) that wrap the core protocol logic
  • Implemented SmartProtocol containing 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
genedna requested a review from benjamin-747 October 20, 2025 02:16

@genedna genedna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 升级 russh0.54.6 最新版本
  2. 修改 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

Comment thread src/config.rs Outdated
Comment thread src/config.rs Outdated
Comment thread docs/PROTOCOL_ABSTRACTION.md Outdated
Comment thread src/protocol/types.rs Outdated
Comment thread src/protocol/types.rs
Comment thread src/protocol/smart.rs Outdated
Comment thread src/protocol/smart.rs Outdated

let refs = self
.repo_storage
.get_repository_refs(repo_path)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不需要再引入存储层,需要在定义trait的时候加上想要的数据

Signed-off-by: allure <1550220889@qq.com>
Comment thread src/protocol/types.rs Outdated
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"),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请根据这个文档更新capabilities: https://git-scm.com/docs/protocol-capabilities

Comment thread src/protocol/core.rs Outdated
/// Update a single reference
async fn update_reference(
&self,
repo_path: &str,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请移mr 中所有repo_path 字段,因为其和monrepo 相关

Comment thread src/protocol/core.rs Outdated
&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>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

减少层级嵌套,使用关联类型

Comment thread src/protocol/core.rs Outdated

/// Handle git info-refs request
pub async fn info_refs(
&mut self,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

考虑是否要使用可变引用

@genedna
genedna requested a review from Copilot October 21, 2025 03:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/protocol/types.rs Outdated
}

/// Side-band types for multiplexed data streams
pub enum SideBind {

Copilot AI Oct 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'SideBind' to 'SideBand'. The correct terminology in Git protocol documentation is 'side-band', not 'side-bind'.

Copilot uses AI. Check for mistakes.
Comment thread src/protocol/pack.rs Outdated

#[tokio::test]
async fn test_pack_roundtrip_encode_decode() {
// 构造两个 Blob

Copilot AI Oct 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments in test code are written in Chinese. For consistency and accessibility, comments should be in English.

Copilot uses AI. Check for mistakes.
Comment thread src/protocol/utils.rs Outdated

pub fn build_smart_reply(
transport_protocol: TransportProtocol,
ref_list: &Vec<String>,

Copilot AI Oct 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
ref_list: &Vec<String>,
ref_list: &[String],

Copilot uses AI. Check for mistakes.
Comment thread Cargo.toml
Signed-off-by: allure <1550220889@qq.com>
@benjamin-747
benjamin-747 merged commit 88e4813 into libra-tools:main Oct 24, 2025
@github-actions github-actions Bot mentioned this pull request Feb 10, 2026
genedna pushed a commit to genedna/git-internal that referenced this pull request Mar 15, 2026
feat: Abstract HTTP and SSH protocal from mega to git-internal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants