SlHelpers
Tag.h
1 // SPDX-License-Identifier: GPL-2.0-only
2 
3 #pragma once
4 
5 #include <string>
6 
7 #include <git2.h>
8 #include <variant>
9 
10 #include "Helpers.h"
11 #include "Object.h"
12 
13 namespace SlGit {
14 
15 class Blob;
16 class Commit;
17 class Repo;
18 class Tree;
19 
23 class Tag : public TypedObject<git_tag> {
24  using GitTy = git_tag;
25 
26  friend class Repo;
27 public:
28  Tag() = delete;
29 
31  const git_oid *targetId() const noexcept { return git_tag_target_id(tag()); }
33  std::string targetIdStr() const noexcept { return Helpers::oidToStr(*targetId()); }
35  git_object_t targetType() const noexcept { return git_tag_target_type(tag()); }
36 
38  std::string name() const noexcept { return git_tag_name(tag()); }
40  const git_signature *tagger() const noexcept { return git_tag_tagger(tag()); }
42  std::string message() const noexcept { return git_tag_message(tag()); }
43 
45  std::variant<std::monostate, Commit, Tree, Blob> peel() const noexcept;
46 
48  GitTy *tag() const noexcept { return typed(); }
49 private:
50  explicit Tag(const Repo &repo, GitTy *tag) noexcept;
51 };
52 
53 }
Definition: Blob.h:11
std::string message() const noexcept
Get the tag message of this Tag.
Definition: Tag.h:42
const git_signature * tagger() const noexcept
Get the tagger of this Tag.
Definition: Tag.h:40
git_object_t targetType() const noexcept
Get the type of the target of this Tag (GIT_OBJECT_COMMIT, ...)
Definition: Tag.h:35
Git Object class – base for Blob, Commit, Tag, Tree.
Definition: Object.h:65
static std::string oidToStr(const git_oid &id)
Convert OID id to string.
Definition: Helpers.h:20
The most important Git class.
Definition: Repo.h:45
GitTy * tag() const noexcept
Get the stored pointer to libgit2&#39;s git_tag.
Definition: Tag.h:48
git_tag * typed() const noexcept
Get the stored pointer typed to one of libgit2&#39;s types.
Definition: Object.h:83
std::variant< std::monostate, Commit, Tree, Blob > peel() const noexcept
Peel this Tag until the underlaying object is found and return that.
std::string name() const noexcept
Get the name of this Tag (the tag proper)
Definition: Tag.h:38
Tag is a representation of a git tag.
Definition: Tag.h:23
std::string targetIdStr() const noexcept
Get the SHA of the target of this Tag.
Definition: Tag.h:33
const git_oid * targetId() const noexcept
Get the OID of the target of this Tag.
Definition: Tag.h:31
const Repo & repo() const
Get the Repo this Object lives in.
Definition: Object.h:38