SVCS - English Documentation
Loading...
Searching...
No Matches
RemoteManager.hxx
Go to the documentation of this file.
1
21#pragma once
22
23#include <string>
24#include <unordered_map>
25#include <vector>
26#include <filesystem>
27#include <functional>
28
42 * обработку удаленных протоколов, управление пользователями и команды администрирования сервера.
43 * Это пространство имен инкапсулирует все серверные операции, которые обеспечивают
44 * многопользовательское сотрудничество и хостинг удаленных репозиториев.
45 */
46namespace svcs::server {
48namespace fs = std::filesystem;
49
63struct Remote {
67 *
68 * @russian
69 * @brief Короткое имя удаленного репозитория (например, "origin").
70 */
71 std::string name;
72
79 */
80 std::string url;
81
89 std::string fetch_spec;
90
102 Remote(const std::string& name, const std::string& url) :
103 name(name), url(url), fetch_spec("+refs/heads/*:refs/remotes/" + name + "/*") {}
104};
105
121class RemoteManager {
122private:
130 std::unordered_map<std::string, Remote> remotes_;
131
139 fs::path config_path_;
140
141public:
157 explicit RemoteManager(const fs::path& repo_path);
158
168
174 bool addRemote(const std::string& name, const std::string& url);
175
187 bool removeRemote(const std::string& name);
188
200 bool hasRemote(const std::string& name) const;
201
213 std::string getRemoteUrl(const std::string& name) const;
214
224 std::vector<std::string> listRemotes() const;
225
237 void save() const;
238
250 void load();
251
261 size_t count() const { return remotes_.size(); }
262};
263
264}
void save() const
Saves the current remote configurations back to the config file.
Definition RemoteManager.cxx:75
RemoteManager(const fs::path &repo_path)
Constructs a RemoteManager and loads existing remotes.
Definition RemoteManager.cxx:25
bool hasRemote(const std::string &name) const
Checks if a remote with the given name exists.
Definition RemoteManager.cxx:55
std::string getRemoteUrl(const std::string &name) const
Gets the URL of a configured remote.
Definition RemoteManager.cxx:59
std::vector< std::string > listRemotes() const
Lists the names of all configured remotes.
Definition RemoteManager.cxx:67
void load()
Loads (or reloads) the remote configurations from the config file.
Definition RemoteManager.cxx:89
size_t count() const
Gets the number of configured remotes.
Definition RemoteManager.hxx:166
bool removeRemote(const std::string &name)
Removes a remote configuration by name.
Definition RemoteManager.cxx:44
bool addRemote(const std::string &name, const std::string &url)
Adds a new remote configuration.
Definition RemoteManager.cxx:30
Server-side components and administration commands.
Remote(const std::string &name, const std::string &url)
Constructs a Remote struct.
Definition RemoteManager.hxx:67
std::string name
The shortname of the remote (e.g., "origin").
Definition RemoteManager.hxx:47
std::string url
The URL (path or network address) of the remote.
Definition RemoteManager.hxx:53
std::string fetch_spec
The refspec defining what to fetch (e.g., "+refs/heads/*:refs/remotes/origin/*").
Definition RemoteManager.hxx:59