Skip to content

mridulChhipa/Version-Control-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📂 Mini Version Control System (VCS) in C++

📖 Overview

This project is a lightweight version control system for text files, implemented entirely in C++ without using STL’s map or priority_queue. It supports:

  • File creation and editing
  • Versioning with snapshots
  • Rollbacks to previous versions
  • History tracking of commits
  • Listing recent files and biggest version trees
  • Compile through shells scripts
Note: User must be able to input commands at runtime, i.e., from stdin has been followed. For that user must run the main.exe after compiling.

The system uses:

  • A custom hash map (map.cpp)
  • A custom heap/priority queue (Heap.cpp)
  • A tree structure to represent file versions (Tree.cpp)

⚙️ Features

File Operations

  • CREATE <filename>

    • Creates a new file with an initial snapshot (version 0).
  • READ <filename>

    • Prints the current active version’s ID and content.
  • INSERT <filename> <content>

    • Appends content to the active version.
    • If the active version is a snapshot, a new version is created.
  • UPDATE <filename> <content>

    • Replaces the file’s content.
    • Creates a new version if the active one is a snapshot.

Version Control

  • SNAPSHOT <filename> <message>

    • Commits the current version with a message and timestamp.
  • ROLLBACK <filename> [versionID]

    • Rolls back to the parent version (if no ID is provided).
    • Or rolls back to a specific version if versionID is given.
  • HISTORY <filename>

    • Shows all snapshots (ID, timestamp, commit message) in chronological order.

File Listings

  • RECENT_FILES [num]

    • Lists files in descending order of their last modification time.
  • BIGGEST_TREES [num]

    • Lists files in descending order of their total version count.

Exit

  • EXIT

    • Ends the program.

🏧 Project Structure

.
├── main.cpp        # Command interpreter (CLI)
├── map.cpp         # Custom hash map implementation
├── Heap.cpp        # Custom heap/priority queue implementation
├── Tree.cpp        # Version tree (file versioning)

📦 Data Structures

map<K, V> (in map.cpp)

  • Hash-based key-value store.

  • Supports:

    • count(key)
    • operator[]
    • insert(key, value)
    • erase(key)
    • items() → returns all key-value pairs as a vector.

Heap<T, C> (in Heap.cpp)

  • Binary heap (min/max based on comparator).

  • Supports:

    • push(value)
    • pop()
    • top()
    • empty()
    • size()

Tree (in Tree.cpp)

  • Represents a file’s version history as a tree of TreeNode.

  • TreeNode holds:

    • version_id
    • content
    • message
    • created_timestamp
    • snapshot_timestamp
    • parent and children pointers.

▶️ Usage

Windows

To compile and run: open the file run.bat

2. Linux

To compile and run: open the file run.sh

🛠️ Error Handling

  • Invalid commands → Unknown command
  • Missing filename → Please provide a filename
  • File does not exist → Error: File does not exist
  • Colliding names → File already exists
  • No content/message → Error: No content provided
  • No num parameter provided in system-wide commands→ Please specify the number of files
  • If num more than total files → Terminating early ...
  • If rollback to parent of root → Already at root version. Cannot rollback further.

About

Mini Git

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published