SVCS - English Documentation
Loading...
Searching...
No Matches
svcs::core::Commit Class Reference

Represents a single, immutable historical point (snapshot) in the repository's history. More...

#include <Commit.hxx>

Inheritance diagram for svcs::core::Commit:
svcs::core::VcsObject

Public Member Functions

 Commit ()
 Default constructor.
 Commit (std::string thash, std::vector< std::string > phashes, std::string auth, std::string msg, std::time_t tstamp=std::time(nullptr))
 Main constructor for the Commit object.
std::string getType () const override
 Returns the type of the VCS object.
std::string serialize () const override
 Serializes the Commit metadata into a standardized, canonical format for hashing and storage.
const std::string & getTreeHash () const
 Returns the hash ID of the associated root Tree object.
const std::vector< std::string > & getParentHashes () const
 Returns the hash IDs of the parent commits.
const std::string & getAuthor () const
 Returns the author and email string for the commit.
std::time_t getTimestamp () const
 Returns the UNIX timestamp of the commit creation.
const std::string & getMessage () const
 Returns the user-defined commit message.
void setMessage (const std::string &msg)
 Sets the commit message.
void setTimestamp (std::time_t tstamp)
 Sets the commit timestamp.
void setTimestampNow ()
 Sets the commit timestamp to the current time.
void setParent (const std::string &parent)
 Sets a parent commit hash.
Public Member Functions inherited from svcs::core::VcsObject
 VcsObject ()=default
 Default constructor. Required for derived classes.
 VcsObject (const VcsObject &other)=default
 Copy constructor. Required for derived classes to correctly copy the hash_id.
virtual ~VcsObject ()=default
 Virtual destructor.
std::string getHashId () const
 Returns the unique hash identifier of the object.

Static Public Member Functions

static Commit deserialize (const std::string &raw_content)
 Creates a Commit object from a serialized string read from the object database.
Static Public Member Functions inherited from svcs::core::VcsObject
static std::string calculateHash (const std::string &content)
 Calculates SHA-256 hash for given canonical content.

Additional Inherited Members

Protected Member Functions inherited from svcs::core::VcsObject
void computeHash (const std::string &content)
 Computes the cryptographic hash ID for the object's content.
Protected Attributes inherited from svcs::core::VcsObject
std::string hash_id
 The unique cryptographic hash identifier (e.g., SHA-256) for this object.

Detailed Description

Represents a single, immutable historical point (snapshot) in the repository's history.

This object binds the content structure (Tree hash) with the metadata (author, message, parent history).

Constructor & Destructor Documentation

◆ Commit()

svcs::core::Commit::Commit ( std::string thash,
std::vector< std::string > phashes,
std::string auth,
std::string msg,
std::time_t tstamp = std::time(nullptr) )

Main constructor for the Commit object.

Initializes the metadata fields, sorts the parent hashes for consistency, and immediately computes the object's hash ID.

Parameters
thashHash of the root Tree object.
phashesHashes of the immediate parent commit(s).
authAuthor and email string.
msgUser-defined commit message.
tstampTime when the commit was created (default is current time).

Member Function Documentation

◆ deserialize()

Commit svcs::core::Commit::deserialize ( const std::string & raw_content)
static

Creates a Commit object from a serialized string read from the object database.

Parameters
raw_contentThe serialized string data, typically read from a decompressed object file.
Returns
Commit A fully reconstructed Commit object.

◆ getAuthor()

const std::string & svcs::core::Commit::getAuthor ( ) const
nodiscard

Returns the author and email string for the commit.

Returns
const std::string& The author string.

◆ getMessage()

const std::string & svcs::core::Commit::getMessage ( ) const
nodiscard

Returns the user-defined commit message.

Returns
const std::string& The commit message.

◆ getParentHashes()

const std::vector< std::string > & svcs::core::Commit::getParentHashes ( ) const
nodiscard

Returns the hash IDs of the parent commits.

Returns
const std::vector<std::string>& The list of parent hashes (sorted).

◆ getTimestamp()

std::time_t svcs::core::Commit::getTimestamp ( ) const
nodiscard

Returns the UNIX timestamp of the commit creation.

Returns
std::time_t The timestamp value.

◆ getTreeHash()

const std::string & svcs::core::Commit::getTreeHash ( ) const
nodiscard

Returns the hash ID of the associated root Tree object.

Returns
const std::string& The tree hash.

◆ getType()

std::string svcs::core::Commit::getType ( ) const
nodiscardoverridevirtual

Returns the type of the VCS object.

Returns
std::string Always returns "commit". Pure virtual method to get the type of the VCS object.

This is crucial for object storage and reconstruction (e.g., "commit", "blob", "tree").

Returns
std::string The type identifier of the object.

Implements svcs::core::VcsObject.

◆ serialize()

std::string svcs::core::Commit::serialize ( ) const
nodiscardoverridevirtual

Serializes the Commit metadata into a standardized, canonical format for hashing and storage.

The serialized format includes key/value pairs (tree, parent, author) followed by the message.

Returns
std::string The standardized, serialized commit data. Pure virtual method to serialize the object's core data.

The returned string content is what will be hashed and stored in the database.

Returns
std::string The standardized, serialized data of the object.

Implements svcs::core::VcsObject.

◆ setMessage()

void svcs::core::Commit::setMessage ( const std::string & msg)

Sets the commit message.

Parameters
msgThe new commit message.

◆ setParent()

void svcs::core::Commit::setParent ( const std::string & parent)

Sets a parent commit hash.

Parameters
parentThe parent commit hash.

◆ setTimestamp()

void svcs::core::Commit::setTimestamp ( std::time_t tstamp)

Sets the commit timestamp.

Parameters
tstampThe new timestamp value.

The documentation for this class was generated from the following files: