Skip to main content

A simple 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 vcs-core

Local Installation

# Clone the repository
git clone https://github.com/ZEUS33776/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 Deshmukh

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

vcs_core-0.1.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

vcs_core-0.1.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file vcs_core-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for vcs_core-0.1.0.tar.gz
Algorithm Hash digest
SHA256 63fb8993630b0e51719df7f04d1f740eacd37b874854f8a762366fb6d1409071
MD5 e9c955c8664e48f2fcb8657281b7d8b5
BLAKE2b-256 6e55519c5ac31383946745738a80d702bdeb8c5d25dceec80848632bdb99a6d4

See more details on using hashes here.

File details

Details for the file vcs_core-0.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for vcs_core-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 32309bc6d5fefce9624c23b9c35368482f518b4c604eb36d46cdf5996e75a573
MD5 bf2c430e4cc173bbb951722fef968225
BLAKE2b-256 e88b2fcbbf1d657496c96d5a11b26a5bfb08727e1167f3b719600fe860ea8b8b

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