SlHelpers
Loading...
Searching...
No Matches
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
11namespace SlGit {
12
16class Blob : public TypedObject<git_blob> {
17 using GitTy = git_blob;
18
19 friend class Repo;
20public:
21 Blob() = delete;
22
24 std::string content() const noexcept {
25 return std::string(static_cast<const char *>(rawcontent()), rawsize());
26 }
27
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(); }
34private:
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}
std::string_view contentView() const noexcept
Get the content of this Blob (as a string_view).
Definition Blob.h:28
GitTy * blob() const noexcept
Get the stored pointer to libgit2's git_blob.
Definition Blob.h:33
std::string content() const noexcept
Get the content of this Blob (as a string).
Definition Blob.h:24
const Repo & repo() const
Get the Repo this Object lives in.
Definition Object.h:38
git_blob * typed() const noexcept
Definition Object.h:83