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 pathreflog.hpp
More file actions
80 lines (61 loc) · 1.97 KB
/
Copy pathreflog.hpp
File metadata and controls
80 lines (61 loc) · 1.97 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
73
74
75
76
77
78
79
80
#pragma once
#include <cppgit2/git_exception.hpp>
#include <cppgit2/libgit2_api.hpp>
#include <cppgit2/oid.hpp>
#include <cppgit2/ownership.hpp>
#include <cppgit2/signature.hpp>
#include <git2.h>
namespace cppgit2 {
class reflog : public libgit2_api {
public:
// Default construct a reflog
reflog();
// Construct reflog from libgit2 C ptr
// If owned by user, will be free'd in the destructor
// using git_reflog_free
reflog(git_reflog *c_ptr, ownership owner = ownership::libgit2);
// Free reflog if owned by user
~reflog();
// Entry in this reflog
class entry : public libgit2_api {
public:
entry(const git_reflog_entry *c_ptr) : c_ptr_(c_ptr) {}
signature committer() {
return signature(git_reflog_entry_committer(c_ptr_));
}
std::string message() {
auto ret = git_reflog_entry_message(c_ptr_);
if (ret)
return std::string(ret);
else
return "";
}
oid new_oid() { return oid(git_reflog_entry_id_new(c_ptr_)); }
oid old_oid() { return oid(git_reflog_entry_id_old(c_ptr_)); }
const git_reflog_entry *c_ptr() { return c_ptr_; }
private:
const git_reflog_entry *c_ptr_;
};
// Remove entry from reflog by index
// To ensure there's no gap in the log history,
// set rewrite_previous_entry to true
void remove(size_t index, bool rewrite_previous_entry);
// Get the number of log entries in this reflog
size_t size() const;
// Add a new entry to the in-memory reflog
void append(const oid &id, const signature &committer,
const std::string &message = "");
// Lookup an entry by index
// Requesting reflog[0] will return the most recently created entry
entry operator[](size_t index) const;
// Write an existing in-memory reflog object back to disk
// Uses atomic file lock
void write_to_disk();
// Access libgit2 C ptr
const git_reflog *c_ptr() const;
private:
friend class repository;
git_reflog *c_ptr_;
ownership owner_;
};
} // namespace cppgit2