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

Manages all physical file and directory operations within the SVCS repository. More...

#include <RepositoryManager.hxx>

Inheritance diagram for svcs::core::RepositoryManager:
svcs::test::server::MockRepositoryManager

Public Member Functions

 RepositoryManager (std::shared_ptr< ISubject > bus)
 Constructs a RepositoryManager.
void updateHead (const std::string &commit_hash) const
 Updates HEAD reference.
bool initializeRepository (const std::string &path, bool force=false)
 Initializes a new SVCS repository in the specified path.
bool isRepositoryInitialized (const std::string &path=".")
 Checks if a SVCS repository is initialized in the given path or its parents.
void updateBranchReference (const std::string &branchName, const std::string &commitHash) const
 Updates branch reference file with commit hash.
std::filesystem::path getRepositoryPath () const
 Returns the determined root path of the currently active repository.
bool addFileToStaging (const std::string &filePath)
 Attempts to add a file to the staging area (index).
std::string getHeadCommit () const
 Retrieves the hash of the current HEAD commit in the repository.
std::string createCommit (const std::string &message)
 Creates a commit from the currently staged files.
void updateCommitReferences (const std::string &removedCommitHash, const std::string &newParentHash) const
 Updates commit references when a commit is removed.
bool revertCommit (const std::string &commit_hash)
 Reverts the repository state to a previous commit.
std::optional< CommitInfogetCommitByHash (const std::string &commit_hash) const
 Retrieves the CommitInfo structure for a given commit hash.
std::string getParentCommitHash (const std::string &commit_hash) const
 Retrieves the hash of the parent commit for a given commit.
bool restoreFilesFromCommit (const CommitInfo &commit) const
 Restores the working directory files to the state recorded in a specific commit.
bool clearStagingArea ()
 Clears the contents of the staging area (index).
bool saveStagedChanges (const std::string &message)
 Creates a commit from staged changes. (Convenience method often used by the SaveCommand).
std::vector< std::string > getStagedFiles ()
 Retrieves a list of all files currently marked as staged (indexed).
std::vector< CommitInfogetCommitHistory () const
 Retrieves the complete commit history for the current branch.
std::vector< CommitInfogetBranchHistory (const std::string &branch_name) const
 Retrieves the commit history for a specific branch.
std::string getCurrentBranch () const
 Gets the current branch name.
bool removeRepository (const std::filesystem::path &path) const
 Attempts to recursively remove the entire SVCS repository structure (e.g., the .svcs directory) and its contents.
bool branchExists (const std::string &branch_name) const
 Checks if a branch exists.
std::string getBranchHead (const std::string &branch_name) const
 Gets the head commit of a branch.
std::string getFileContentAtCommit (const std::string &commit_hash, const std::string &file_path) const
 Gets the content of a file at a specific commit.
std::vector< std::string > getCommitFiles (const std::string &commit_hash) const
 Gets all files changed in a commit.
void setMergeState (const std::string &branch_name, const std::string &commit_hash) const
 Sets merge state (for conflict resolution).
void clearMergeState () const
 Clears merge state (after merge completion/abort).
bool isMergeInProgress () const
 Checks if a merge is in progress.
std::string getMergeBranch () const
 Gets the branch being merged.

Static Public Member Functions

static std::string generateCommitHash (const std::string &content)
 Generates a commit hash from content.

Detailed Description

Manages all physical file and directory operations within the SVCS repository.

The RepositoryManager is the core layer responsible for interacting directly with the file system for tasks like initialization, path management, staging, committing, and logging.

Constructor & Destructor Documentation

◆ RepositoryManager()

svcs::core::RepositoryManager::RepositoryManager ( std::shared_ptr< ISubject > bus)
explicit

Constructs a RepositoryManager.

Parameters
busA shared pointer to the event bus (ISubject) for communication.

Member Function Documentation

◆ addFileToStaging()

bool svcs::core::RepositoryManager::addFileToStaging ( const std::string & filePath)

Attempts to add a file to the staging area (index).

This typically involves reading the file and updating the index state.

Parameters
filePathThe path to the file to be staged.
Returns
true if the file was successfully added, false otherwise.

◆ branchExists()

bool svcs::core::RepositoryManager::branchExists ( const std::string & branch_name) const

Checks if a branch exists.

Parameters
branch_nameThe branch name to check.
Returns
true if branch exists, false otherwise.

◆ clearStagingArea()

bool svcs::core::RepositoryManager::clearStagingArea ( )

Clears the contents of the staging area (index).

Returns
true if the staging area was successfully cleared, false otherwise.

◆ createCommit()

std::string svcs::core::RepositoryManager::createCommit ( const std::string & message)

Creates a commit from the currently staged files.

Parameters
messageCommit message provided by the user.
Returns
The newly created commit hash if successful, empty string otherwise.

◆ generateCommitHash()

std::string svcs::core::RepositoryManager::generateCommitHash ( const std::string & content)
static

Generates a commit hash from content.

Parameters
contentThe content to hash.
Returns
The generated commit hash.

◆ getBranchHead()

std::string svcs::core::RepositoryManager::getBranchHead ( const std::string & branch_name) const

Gets the head commit of a branch.

Parameters
branch_nameThe branch name.
Returns
The commit hash of the branch head.

◆ getBranchHistory()

std::vector< CommitInfo > svcs::core::RepositoryManager::getBranchHistory ( const std::string & branch_name) const

Retrieves the commit history for a specific branch.

Parameters
branch_nameThe name of the branch.
Returns
Vector of CommitInfo objects for the branch.

◆ getCommitByHash()

