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

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.1.tar.gz (9.3 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.1-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_vcs_lite-0.1.1.tar.gz
  • Upload date:
  • Size: 9.3 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.1.tar.gz
Algorithm Hash digest
SHA256 f280f8098fa89fa453931d376e51fe9e5236b89609618ed82660de5f9817aef6
MD5 9831b91ca510bf3c8526031bcca29a64
BLAKE2b-256 2bdd8a5f8d68d5a5eb966dacd6871529d731cad4c66259c6a8b4c7e58e951129

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_vcs_lite-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.5 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a2f3a7f2cac6199a8bef30f0f7a976a26132c1706504090c61cbd44d2259f675
MD5 f7901d71734462d145ee808740b1b4e5
BLAKE2b-256 49ccbf12c334be6b443c190180b7c55bb0c5efeefe809d47b861a5e274508333

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