SVCS - English Documentation
Loading...
Searching...
No Matches
RepositoryManager.hxx
Go to the documentation of this file.
1
20
21#pragma once
22
24
25#include <optional>
26#include <string>
27#include <filesystem>
28#include <vector>
29#include <memory>
30
38 * @russian
39 * @namespace svcs::core
40 * @brief Основные структуры данных СКВ и модель объектов.
41 * @details Содержит фундаментальные типы объектов СКВ, такие как Blob, Tree, Commit,
42 * которые формируют строительные блоки системы контроля версий.
43 */
44namespace svcs::core {
45
46using namespace svcs::services;
47
57struct CommitInfo {
65 std::string hash;
66
74 std::string message;
75
83 int files_count = 0;
84
92 std::string author;
93
101 std::string timestamp;
102
110 std::string branch;
111};
112
128class RepositoryManager {
129private:
137 std::string currentRepoPath;
138
146 std::shared_ptr<ISubject> eventBus;
147
148 // --- Private Utility Methods for Logging / Приватные служебные методы для логирования ---
149
159 void logError(const std::string& message) const;
160
170 void logDebug(const std::string& message) const;
171
181 void logInfo(const std::string& message) const;
182
183 // --- Private Utility Methods for File System Operations / Приватные служебные методы для операций с файловой системой ---
184
196 bool createDirectory(const std::filesystem::path& path) const;
197
211 bool createFile(const std::filesystem::path& path, const std::string& content = "") const;
212
222 std::string getCurrentBranchFromHead() const;
223
224public:
234 explicit RepositoryManager(std::shared_ptr<ISubject> bus);
235
245 void updateHead(const std::string& commit_hash) const;
246
262 bool initializeRepository(const std::string& path, bool force = false);
263
275 bool isRepositoryInitialized(const std::string& path = ".");
276
288 void updateBranchReference(const std::string& branchName, const std::string& commitHash) const;
289
299 [[nodiscard]] std::filesystem::path getRepositoryPath() const;
300
301 // --- Staging and History Management Methods / Методы управления подготовкой и историей ---
302
316 bool addFileToStaging(const std::string& filePath);
317
327 std::string getHeadCommit() const;
328
340 std::string createCommit(const std::string& message);
341
353 void updateCommitReferences(const std::string& removedCommitHash, const std::string& newParentHash) const;
354
368 bool revertCommit(const std::string& commit_hash);
369
381 std::optional<CommitInfo> getCommitByHash(const std::string& commit_hash) const;
382
394 std::string getParentCommitHash(const std::string& commit_hash) const;
395
407 static std::string generateCommitHash(const std::string& content);
408
420 bool restoreFilesFromCommit(const CommitInfo& commit) const;
421
431 bool clearStagingArea();
432
444 bool saveStagedChanges(const std::string& message);
445
455 std::vector<std::string> getStagedFiles();
456
466 std::vector<CommitInfo> getCommitHistory() const;
467
479 std::vector<CommitInfo> getBranchHistory(const std::string& branch_name) const;
480
490 std::string getCurrentBranch() const;
491
503 bool removeRepository(const std::filesystem::path& path) const;
504
516 bool branchExists(const std::string& branch_name) const;
517
529 std::string getBranchHead(const std::string& branch_name) const;
530
544 std::string getFileContentAtCommit(const std::string& commit_hash, const std::string& file_path) const;
545
557 std::vector<std::string> getCommitFiles(const std::string& commit_hash) const;
558
570 void setMergeState(const std::string& branch_name, const std::string& commit_hash) const;
571
579 void clearMergeState() const;
580
590 bool isMergeInProgress() const;
591
601 std::string getMergeBranch() const;
602};
603
604}
Defines the interface for the Subject (Publisher) component of the Observer pattern.
Manages all physical file and directory operations within the SVCS repository.
Definition RepositoryManager.hxx:83
std::vector< std::string > getStagedFiles()
Retrieves a list of all files currently marked as staged (indexed).
Definition RepositoryManager.cxx:366
std::string getHeadCommit() const
Retrieves the hash of the current HEAD commit in the repository.
Definition RepositoryManager.cxx:775
void updateBranchReference(const std::string &branchName, const std::string &commitHash) const
Updates branch reference file with commit hash.
Definition RepositoryManager.cxx:260
std::string getCurrentBranch() const
Gets the current branch name.
Definition RepositoryManager.cxx:892
std::string getParentCommitHash(const std::string &commit_hash) const
Retrieves the hash of the parent commit for a given commit.
Definition RepositoryManager.cxx:542
std::string getBranchHead(const std::string &branch_name) const
Gets the head commit of a branch.
Definition RepositoryManager.cxx:907
std::filesystem::path getRepositoryPath() const
Returns the determined root path of the currently active repository.
Definition RepositoryManager.cxx:1064
void setMergeState(const std::string &branch_name, const std::string &commit_hash) const
Sets merge state (for conflict resolution).
Definition RepositoryManager.cxx:986
bool saveStagedChanges(const std::string &message)
Creates a commit from staged changes. (Convenience method often used by the SaveCommand).
Definition RepositoryManager.cxx:764
void updateCommitReferences(const std::string &removedCommitHash, const std::string &newParentHash) const
Updates commit references when a commit is removed.
Definition RepositoryManager.cxx:581
std::vector< CommitInfo > getCommitHistory() const
Retrieves the complete commit history for the current branch.
Definition RepositoryManager.cxx:816
bool isMergeInProgress() const
Checks if a merge is in progress.
Definition RepositoryManager.cxx:1026
bool isRepositoryInitialized(const std::string &path=".")
Checks if a SVCS repository is initialized in the given path or its parents.
Definition RepositoryManager.cxx:312
bool restoreFilesFromCommit(const CommitInfo &commit) const
Restores the working directory files to the state recorded in a specific commit.
Definition RepositoryManager.cxx:716
std::string createCommit(const std::string &message)
Creates a commit from the currently staged files.
Definition RepositoryManager.cxx:463
std::string getMergeBranch() const
Gets the branch being merged.
Definition RepositoryManager.cxx:1037
void clearMergeState() const
Clears merge state (after merge completion/abort).
Definition RepositoryManager.cxx:1006
RepositoryManager(std::shared_ptr< ISubject > bus)
Constructs a RepositoryManager.
Definition RepositoryManager.cxx:28
bool clearStagingArea()
Clears the contents of the staging area (index).
Definition RepositoryManager.cxx:392
std::vector< std::string > getCommitFiles(const std::string &commit_hash) const
Gets all files changed in a commit.
Definition RepositoryManager.cxx:948
void updateHead(const std::string &commit_hash) const
Updates HEAD reference.
Definition RepositoryManager.cxx:415
static std::string generateCommitHash(const std::string &content)
Generates a commit hash from content.
Definition RepositoryManager.cxx:449
bool addFileToStaging(const std::string &filePath)
Attempts to add a file to the staging area (index).
Definition RepositoryManager.cxx:337
bool initializeRepository(const std::string &path, bool force=false)
Initializes a new SVCS repository in the specified path.
Definition RepositoryManager.cxx:50
bool branchExists(const std::string &branch_name) const
Checks if a branch exists.
Definition RepositoryManager.cxx:896
bool removeRepository(const std::filesystem::path &path) const
Attempts to recursively remove the entire SVCS repository structure (e.g., the .svcs directory) and i...
Definition RepositoryManager.cxx:167
std::optional< CommitInfo > getCommitByHash(const std::string &commit_hash) const
Retrieves the CommitInfo structure for a given commit hash.
Definition RepositoryManager.cxx:704
bool revertCommit(const std::string &commit_hash)
Reverts the repository state to a previous commit.
Definition RepositoryManager.cxx:629
std::string getFileContentAtCommit(const std::string &commit_hash, const std::string &file_path) const
Gets the content of a file at a specific commit.
Definition RepositoryManager.cxx:929
std::vector< CommitInfo > getBranchHistory(const std::string &branch_name) const
Retrieves the commit history for a specific branch.
Definition RepositoryManager.cxx:820
Core VCS data structures and object model.
Service layer components and infrastructure services.
Structure containing essential metadata for a single commit.
Definition RepositoryManager.hxx:38
std::string message
The message provided by the user when creating the commit.
Definition RepositoryManager.hxx:49
std::string branch
The branch this commit belongs to.
Definition RepositoryManager.hxx:73
std::string hash
The unique identifier (hash) of the commit.
Definition RepositoryManager.hxx:43
int files_count
The count of files included in this commit.
Definition RepositoryManager.hxx:55
std::string author
The author or user who created the commit.
Definition RepositoryManager.hxx:61
std::string timestamp
Timestamp of when the commit was created.
Definition RepositoryManager.hxx:67