Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
199 changes: 199 additions & 0 deletions docs/GIT_PROTOCOL_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
# Git Protocol Abstraction Design and Implementation

## 1. Project Overview

The git-internal library implements a transport layer abstraction for the Git smart protocol, separating HTTP and SSH protocol handling from monorepo business code and adapting to any business system through Trait interfaces.

## 2. Architecture Design

### 2.1 Layered Architecture

```
┌─────────────────────────────────────┐
│ Business System Integration │ ← Implement Trait interfaces
├─────────────────────────────────────┤
│ Transport Protocol Adapters │ ← HTTP/SSH handlers
├─────────────────────────────────────┤
│ Git Smart Protocol Core │ ← Protocol logic implementation
├─────────────────────────────────────┤
│ Pack File Processing Layer │ ← Object packing/unpacking
└─────────────────────────────────────┘
```

### 2.2 Core Abstraction Interfaces

**RepositoryAccess Trait**

- Provides storage layer abstraction, isolating business logic
- Supports reference management, object access, and Pack operations
- Can adapt to any storage backend (filesystem, database, etc.)

**AuthenticationService Trait**

- Unified authentication interface supporting HTTP and SSH
- Can integrate with any authentication system (OAuth, JWT, public key, etc.)

**GitProtocol Core**

- Transport-agnostic protocol implementation
- Unified info/refs, upload-pack, receive-pack interfaces

## 3. Implementation Status

### 3.1 Completed Features

**Core Protocol**

- Complete Git smart protocol v1 implementation
- Reference advertisement and capability negotiation
- upload-pack service (clone/fetch operations)
- receive-pack service (push operations)
- Pack file generation and parsing

**Transport Layer**

- HTTP transport adapter (request parsing, streaming responses)
- SSH transport adapter (command parsing, authentication integration)
- Transport protocol abstraction (unified interface)

**Data Processing**

- Side-band multiplexing
- Progress reporting mechanism
- Object parsing (blob, commit, tree)
- Reference updates and validation

**Authentication System**

- HTTP authentication (header-based)
- SSH authentication (public key verification)
- Pluggable authentication architecture

## 4. Module Organization

```
src/protocol/
├── core.rs # Main abstractions (Trait definitions, GitProtocol)
├── http.rs # HTTP transport adapter
├── ssh.rs # SSH transport adapter
├── smart.rs # Git smart protocol implementation
├── pack.rs # Pack generation and processing
├── types.rs # Protocol types and error definitions
├── utils.rs # Protocol utility functions
└── mod.rs # Module exports
```

## 5. HTTP Protocol Abstraction

### 5.1 Design Features

- Request path parsing and repository location
- Standard Git HTTP content type handling
- Streaming responses for large repository transfers
- Error mapping to HTTP status codes

### 5.2 Main Functions

- `handle_info_refs`: Process reference query requests
- `handle_upload_pack`: Process clone/fetch requests
- `handle_receive_pack`: Process push requests
- `authenticate_http`: HTTP authentication integration

## 6. SSH Protocol Abstraction

### 6.1 Design Features

- Git command line parsing (git-upload-pack, git-receive-pack)
- Repository path extraction and validation
- Direct protocol mapping without HTTP overhead
- Public key authentication integration

### 6.2 Main Functions

- Command parsing and dispatching
- Repository path extraction
- Protocol operation mapping
- SSH authentication integration

## 7. Trait Adaptation Solution

### 7.1 Storage Adaptation

Adapt any storage system through RepositoryAccess Trait:

- Filesystem storage
- Database storage
- Cloud storage services
- Distributed storage

### 7.2 Authentication Adaptation

Integrate any authentication system through AuthenticationService Trait:

- Traditional username/password
- OAuth/JWT tokens
- SSH public key authentication
- Enterprise SSO systems

### 7.3 Framework Agnostic

- No dependency on specific web frameworks
- No binding to specific SSH libraries
- No database choice restrictions
- No forced authentication schemes

## 8. Error Handling and Types

### 8.1 Protocol Error Types

- InvalidService: Invalid service request
- RepositoryNotFound: Repository does not exist
- Unauthorized: Authentication failure
- InvalidRequest: Request format error
- Other I/O and internal errors

### 8.2 Transport Mapping

Each transport layer is responsible for mapping protocol errors to appropriate transport error formats (HTTP status codes, SSH error messages, etc.).

## 9. Capabilities and Features

### 9.1 Supported Git Capabilities

- side-band-64k: Multiplexed data streams
- ofs-delta: Offset delta objects
- report-status: Push status reporting
- multi_ack_detailed: Detailed acknowledgment negotiation
- no-done: Optimized negotiation flow

### 9.2 Protocol Features

- Complete want/have negotiation
- Incremental Pack transmission
- Progress reporting
- Reference update validation

## 10. Integration Guide

### 10.1 Implementation Steps

1. Implement RepositoryAccess Trait to connect storage system
2. Implement AuthenticationService Trait to connect authentication system
3. Create HTTP/SSH handler instances
4. Route requests to appropriate handlers in framework

### 10.2 Design Principles

- Separation of concerns: Protocol logic decoupled from business logic
- Interface abstraction: Pluggable architecture through Traits
- Transport agnostic: Same protocol logic supports multiple transports
- Performance focused: Streaming processing, memory efficient

## 11. Summary

The git-internal library successfully implements Git protocol transport layer abstraction, separating protocol handling from business logic through clear Trait interfaces. This design supports:

- **Complete protocol implementation**: Full Git smart protocol v1 functionality
- **Flexible integration solution**: Can adapt to any storage and authentication system
- **Transport layer abstraction**: Unified HTTP and SSH handling
- **High-performance design**: Streaming processing and memory optimization
Loading