SlHelpers
Loading...
Searching...
No Matches
Commit.h
1// SPDX-License-Identifier: GPL-2.0-only
2
3#pragma once
4
5#include <optional>
6#include <string>
7
8#include <git2.h>
9
10#include "Helpers.h"
11#include "Object.h"
12
13namespace SlGit {
14
15class Repo;
16class Tree;
17
21class Commit : public TypedObject<git_commit> {
22 using GitTy = git_commit;
23
24 friend class Repo;
25public:
26 Commit() = delete;
27
29 std::optional<Commit> parent(unsigned int nth = 0) const noexcept;
31 std::optional<Commit> ancestor(unsigned int nth = 0) const noexcept;
32
34 std::optional<Tree> tree() const noexcept;
35
37 const git_oid *treeId() const noexcept { return git_commit_tree_id(commit()); }
39 std::string treeIdStr() const noexcept { return Helpers::oidToStr(*treeId()); }
41 std::string messageEncoding() const noexcept {
42 return git_commit_message_encoding(commit());
43 }
44
45 std::string message() const noexcept { return git_commit_message(commit()); }
47 std::string summary() const noexcept { return git_commit_summary(commit()); }
49 git_time_t time() const noexcept { return git_commit_time(commit()); }
51 int timeOffset() const noexcept { return git_commit_time_offset(commit()); }
53 const git_signature *committer() const noexcept { return git_commit_committer(commit()); }
55 const git_signature *author() const noexcept { return git_commit_author(commit()); }
57 std::string rawHeader() const noexcept { return git_commit_raw_header(commit()); }
58
60 unsigned int parentCount() const noexcept { return git_commit_parentcount(commit()); }
62 const git_oid *parentId(unsigned int nth) const noexcept {
63 return git_commit_parent_id(commit(), nth);
64 }
65
67 std::optional<std::string> catFile(const std::string &file) const noexcept;
68
70 GitTy *commit() const noexcept { return typed(); }
72 operator GitTy *() const noexcept { return commit(); }
73private:
74 friend class Tag;
75 explicit Commit(const Repo &repo, GitTy *commit) noexcept :
77};
78
79}
Commit is a representation of a git commit.
Definition Commit.h:21
std::string summary() const noexcept
Get the summary line of this Commit.
Definition Commit.h:47
git_time_t time() const noexcept
Get the time of this Commit.
Definition Commit.h:49
const git_signature * author() const noexcept
Get the author of this Commit.
Definition Commit.h:55
std::string rawHeader() const noexcept
Get a raw Commit header.
Definition Commit.h:57
const git_oid * treeId() const noexcept
Get the OID of the tree of this Commit.
Definition Commit.h:37
std::string messageEncoding() const noexcept
Get the commit message encoding of this Commit.
Definition Commit.h:41
std::string treeIdStr() const noexcept
Get the SHA of the tree of this Commit.
Definition Commit.h:39
std::optional< std::string > catFile(const std::string &file) const noexcept
Cat a file in this Commit's tree.
unsigned int parentCount() const noexcept
Get count of parents.
Definition Commit.h:60
int timeOffset() const noexcept
Get the timezone offset of this Commit.
Definition Commit.h:51
const git_oid * parentId(unsigned int nth) const noexcept
Get OID of the nth parent.
Definition Commit.h:62
GitTy * commit() const noexcept
Get the stored pointer to libgit2's git_commit.
Definition Commit.h:70
std::optional< Tree > tree() const noexcept
Get the Tree of this Commit.
std::optional< Commit > parent(unsigned int nth=0) const noexcept
Get the nth parent of this Commit.
const git_signature * committer() const noexcept
Get the committer of this Commit.
Definition Commit.h:53
std::optional< Commit > ancestor(unsigned int nth=0) const noexcept
Get the nth generation ancestor of this Commit.
std::string message() const noexcept
Get the commit message of this Commit.
Definition Commit.h:45
static std::string oidToStr(const git_oid &id)
Convert OID id to string.
Definition Helpers.h:20
const Repo & repo() const
Get the Repo this Object lives in.
Definition Object.h:38
The most important Git class.
Definition Repo.h:45
Tag is a representation of a git tag.
Definition Tag.h:23
Tree is a representation of a git tree.
Definition Tree.h:27
Git Object class – base for Blob, Commit, Tag, Tree.
Definition Object.h:65
git_commit * typed() const noexcept
Definition Object.h:83