SVCS - English Documentation
Loading...
Searching...
No Matches
Index.hxx
Go to the documentation of this file.
1
13#pragma once
14
16
17#include <filesystem>
18#include <string>
19#include <map>
20
34namespace svcs::core {
36namespace fs = std::filesystem;
37
49struct IndexEntry {
57 std::string blob_hash;
60
66 fs::path file_path;
67
68 /**
69 * @english
70 * @brief The time of the file's last modification, used to detect changes.
71 *
72 * @russian
73 * @brief Время последнего изменения файла, используется для обнаружения изменений.
74 */
75 fs::file_time_type last_modified;
76
84 long long file_size = 0;
85};
86
100class Index {
101private:
109 std::map<fs::path, IndexEntry> entries;
110
118 fs::path index_file_path;
119
127 fs::path repo_root_path;
128
136 ObjectStorage& storage_;
137
151 static void getFileMetaData(const fs::path& full_path,
152 long long& size, fs::file_time_type& mtime);
153
154public:
168 Index(const fs::path& vcs_root_path, fs::path repo_root_path, ObjectStorage& storage);
169
177 ~Index();
178
182
188 void addEntry(const IndexEntry& entry);
189
201 [[nodiscard]] const IndexEntry* getEntry(const fs::path& file_path) const;
202
212 void load();
213
223 void save() const;
224
234 [[nodiscard]] bool write() const;
235
247 [[nodiscard]] bool isFileModified(const fs::path& file_path) const;
248
262 void stage_file(const fs::path& relative_path);
263
277 std::string createTreeObject();
278};
279
280}
Manages the reading, writing, and lifecycle of VCS objects on the disk using the Git format.
Manages the Staging Area (Index) of the VCS repository.
Definition Index.hxx:68
bool isFileModified(const fs::path &file_path) const
Checks if a file in the working directory has been modified since it was last staged.
Definition Index.cxx:101
std::string createTreeObject()
Creates the hierarchical Tree structure based on the current staged entries and saves the Tree object...
Definition Index.cxx:250
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 log...
Definition Index.cxx:68
void save() const
Saves the current state of the index entries to the index file (temporary text format).
Definition Index.cxx:153
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.
Definition Index.cxx:46
const IndexEntry * getEntry(const fs::path &file_path) const
Retrieves an entry from the index by its relative file path.
Definition Index.cxx:60
void addEntry(const IndexEntry &entry)
Adds or updates an entry in the staging area.
Definition Index.cxx:56
~Index()
Destructor.
bool write() const
Another saving function (like load) but returns bool.
Definition Index.cxx:221
void load()
Loads the index entries from the index file on disk (temporary text format).
Definition Index.cxx:175
Manages the version control object database, including persistence and object restoration.
Definition ObjectStorage.hxx:40
Core VCS data structures and object model.
Represents a single file entry in the staging area (Index).
Definition Index.hxx:35
long long file_size
The size of the file in bytes.
Definition Index.hxx:58
fs::path file_path
The file's path, relative to the repository's root directory.
Definition Index.hxx:46
fs::file_time_type last_modified
The time of the file's last modification, used to detect changes.
Definition Index.hxx:52
std::string blob_hash
The SHA-256 hash of the file's content (the Blob object ID).
Definition Index.hxx:40