This repository was archived by the owner on Jan 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathoid.cpp
More file actions
72 lines (55 loc) · 1.84 KB
/
Copy pathoid.cpp
File metadata and controls
72 lines (55 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <cppgit2/oid.hpp>
#include <iostream>
namespace cppgit2 {
oid::oid() {}
oid::oid(const std::string &hex_string) {
if (git_oid_fromstr(&c_struct_, hex_string.c_str()))
throw git_exception();
}
oid::oid(const std::string &hex_string, size_t length) {
if (git_oid_fromstrn(&c_struct_, hex_string.c_str(), length))
throw git_exception();
}
oid::oid(const git_oid *c_ptr) {
// Convert git_oid * to string and construct this oid
size_t n = GIT_OID_HEXSZ;
std::string buffer(n, '0');
if (!git_oid_tostr(const_cast<char *>(buffer.c_str()), n + 1, c_ptr))
throw git_exception();
// Construct from string
if (git_oid_fromstr(&c_struct_, buffer.c_str()))
throw git_exception();
}
oid::oid(const unsigned char *raw) { git_oid_fromraw(&c_struct_, raw); }
int oid::compare(const oid &rhs) const {
return git_oid_cmp(&c_struct_, rhs.c_ptr());
}
int oid::compare(const oid &rhs, size_t length) const {
return git_oid_ncmp(&c_struct_, rhs.c_ptr(), length);
}
oid oid::copy() const {
oid result;
git_oid_cpy(&result.c_struct_, &c_struct_);
return result;
}
bool oid::is_zero() const { return git_oid_iszero(&c_struct_); }
bool oid::operator==(const oid &rhs) const {
return git_oid_equal(&c_struct_, rhs.c_ptr());
}
bool oid::operator==(const std::string &rhs) const {
return git_oid_streq(&c_struct_, rhs.c_str()) ? false : true;
}
std::string oid::to_hex_string(size_t n) const {
std::string result(n, '0');
if (!git_oid_tostr(const_cast<char *>(result.c_str()), n + 1, &c_struct_))
throw git_exception();
return result;
}
std::string oid::to_path_string() const {
std::string result(GIT_OID_HEXSZ + 1, '0');
git_oid_pathfmt(const_cast<char *>(result.c_str()), &c_struct_);
return result;
}
git_oid *oid::c_ptr() { return &c_struct_; }
const git_oid *oid::c_ptr() const { return &c_struct_; }
} // namespace cppgit2