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
10namespace SlGit {
11
15class Helpers {
16public:
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}
static std::optional< git_oid > strToOid(std::string_view sv)
Convert string sv to git_oid.
Definition Helpers.h:27
static std::string oidToStr(const git_oid &id)
Convert OID id to string.
Definition Helpers.h:20