SVCS - English Documentation
Loading...
Searching...
No Matches
Commit.hxx
Go to the documentation of this file.
1
17#pragma once
18
19#include "VcsObject.hxx"
20
21#include <string>
22#include <vector>
23#include <ctime>
24
35 * @details Содержит фундаментальные типы объектов СКВ, такие как Blob, Tree, Commit,
36 * которые формируют строительные блоки системы контроля версий.
37 */
38namespace svcs::core {
39
51class Commit : public VcsObject {
52private:
60 std::string tree_hash;
61
69 std::vector<std::string> parent_hashes;
70
78 std::string author;
79
87 std::time_t timestamp;
88
96 std::string message;
97
98public:
106 Commit() : tree_hash(""), parent_hashes({}), author(""), timestamp(time_t()), message("") {};
107
127 Commit(
128 std::string thash,
129 std::vector<std::string> phashes,
130 std::string auth,
131 std::string msg,
132 std::time_t tstamp = std::time(nullptr)
133 );
134
135 // VcsObject overrides
136
147 [[nodiscard]] std::string getType() const override;
148
161 [[nodiscard]] std::string serialize() const override;
162
174 static Commit deserialize(const std::string& raw_content);
175
176 // Getters
177
183
187 [[nodiscard]] const std::string& getTreeHash() const;
188
198 [[nodiscard]] const std::vector<std::string>& getParentHashes() const;
199
209 [[nodiscard]] const std::string& getAuthor() const;
210
220 [[nodiscard]] std::time_t getTimestamp() const;
221
231 [[nodiscard]] const std::string& getMessage() const;
232
242 void setMessage(const std::string& msg);
243
253 void setTimestamp(std::time_t tstamp);
254
262 void setTimestampNow();
263
273 void setParent(const std::string& parent);
274};
275
276}
Definition of the abstract base class for all Version Control System objects.
std::time_t getTimestamp() const
Returns the UNIX timestamp of the commit creation.
Definition Commit.cxx:173
std::string getType() const override
Returns the type of the VCS object.
Definition Commit.cxx:43
std::string serialize() const override
Serializes the Commit metadata into a standardized, canonical format for hashing and storage.
Definition Commit.cxx:47
const std::string & getMessage() const
Returns the user-defined commit message.
Definition Commit.cxx:177
const std::string & getTreeHash() const
Returns the hash ID of the associated root Tree object.
Definition Commit.cxx:161
void setTimestamp(std::time_t tstamp)
Sets the commit timestamp.
Definition Commit.cxx:188
void setMessage(const std::string &msg)
Sets the commit message.
Definition Commit.cxx:181
const std::vector< std::string > & getParentHashes() const
Returns the hash IDs of the parent commits.
Definition Commit.cxx:165
static Commit deserialize(const std::string &raw_content)
Creates a Commit object from a serialized string read from the object database.
Definition Commit.cxx:64
void setTimestampNow()
Sets the commit timestamp to the current time.
Definition Commit.cxx:192
void setParent(const std::string &parent)
Sets a parent commit hash.
Definition Commit.cxx:196
Commit()
Default constructor.
Definition Commit.hxx:72
const std::string & getAuthor() const
Returns the author and email string for the commit.
Definition Commit.cxx:169
VcsObject()=default
Default constructor. Required for derived classes.
Core VCS data structures and object model.