Skip to content

a distributed version control system engineered from first principles in Go. also paired it up w a web portal for better visualization

Notifications You must be signed in to change notification settings

sidxh/sidgit-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sidgit: a version control from scratch in go

License: MIT

sidgit is a distributed version control system engineered from first principles in Go, implementing Git's cryptographic object model and directed acyclic graph (DAG) commit structure. The system features a content-addressable storage engine with SHA-1 cryptographic hashing, zlib compression, and atomic operations, enhanced with modern concurrent processing, topological graph algorithms, and advanced terminal visualization capabilities.

Includes comprehensive web-based repository visualizer for interactive commit graph exploration and Git internals analysis.

Components

CLI Tool (cmd/sidgit-go/)

Full-featured command-line version control system with Git-compatible object storage and advanced visualization capabilities.

Web Visualizer (visualizer-ui/)

Next.js-based web application providing interactive commit graph visualization, comprehensive object inspection, and Git internals analysis interface.

Features

Core Version Control Operations

  • Repository Management: init - Initialize new repositories with standard Git directory structure
  • Staging & Commits: add (concurrent), commit - Full staging area with parallel file processing
  • History & Inspection: log with graph visualization, status with color-coded output, diff with unified format
  • Branching & Merging: branch, checkout, merge (fast-forward), branch list
  • Object Inspection: cat-file, hash-object, write-tree - Low-level object store access

Advanced Capabilities

  • ASCII Commit Graphs: Topological sorting with multi-branch visualization (log --graph)
  • Concurrent Operations: Parallel file processing in add command using goroutines
  • Enhanced UI: Color-coded status output, formatted object display, branch diagrams
  • Git Compatibility: Standard object format (SHA-1, zlib compression), refs structure
  • Web Visualization: Interactive SVG commit graphs with comprehensive object inspection

Web Visualizer Features

  • Interactive Commit Graph: SVG-based topological visualization with real-time selection
  • Multi-tab Inspector: Details, Files, Changes, Raw, and Explorer views
  • Object Analysis: SHA-1 lookup, cryptographic analysis, storage format inspection
  • Diff Visualization: Side-by-side content comparison with change statistics
  • Repository Upload: Drag-and-drop interface with automatic .sidgit detection

Command Reference

Repository Operations

sidgit init [path]              # Initialize repository
sidgit status                   # Show working tree status with colors
sidgit add <files...>           # Stage files (concurrent processing)
sidgit commit -m "message"      # Create commit

History & Visualization

sidgit log                      # Linear commit history
sidgit log --graph              # ASCII commit graph with branches
sidgit log --oneline            # Compact one-line format
sidgit log --graph --oneline    # Combined graph and compact view

Branching & Navigation

sidgit branch <name>            # Create new branch
sidgit branch list              # List all branches with latest commits
sidgit checkout <branch>        # Switch branches
sidgit merge <branch>           # Fast-forward merge

Diff & Inspection

sidgit diff                     # Working directory vs index
sidgit diff --staged            # Index vs HEAD
sidgit cat-file <hash>          # Inspect objects (formatted output)
sidgit hash-object <file>       # Generate object hash
sidgit write-tree               # Create tree from index

Architecture

The system implements a sophisticated three-layer architecture based on Git's proven distributed version control model:

Content-Addressed Object Store

Component Description
Cryptographic Addressing Objects identified by SHA-1 hash (160-bit) of their content, ensuring immutable references and collision-resistant addressing
Object Types Four fundamental types following Git's object model:
blob: Raw file content with size header
tree: Directory snapshots with mode, type, hash, and name entries
commit: History nodes containing tree pointer, parent references, author/committer metadata, and message
tag: Annotated references (future implementation)
Storage Format Objects stored in .sidgit/objects/XX/YYYY... hierarchy with zlib (RFC 1950) compression
Atomic Operations Write operations use temporary files with atomic rename for consistency
Deduplication Identical content automatically deduplicated through content addressing

Directed Acyclic Graph (DAG) History Model