std::optional< CommitInfo > svcs::core::RepositoryManager::getCommitByHash ( const std::string & commit_hash) const

Retrieves the CommitInfo structure for a given commit hash.

Parameters
commit_hashThe hash of the commit to retrieve.
Returns
An optional containing the CommitInfo if found, or std::nullopt otherwise.

◆ getCommitFiles()

std::vector< std::string > svcs::core::RepositoryManager::getCommitFiles ( const std::string & commit_hash) const

Gets all files changed in a commit.

Parameters
commit_hashThe commit hash.
Returns
Vector of file paths.

◆ getCommitHistory()

std::vector< CommitInfo > svcs::core::RepositoryManager::getCommitHistory ( ) const

Retrieves the complete commit history for the current branch.

Returns
Vector of CommitInfo objects representing the commit history, typically the newest first.

◆ getCurrentBranch()

std::string svcs::core::RepositoryManager::getCurrentBranch ( ) const

Gets the current branch name.

Returns
The current branch name.

◆ getFileContentAtCommit()

std::string svcs::core::RepositoryManager::getFileContentAtCommit ( const std::string & commit_hash,
const std::string & file_path ) const

Gets the content of a file at a specific commit.

Parameters
commit_hashThe commit hash.
file_pathThe file path.
Returns
The file content.

◆ getHeadCommit()

std::string svcs::core::RepositoryManager::getHeadCommit ( ) const

Retrieves the hash of the current HEAD commit in the repository.

Returns
The commit hash string.

◆ getMergeBranch()

std::string svcs::core::RepositoryManager::getMergeBranch ( ) const

Gets the branch being merged.

Returns
Branch name if merge in progress, empty string otherwise.

◆ getParentCommitHash()

std::string svcs::core::RepositoryManager::getParentCommitHash ( const std::string & commit_hash) const

Retrieves the hash of the parent commit for a given commit.

Parameters
commit_hashThe hash of the child commit.
Returns
The parent commit hash string (empty if it is the initial commit).

◆ getRepositoryPath()

std::filesystem::path svcs::core::RepositoryManager::getRepositoryPath ( ) const
nodiscard

Returns the determined root path of the currently active repository.

Returns
The string path to the repository root.

◆ getStagedFiles()

std::vector< std::string > svcs::core::RepositoryManager::getStagedFiles ( )

Retrieves a list of all files currently marked as staged (indexed).

Returns
A vector of strings containing the file paths in the staging area.

◆ initializeRepository()

bool svcs::core::RepositoryManager::initializeRepository ( const std::string & path,
bool force = false )

Initializes a new SVCS repository in the specified path.

Creates the necessary internal directories and files (e.g., .svcs/).

Parameters
pathThe directory path where the repository should be created.
forceIf true, forces initialization even if the directory exists (implementation dependent).
Returns
true if initialization was successful, false otherwise.

◆ isMergeInProgress()

bool svcs::core::RepositoryManager::isMergeInProgress ( ) const

Checks if a merge is in progress.

Returns
true if merge is in progress, false otherwise.

◆ isRepositoryInitialized()

bool svcs::core::RepositoryManager::isRepositoryInitialized ( const std::string & path = ".")

Checks if a SVCS repository is initialized in the given path or its parents.

Parameters
pathThe path to start searching from (defaults to the current directory ".").
Returns
true if a repository structure is found, false otherwise.

◆ removeRepository()

bool svcs::core::RepositoryManager::removeRepository ( const std::filesystem::path & path) const

Attempts to recursively remove the entire SVCS repository structure (e.g., the .svcs directory) and its contents.

Parameters
pathThe root path of the repository to remove.
Returns
true if removal was successful, false otherwise.

◆ restoreFilesFromCommit()

bool svcs::core::RepositoryManager::restoreFilesFromCommit ( const CommitInfo & commit) const

Restores the working directory files to the state recorded in a specific commit.

Parameters
commitThe CommitInfo structure representing the target state.
Returns
true if files were restored successfully, false otherwise.

◆ revertCommit()

bool svcs::core::RepositoryManager::revertCommit ( const std::string & commit_hash)

Reverts the repository state to a previous commit.

This is typically used to undo the effects of a previous 'save' (commit).

Parameters
commit_hashThe hash of the commit to revert to (or the one before the commit to undo).
Returns
true if the revert was successful, false otherwise.

◆ saveStagedChanges()

bool svcs::core::RepositoryManager::saveStagedChanges ( const std::string & message)

Creates a commit from staged changes. (Convenience method often used by the SaveCommand).

Parameters
messageCommit message.
Returns
true if the save (commit) was successful, false otherwise.

◆ setMergeState()

void svcs::core::RepositoryManager::setMergeState ( const std::string & branch_name,
const std::string & commit_hash ) const

Sets merge state (for conflict resolution).

Parameters
branch_nameBranch being merged.
commit_hashCommit being merged.

◆ updateBranchReference()

void svcs::core::RepositoryManager::updateBranchReference ( const std::string & branchName,
const std::string & commitHash ) const

Updates branch reference file with commit hash.

Parameters
branchNameThe name of the branch to update.
commitHashThe commit hash to set as branch head.

◆ updateCommitReferences()

void svcs::core::RepositoryManager::updateCommitReferences ( const std::string & removedCommitHash,
const std::string & newParentHash ) const

Updates commit references when a commit is removed.

Parameters
removedCommitHashThe hash of the commit being removed.
newParentHashThe new parent hash for dependent commits.

◆ updateHead()

void svcs::core::RepositoryManager::updateHead ( const std::string & commit_hash) const

Updates HEAD reference.

Parameters
commit_hashThe commit hash to set as HEAD.

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