SVCS - English Documentation
Loading...
Searching...
No Matches
Repository.hxx
Go to the documentation of this file.
1
21#pragma once
22
24#include "ObjectStorage.hxx"
25#include "Index.hxx"
26
27#include <string>
28#include <vector>
29#include <memory>
30#include <filesystem>
31
40 * @namespace svcs::core
41 * @brief Основные структуры данных СКВ и модель объектов.
42 * @details Содержит фундаментальные типы объектов СКВ, такие как Blob, Tree, Commit,
43 * которые формируют строительные блоки системы контроля версий.
44 */
45namespace svcs::core {
46
58class Repository : public ISubject {
59private:
67 const std::filesystem::path root_path;
68
76 std::unique_ptr<ObjectStorage> objects;
77
87 std::vector<std::weak_ptr<IObserver>> observers;
88
96 std::unique_ptr<Index> index;
97
98public:
108 ~Repository() override;
109
119 explicit Repository(std::filesystem::path rpath);
120
131
141 bool init();
142
152 [[nodiscard]] bool is_initialized() const;
153
163 [[nodiscard]] const std::filesystem::path& getPath() const { return root_path; }
164
174 [[nodiscard]] ObjectStorage* getObjectStorage() const { return objects.get(); }
175
185 void attach(std::shared_ptr<IObserver> observer) override;
186
196 void detach(std::shared_ptr<IObserver> observer) override;
197
207 void notify(const Event& event) const override;
208
220 static std::shared_ptr<Repository> findRepository(const std::string& start_path = ".");
221
233 static bool isRepository(const std::string& path);
234
250 bool stageFile(const std::string& path);
251};
252
253}
Defines the interface for the Subject (Publisher) component of the Observer pattern.
Definition of IndexEntry data structure and Index struct.
Manages the reading, writing, and lifecycle of VCS objects on the disk using the Git format.
Manages the version control object database, including persistence and object restoration.
Definition ObjectStorage.hxx:40
~Repository() override
Virtual destructor.
Definition Repository.cxx:28
void detach(std::shared_ptr< IObserver > observer) override
Detaches a registered observer.
Definition Repository.cxx:142
const std::filesystem::path & getPath() const
Gets the root path of the repository.
Definition Repository.hxx:108
ObjectStorage * getObjectStorage() const
Gets the raw pointer to the managed ObjectStorage instance for database interaction.
Definition Repository.hxx:115
void notify(const Event &event) const override
Notifies all attached observers about an event.
Definition Repository.cxx:154
void initializeDependencies()
Initializes the repository's internal dependencies.
Definition Repository.cxx:40
Repository(std::filesystem::path rpath)
Constructs the repository manager.
Definition Repository.cxx:33
bool stageFile(const std::string &path)
Stages a file by hashing its content, storing it in the object database, and updating the staging ind...
Definition Repository.cxx:210
static std::shared_ptr< Repository > findRepository(const std::string &start_path=".")
Statically searches for an existing repository starting from a given path and moving up.
Definition Repository.cxx:167
bool is_initialized() const
Checks if the repository structure is fully initialized and valid.
Definition Repository.cxx:117
void attach(std::shared_ptr< IObserver > observer) override
Attaches an observer to receive events.
Definition Repository.cxx:131
bool init()
Initializes the basic repository structure (.svcs, objects, refs) on the disk.
Definition Repository.cxx:46
static bool isRepository(const std::string &path)
Statically checks if a given path is the root of an SVCS repository.
Definition Repository.cxx:195
The Subject (Publisher) Interface (Abstract Base Class).
Definition ISubject.hxx:38
Core VCS data structures and object model.