Component Description
Commit Graph History represented as DAG where commits are nodes and parent relationships are directed edges
Topological Ordering Implements Kahn's algorithm for commit traversal ensuring proper ancestry relationships
Reference Management HEAD: Symbolic reference to current branch (ref: refs/heads/<branch>)
• Branches: Direct references stored in refs/heads/ pointing to commit objects
• Detached HEAD: Direct object reference for specific commit checkout
Graph Algorithms Custom implementation for ancestry checking, merge-base calculation, and reachability analysis
Multi-parent Support Architecture supports merge commits (multiple parents) for future three-way merge implementation

Index-Based Staging Architecture

Component Description
Three-Tree Architecture Working Directory ↔ Index ↔ Repository with independent state tracking
Index Structure Binary format storing:
• File metadata (mode, size, timestamps)
• SHA-1 hashes of staged content
• Path information with lexicographic ordering
Concurrent Processing Parallel file hashing and object creation using worker pool pattern with goroutines
State Transitions Explicit staging allows granular commit preparation and conflict resolution
Performance Optimizations • Stat-based change detection
• Incremental index updates
• Memory-mapped file operations for large repositories

Implementation Details

Project Structure

cmd/sidgit-go/          # CLI interface (Cobra framework)
├── main.go             # Application entry point
└── cmd/                # Command definitions with flags
internal/
├── cli/                # Command handlers and business logic
├── git/                # Core Git operations and data structures
└── ui/                 # Enhanced output formatting and visualization
visualizer-ui/          # Web-based repository visualizer
├── app/                # Next.js App Router pages and API routes
├── components/         # React components for visualization
├── types/              # TypeScript type definitions
└── lib/                # Utility functions and helpers

Key Components

  • Concurrent Processing: Goroutine-based parallel file operations
  • Graph Algorithms: Topological sorting for commit history visualization
  • Object Parsing: Full support for Git object formats
  • UI Enhancements: Color coding, ASCII art, formatted output
  • Web Interface: Interactive SVG rendering with real-time object inspection

Installation

CLI Tool Installation

Via Homebrew (Recommended)

# Add custom tap
brew tap sidxh/xyz

# Install sidgit CLI
brew install sidgit

# Verify installation
sidgit --help

Build from Source

git clone https://github.com/sidxh/sidgit-go
cd sidgit-go
go build -o sidgit cmd/sidgit-go/main.go

# Optional: Install globally
sudo mv sidgit /usr/local/bin/

Web Visualizer Setup

Development Environment

cd visualizer-ui
npm install
# or
pnpm install

# Start development server
npm run dev
# or
pnpm dev

# Access at http://localhost:3000

Production Deployment

cd visualizer-ui
npm run build
npm start
# or
pnpm build
pnpm start

Usage Examples

CLI Operations

# Initialize and create first commit
mkdir project && cd project
sidgit init
echo "Hello World" > README.txt
sidgit add README.txt
sidgit commit -m "Initial commit"

# Create and work with branches
sidgit branch feature
sidgit checkout feature
echo "Feature code" > feature.txt
sidgit add feature.txt
sidgit commit -m "Add feature"

# Visualize history
sidgit log --graph --oneline
sidgit branch list

# Merge and inspect
sidgit checkout main
sidgit merge feature
sidgit status

Web Visualizer Workflow

  1. Create Repository: Use CLI to initialize and populate repository
  2. Access Visualizer: Navigate to web interface at http://localhost:3000
  3. Upload Repository: Drag-and-drop project directory containing .sidgit folder
  4. Explore History: Click commit nodes to inspect details, files, and changes
  5. Analyze Objects: Use Explorer tab for direct SHA-1 hash inspection

Integration Example

# Create repository with CLI
sidgit init my-project
cd my-project
echo "Initial content" > file1.txt
sidgit add file1.txt
sidgit commit -m "Initial commit"

# Create branch and additional commits
sidgit branch feature
sidgit checkout feature
echo "Feature content" > file2.txt
sidgit add file2.txt
sidgit commit -m "Add feature"

# Visualize in web interface
# Upload my-project directory to visualizer
# Explore interactive commit graph and object details

License

MIT License - see LICENSE file for details.

About

a distributed version control system engineered from first principles in Go. also paired it up w a web portal for better visualization

Resources

Stars

Watchers

Forks

Packages

No packages published