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 pathstatus.hpp
More file actions
154 lines (128 loc) · 4.23 KB
/
Copy pathstatus.hpp
File metadata and controls
154 lines (128 loc) · 4.23 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#pragma once
#include <cppgit2/bitmask_operators.hpp>
#include <cppgit2/libgit2_api.hpp>
#include <cppgit2/ownership.hpp>
#include <cppgit2/strarray.hpp>
#include <cppgit2/tree.hpp>
#include <git2.h>
namespace cppgit2 {
class status : public libgit2_api {
public:
// Status flags for a single file.
//
// The `index_` set of flags
// represents the status of file in the index relative to the HEAD
//
// `wt_` set of flags represent the status of the file in the
// working directory relative to the index.
enum class status_type {
current = 0,
index_new = (1u << 0),
index_modified = (1u << 1),
index_deleted = (1u << 2),
index_renamed = (1u << 3),
index_typechange = (1u << 4),
wt_new = (1u << 7),
wt_modified = (1u << 8),
wt_deleted = (1u << 9),
wt_typechange = (1u << 10),
wt_renamed = (1u << 11),
wt_unreadable = (1u << 12),
ignored = (1u << 14),
conflicted = (1u << 15)
};
// Select the files on which to report status
enum class show { index_and_workdir = 0, index_only = 1, workdir_only = 2 };
class options : public libgit2_api {
public:
options() {
auto ret = git_status_init_options(&default_options_,
GIT_STATUS_OPTIONS_VERSION);
c_ptr_ = &default_options_;
if (ret != 0)
throw git_exception();
}
options(git_status_options *c_ptr) : c_ptr_(c_ptr) {}
// Version
unsigned int version() const { return c_ptr_->version; }
void set_version(unsigned int value) { c_ptr_->version = value; }
// Show setting
status::show show() const {
return static_cast<status::show>(c_ptr_->show);
}
void set_show(status::show value) {
c_ptr_->show = static_cast<git_status_show_t>(value);
}
enum class flag {
include_untracked = (1u << 0),
include_ignored = (1u << 1),
include_unmodified = (1u << 2),
exclude_submodules = (1u << 3),
recurse_untracked_dirs = (1u << 4),
disable_pathspec_match = (1u << 5),
recurse_ignored_dirs = (1u << 6),
renames_head_to_index = (1u << 7),
renames_index_to_workdir = (1u << 8),
sort_case_sensitively = (1u << 9),
sort_case_insensitively = (1u << 10),
renames_from_rewrites = (1u << 11),
no_refresh = (1u << 12),
update_index = (1u << 13),
include_unreadable = (1u << 14),
include_unreadable_as_untracked = (1u << 15)
};
// Flags
flag flags() const { return static_cast<flag>(c_ptr_->flags); }
void set_flags(flag value) {
c_ptr_->flags = static_cast<unsigned int>(value);
}
// Pathspec
strarray pathspec() const { return strarray(&c_ptr_->pathspec); }
void set_pathspec(const strarray &value) {
c_ptr_->pathspec = *(value.c_ptr());
}
// Baseline tree
tree baseline() const { return tree(c_ptr_->baseline); }
void set_baseline(const tree &baseline_tree) {
c_ptr_->baseline = const_cast<git_tree *>(baseline_tree.c_ptr());
}
// Access libgit2 C ptr
const git_status_options *c_ptr() const { return c_ptr_; }
private:
friend status;
git_status_options *c_ptr_;
git_status_options default_options_;
};
class entry : public libgit2_api {
public:
entry(const git_status_entry *c_ptr) : c_ptr_(c_ptr) {}
private:
const git_status_entry *c_ptr_;
};
class list : public libgit2_api {
public:
list() : c_ptr_(nullptr), owner_(ownership::libgit2) {}
list(git_status_list *c_ptr, ownership owner = ownership::libgit2)
: c_ptr_(c_ptr), owner_(owner) {}
~list() {
if (c_ptr_ && owner_ == ownership::user)
git_status_list_free(c_ptr_);
}
// Get one of the entries in the status list.
// The entry is not modifiable and should not be freed.
const entry operator[](size_t index) const {
return entry(git_status_byindex(c_ptr_, index));
}
// Gets the count of status entries in this list.
size_t size() const { return git_status_list_entrycount(c_ptr_); }
private:
friend class status;
friend class repository;
ownership owner_;
git_status_list *c_ptr_;
};
private:
};
ENABLE_BITMASK_OPERATORS(status::status_type);
ENABLE_BITMASK_OPERATORS(status::options::flag);
} // namespace cppgit2