SlHelpers
Loading...
Searching...
No Matches
Helpers.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
namespace
SlGit {
11
15
class
Helpers {
16
public
:
17
Helpers() =
delete
;
18
20
static
std::string
oidToStr
(
const
git_oid &
id
) {
21
std::string s(GIT_OID_MAX_HEXSIZE,
'\0'
);
22
git_oid_tostr(s.data(), s.size() + 1, &
id
);
23
return
s;
24
}
25
27
static
std::optional<git_oid>
strToOid
(std::string_view sv) {
28
git_oid oid;
29
if
(git_oid_fromstrn(&oid, sv.data(), sv.size()))
30
return
std::nullopt;
31
return
oid;
32
}
33
};
34
35
}
SlGit::Helpers::strToOid
static std::optional< git_oid > strToOid(std::string_view sv)
Convert string sv to git_oid.
Definition
Helpers.h:27
SlGit::Helpers::oidToStr
static std::string oidToStr(const git_oid &id)
Convert OID id to string.
Definition
Helpers.h:20
include
git
Helpers.h
Generated by
1.16.1