-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathstatus.cpp
More file actions
105 lines (91 loc) · 2.69 KB
/
Copy pathstatus.cpp
File metadata and controls
105 lines (91 loc) · 2.69 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
#include "git2cpp/status.h"
#include "git2cpp/error.h"
namespace git
{
size_t Status::entrycount() const
{
return git_status_list_entrycount(status_.get());
}
git_status_entry const & Status::operator[](size_t i) const
{
if (auto res = git_status_byindex(status_.get(), i))
return *res;
else
throw error_t("status entry index out of bounds: " + std::to_string(i));
}
namespace
{
git_status_show_t convert(Status::Options::Show show)
{
switch (show)
{
case Status::Options::Show::IndexOnly:
return GIT_STATUS_SHOW_INDEX_ONLY;
case Status::Options::Show::WorkdirOnly:
return GIT_STATUS_SHOW_WORKDIR_ONLY;
default:
return GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
}
}
}
Status::Options::Options(Show show, Sort sort)
: opts_(GIT_STATUS_OPTIONS_INIT)
{
opts_.show = convert(show);
switch (sort)
{
case Sort::CaseSensitively:
opts_.flags |= GIT_STATUS_OPT_SORT_CASE_SENSITIVELY;
break;
case Sort::CaseInsensitively:
opts_.flags |= GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY;
break;
}
}
void Status::Options::set_pathspec(char ** ptr, size_t size)
{
opts_.pathspec.strings = ptr;
opts_.pathspec.count = size;
}
Status::Options & Status::Options::include_untracked()
{
opts_.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED;
return *this;
}
Status::Options & Status::Options::exclude_untracked()
{
opts_.flags &= ~GIT_STATUS_OPT_INCLUDE_UNTRACKED;
return *this;
}
Status::Options & Status::Options::recurse_untracked_dirs()
{
opts_.flags |= GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
return *this;
}
Status::Options & Status::Options::exclude_submodules()
{
opts_.flags |= GIT_STATUS_OPT_EXCLUDE_SUBMODULES;
return *this;
}
Status::Options & Status::Options::include_ignored()
{
opts_.flags |= GIT_STATUS_OPT_INCLUDE_IGNORED;
return *this;
}
Status::Options & Status::Options::renames_head_to_index()
{
opts_.flags |= GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX;
return *this;
}
Status::Status(git_repository * repo, Options const & opts)
{
git_status_list * status;
if (git_status_list_new(&status, repo, opts.raw()))
throw get_status_error();
status_.reset(status);
}
void Status::Destroy::operator()(git_status_list* status) const
{
git_status_list_free(status);
}
}