SlHelpers
Blob.h
1 // SPDX-License-Identifier: GPL-2.0-only
2 
3 #pragma once
4 
5 #include <string>
6 
7 #include <git2.h>
8 
9 #include "Object.h"
10 
11 namespace SlGit {
12 
16 class Blob : public TypedObject<git_blob> {
17  using GitTy = git_blob;
18 
19  friend class Repo;
20 public:
21  Blob() = delete;
22 
24  std::string content() const noexcept {
25  return std::string(static_cast<const char *>(rawcontent()), rawsize());
26  }
28  std::string_view contentView() const noexcept {
29  return std::string_view(static_cast<const char *>(rawcontent()), rawsize());
30  }
31 
33  GitTy *blob() const noexcept { return typed(); }
34 private:
35  git_object_size_t rawsize() const noexcept { return git_blob_rawsize(blob()); }
36  const void *rawcontent() const noexcept { return git_blob_rawcontent(blob()); }
37 
38  friend class Tag;
39  explicit Blob(const Repo &repo, GitTy *blob) noexcept;
40 };
41 
42 }
Definition: Blob.h:11
Git Object class – base for Blob, Commit, Tag, Tree.
Definition: Object.h:65
std::string_view contentView() const noexcept
Get the content of this Blob (as a string_view)
Definition: Blob.h:28
The most important Git class.
Definition: Repo.h:45
Blob is a representation of a git blob.
Definition: Blob.h:16
git_blob * typed() const noexcept
Get the stored pointer typed to one of libgit2&#39;s types.
Definition: Object.h:83
GitTy * blob() const noexcept
Get the stored pointer to libgit2&#39;s git_blob.
Definition: Blob.h:33
const Repo & repo() const
Get the Repo this Object lives in.
Definition: Object.h:38
std::string content() const noexcept
Get the content of this Blob (as a string)
Definition: Blob.h:24