Skip to main content

A lightweight Git-like version control system

Project description

vcs - A Lightweight Git-like Version Control System

Python Version License: MIT

A simple, educational version control system implemented in Python that demonstrates the core concepts behind Git. Perfect for learning how version control systems work internally.


๐Ÿ“‹ Table of Contents


๐ŸŽฏ Overview

vcs is a minimal version control system that implements the fundamental concepts of Git in a simplified manner. It provides content tracking through blob and tree objects, commit history with parent-child relationships, staging area for preparing commits, and basic authentication for access control.


๐Ÿงฐ Features

  • Repository initialization (vcs init)
  • User authentication (vcs auth)
  • File staging (vcs add)
  • Commit creation (vcs commit)
  • History viewing (vcs log)
  • Commit inspection (vcs show)
  • Version checkout (vcs checkout)
  • Compressed storage using zlib for efficient space usage
  • Content-based addressing with SHA-1 hashing

๐Ÿ“ฆ Installation

From PyPI

pip install py-vcs-lite

Local Installation

# Clone the repository
git clone https://github.com/yourusername/vcs.git
cd vcs

# Install the package
pip install .

Verify Installation

vcs --help

๐Ÿ“– Commands

vcs init

Initialize a new VCS repository in the current directory.

vcs init

How it works:

  • Creates a .vcs/ directory with necessary subdirectories (objects, commits, etc.)
  • Sets up essential files like HEAD and index to start tracking
  • Establishes the foundation for version control in your project

vcs auth <username> <email>

Set user credentials that will be stored in the config file.

vcs auth john_doe john@example.com

How it works:

  • Stores the username and email in .vcs/config for subsequent operations
  • Required for commit operations to identify the author

vcs add <file>

Stage a file for the next commit.

vcs add filename.txt

How it works:

  • Stages changes by hashing the file's contents into a blob object
  • Updates the index to track the file and its hash (prepares for commit)
  • Think of this as telling VCS: "I want this file to be part of the next commit"

vcs commit "<message>"

Create a new commit with staged changes.

vcs commit "Initial commit"

How it works:

  • Creates a new commit object with:
    • A tree object representing the snapshot of all files staged (from the index)
    • Metadata like the commit message, author, timestamp
  • Stores the commit object compressed in .vcs/objects
  • Updates HEAD to point to this new commit hash
  • Saves the snapshot, so you can revert or checkout later

vcs log

Display the commit history.

vcs log

How it works:

  • Shows the history of commits starting from HEAD
  • Displays chronological list with hash, author, timestamp, and message
  • Useful to track changes over time and review commit messages

vcs show <commit_hash>

Show detailed information about a specific commit.

vcs show a1b2c3d4
# or
vcs show HEAD

How it works:

  • Retrieves the commit object from storage
  • Displays commit metadata and associated file changes
  • Helps you understand what changed in a specific commit

vcs checkout <commit_hash>

Switch the working directory to a specific commit.

vcs checkout a1b2c3d4

How it works:

  • Switches your working directory to reflect the snapshot of the specified commit
  • Deletes files that don't exist in the commit and restores files from the commit tree
  • Updates HEAD to point to the commit
  • Allows you to view or work with your project at any point in history

๐Ÿ’ก Usage Examples

Basic Workflow

# Initialize repository
vcs init

# Set user credentials
vcs auth alice alice@example.com

# Create and add a file
echo "Hello World" > hello.txt
vcs add hello.txt

# Commit the changes
vcs commit "Add hello.txt"

# Make changes and commit again
echo "Updated content" >> hello.txt
vcs add hello.txt
vcs commit "Update hello.txt"

# View history
vcs log

# Check out previous version
vcs checkout <first_commit_hash>

Working with Multiple Files

# Add multiple files
echo "File 1" > file1.txt
echo "File 2" > file2.txt
vcs add file1.txt
vcs add file2.txt
vcs commit "Add two files"

# Show latest commit details
vcs show HEAD

๐Ÿ“ Project Structure

project/
โ”œโ”€โ”€ .vcs/                    # VCS repository data
โ”‚   โ”œโ”€โ”€ objects/             # Compressed blob and tree objects
โ”‚   โ”œโ”€โ”€ commits/             # Commit objects
โ”‚   โ”œโ”€โ”€ index                # Staging area
โ”‚   โ”œโ”€โ”€ HEAD                 # Current commit reference
โ”‚   โ””โ”€โ”€ config               # Authentication and settings
โ””โ”€โ”€ vcs/                     # Source code
    โ”œโ”€โ”€ __init__.py
    โ”œโ”€โ”€ main.py             # CLI entry point
    โ””โ”€โ”€ commands/           # Command implementations
        โ”œโ”€โ”€ init.py
        โ”œโ”€โ”€ auth.py
        โ”œโ”€โ”€ add.py
        โ”œโ”€โ”€ commit.py
        โ”œโ”€โ”€ log.py
        โ”œโ”€โ”€ show.py
        โ””โ”€โ”€ checkout.py

๐Ÿ” How It Works

Object Storage

  • Blobs: Store file contents, compressed with zlib
  • Trees: Store directory structures and file metadata
  • Commits: Store commit metadata and tree references

Authentication

  • Username and email stored in .vcs/config
  • Required for commit operations
  • Set once using vcs auth <username> <email>

Data Flow

  1. Add: File content โ†’ Blob object โ†’ Index entry
  2. Commit: Index entries โ†’ Tree object โ†’ Commit object โ†’ Update HEAD
  3. Checkout: Commit hash โ†’ Tree object โ†’ Restore files

File Organization

.vcs/
โ”œโ”€โ”€ objects/           # Content-addressable storage
โ”œโ”€โ”€ commits/           # Commit metadata
โ”œโ”€โ”€ index              # Staging area (JSON)
โ”œโ”€โ”€ HEAD               # Current commit pointer
โ””โ”€โ”€ config             # User credentials

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

Code Style

  • Follow PEP 8
  • Use meaningful variable names
  • Add docstrings for functions
  • Include error handling

๐Ÿ“„ License

MIT License


Author: Arjun

Thank you for using VCS!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_vcs_lite-0.1.2.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_vcs_lite-0.1.2-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file py_vcs_lite-0.1.2.tar.gz.

File metadata

  • Download URL: py_vcs_lite-0.1.2.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for py_vcs_lite-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8d088c01dc2271e38ef84b3bc9b60c329b5ec1f68b34cc4f804e96feece36733
MD5 6eab634a0ee953986f759cbc4fa72fe4
BLAKE2b-256 037e6a0cf081210ec9ddacf6882de6cac25a6216f6b152eba1298d30a9453505

See more details on using hashes here.

File details

Details for the file py_vcs_lite-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: py_vcs_lite-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for py_vcs_lite-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d3810b5664d3dc96fa6a4c5535bd615e88a80c773f23df573d6edde2a21fae16
MD5 c0773a3dfec3043459ef79b8cacd2265
BLAKE2b-256 76b5a8cdbd2140da23f19bcb1646034a3cabb2bd19a138011a90cc7f64ef2e2a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page