SVCS - Русская документация
Загрузка...
Поиск...
Не найдено
BranchManager.hxx
См. документацию.
1
20
21#pragma once
22
24
25#include <string>
26#include <utility>
27#include <vector>
28#include <memory>
29#include <unordered_map>
30
43 */
44namespace svcs::core {
45
46using namespace svcs::services;
47
49 * @english
50 * @class BranchManager
51 * @brief Core service for managing version control branches (creation, deletion, switching).
52 * @details This class abstracts the details of branch storage and provides a
53 * high-level interface for branch manipulation. It uses an internal map to
54 * track branches and communicates status/errors via the ISubject event bus.
55 *
56 * @russian
57 * @class BranchManager
58 * @brief Основной сервис для управления ветвями системы контроля версий (создание, удаление, переключение).
59 * @details Этот класс абстрагирует детали хранения ветвей и предоставляет высокоуровневый
60 * интерфейс для манипулирования ветвями. Он использует внутреннюю карту для отслеживания ветвей
61 * и передает статус/ошибки через шину событий ISubject.
62 *
63 * @ingroup Core
64 */
65class BranchManager {
66public:
76 struct Branch {
78
79
84 std::string name;
85
93 std::string head_commit;
94
102 bool is_current;
103
111 Branch() : name(""), head_commit(""), is_current(false) {}
112
126 Branch(std::string name, std::string head_commit, bool is_current = false)
127 : name(std::move(name)), head_commit(std::move(head_commit)), is_current(is_current) {}
128 };
129
139 explicit BranchManager(std::shared_ptr<ISubject> event_bus);
140
149
150 // --- Public Branch Operations / Публичные операции с ветвями ---
151
163 bool createBranch(const std::string& name);
164
178 bool createBranchFromCommit(const std::string& name, const std::string& commit_hash);
179
189 std::string getHeadCommit();
190
206 bool deleteBranch(const std::string& name, bool force = false);
207
221 bool renameBranch(const std::string& old_name, const std::string& new_name);
222
238 bool switchBranch(const std::string& name);
239
240 // --- Public Branch Queries / Публичные запросы о ветвях ---
241
251 std::vector<Branch> getAllBranches() const;
252
262 std::string getCurrentBranch() const;
263
277 bool updateBranchHead(const std::string& branch_name, const std::string& commit_hash);
278
290 bool branchExists(const std::string& name) const;
291
293
303 std::string getBranchHead(const std::string& branch_name) const;
304
305 // --- Public Utility Methods / Публичные служебные методы ---
306
318 static bool isValidBranchName(const std::string& name);
319
331 static bool commitExists(const std::string& commit_hash);
332
333private:
334 // --- Private Persistence Methods / Приватные методы сохранения состояния ---
335
343 void loadBranches();
344
352 void saveBranches();
353
365 static void saveBranchToFile(const std::string &branch_name, const std::string &commit_hash);
366
376 static void deleteBranchFile(const std::string &branch_name);
377
385 void loadCurrentBranch();
386
396 bool saveCurrentBranch() const;
397
398 // --- Private File System Abstraction Methods / Приватные методы абстракции файловой системы ---
399
411 static std::string readFile(const std::string& path);
412
424 static void writeFile(const std::string& path, const std::string& content);
425
437 static bool fileExists(const std::string& path);
438
448 static void createDirectory(const std::string& path);
449
450 // --- Private Path Generation Methods / Приватные методы генерации путей ---
451
461 static std::string getBranchesFilePath();
462
472 static std::string getHeadFilePath();
473
483 static std::string getBranchesDirectory();
484
492 std::unordered_map<std::string, Branch> branches;
493
501 std::string current_branch;
502
510 std::shared_ptr<ISubject> event_bus;
511};
512
513}
Определяет интерфейс для компонента Subject (Издатель) шаблона Observer.
std::string getBranchHead(const std::string &branch_name) const
Извлекает хеш коммита, на который указывает конкретная ветвь.
Определения BranchManager.cxx:273
bool renameBranch(const std::string &old_name, const std::string &new_name)
Переименовывает существующую ветвь.
Определения BranchManager.cxx:137
BranchManager(std::shared_ptr< ISubject > event_bus)
Конструирует BranchManager.
Определения BranchManager.cxx:21
static bool isValidBranchName(const std::string &name)
Проверяет, является ли заданная строка допустимым именем для новой ветви.
Определения BranchManager.cxx:290
std::vector< Branch > getAllBranches() const
Извлекает список всех известных ветвей, включая их состояние.
Определения BranchManager.cxx:233
bool createBranchFromCommit(const std::string &name, const std::string &commit_hash)
Создает новую ветвь из определенного коммита.
Определения BranchManager.cxx:56
bool branchExists(const std::string &name) const
Проверяет, существует ли ветвь с заданным именем.
Определения BranchManager.cxx:269
std::string getCurrentBranch() const
Извлекает имя текущей активной ветви.
Определения BranchManager.cxx:265
std::string getHeadCommit()
Получает хеш коммита текущего HEAD.
Определения BranchManager.cxx:249
void createDefaultBranches()
Создает начальный набор ветвей по умолчанию (например, 'main').
Определения BranchManager.cxx:32
static bool commitExists(const std::string &commit_hash)
Проверяет, существует ли коммит (реализация, предположительно, проверяет хранилище объектов).
Определения BranchManager.cxx:313
bool deleteBranch(const std::string &name, bool force=false)
Удаляет существующую ветвь.
Определения BranchManager.cxx:104
bool switchBranch(const std::string &name)
Переключает активную ветвь на указанное имя.
Определения BranchManager.cxx:214
bool updateBranchHead(const std::string &branch_name, const std::string &commit_hash)
Обновляет хеш коммита, на который указывает указанная ветвь.
Определения BranchManager.cxx:191
bool createBranch(const std::string &name)
Создает новую ветвь, указывающую на определенный коммит (обычно HEAD).
Определения BranchManager.cxx:43
Основные структуры данных СКВ и модель объектов.
Компоненты сервисного слоя и инфраструктурные сервисы.
Branch()
Конструктор по умолчанию
Определения BranchManager.hxx:68
std::string head_commit
Хеш последнего коммита в этой ветви.
Определения BranchManager.hxx:58
bool is_current
Флаг, указывающий, является ли это текущей активной ветвью.
Определения BranchManager.hxx:63
std::string name
Уникальное имя ветви.
Определения BranchManager.hxx:53