SVCS - English Documentation
Loading...
Searching...
No Matches
svcs::core::Index Class Reference

Manages the Staging Area (Index) of the VCS repository. More...

#include <Index.hxx>

Public Member Functions

 Index (const fs::path &vcs_root_path, fs::path repo_root_path, ObjectStorage &storage)
 Constructs the Index manager, setting up paths and loading the index.
 ~Index ()
 Destructor.
void addEntry (const IndexEntry &entry)
 Adds or updates an entry in the staging area.
const IndexEntrygetEntry (const fs::path &file_path) const
 Retrieves an entry from the index by its relative file path.
void load ()
 Loads the index entries from the index file on disk (temporary text format).
void save () const
 Saves the current state of the index entries to the index file (temporary text format).
bool write () const
 Another saving function (like load) but returns bool.
bool isFileModified (const fs::path &file_path) const
 Checks if a file in the working directory has been modified since it was last staged.
void stage_file (const fs::path &relative_path)
 Stages a file by creating a Blob object, saving it to storage, and updating the Index entry (Core logic of 'svcs add').
std::string createTreeObject ()
 Creates the hierarchical Tree structure based on the current staged entries and saves the Tree objects to ObjectStorage.

Detailed Description

Manages the Staging Area (Index) of the VCS repository.

The Index class is responsible for reading and writing the list of staged files to the index file (.svcs/index), managing the 'svcs add' operation, and providing the necessary structure for commit creation.

Constructor & Destructor Documentation

◆ Index()

svcs::core::Index::Index ( const fs::path & vcs_root_path,
fs::path repo_root_path,
ObjectStorage & storage )

Constructs the Index manager, setting up paths and loading the index.

Parameters
vcs_root_pathThe path to the VCS control directory (e.g., .svcs).
repo_root_pathThe path to the repository's working directory root.
storageReference to the ObjectStorage instance.

Member Function Documentation

◆ addEntry()

void svcs::core::Index::addEntry ( const IndexEntry & entry)

Adds or updates an entry in the staging area.

Parameters
entryThe IndexEntry object to be added or updated.

◆ createTreeObject()

std::string svcs::core::Index::createTreeObject ( )

Creates the hierarchical Tree structure based on the current staged entries and saves the Tree objects to ObjectStorage.

Returns
The SHA-1 hash (ID) of the final root Tree object.
Exceptions
std::runtime_errorIf the index is empty or tree creation fails.

◆ getEntry()

const IndexEntry * svcs::core::Index::getEntry ( const fs::path & file_path) const
nodiscard

Retrieves an entry from the index by its relative file path.

Parameters
file_pathThe relative path of the file.
Returns
Pointer to the constant IndexEntry, or nullptr if not found.

◆ isFileModified()

bool svcs::core::Index::isFileModified ( const fs::path & file_path) const
nodiscard

Checks if a file in the working directory has been modified since it was last staged.

Parameters
file_pathThe relative path of the file to check.
Returns
true If the file is modified, deleted, or untracked; false otherwise.

◆ load()

void svcs::core::Index::load ( )

Loads the index entries from the index file on disk (temporary text format).

Exceptions
std::runtime_errorIf the index file cannot be read.

◆ save()

void svcs::core::Index::save ( ) const

Saves the current state of the index entries to the index file (temporary text format).

Exceptions
std::runtime_errorIf the index file cannot be written.

◆ stage_file()

void svcs::core::Index::stage_file ( const fs::path & relative_path)

Stages a file by creating a Blob object, saving it to storage, and updating the Index entry (Core logic of 'svcs add').

Parameters
relative_pathThe path to the file, relative to the repository's root directory.
Exceptions
std::runtime_errorIf the path is invalid or if read/write operations fail.

◆ write()

bool svcs::core::Index::write ( ) const
nodiscard

Another saving function (like load) but returns bool.

Exceptions
std::runtime_errorIf the index file cannot be written.

The documentation for this class was generated from the following files: