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 pathpathspec.cpp
More file actions
67 lines (57 loc) · 2.53 KB
/
Copy pathpathspec.cpp
File metadata and controls
67 lines (57 loc) · 2.53 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
#include <cppgit2/repository.hpp>
using namespace cppgit2;
pathspec::pathspec() : c_ptr_(nullptr), owner_(ownership::libgit2) {}
pathspec::pathspec(git_pathspec *c_ptr, ownership owner)
: c_ptr_(c_ptr), owner_(owner) {}
pathspec::~pathspec() {
if (c_ptr_ && owner_ == ownership::user)
git_pathspec_free(c_ptr_);
}
pathspec pathspec::compile(const strarray &paths) {
pathspec result(nullptr, ownership::user);
if (git_pathspec_new(&result.c_ptr_, paths.c_ptr()))
throw git_exception();
return result;
}
pathspec::match_list pathspec::match_diff(const diff &diff,
pathspec::flag flags) {
git_pathspec_match_list **result_c =
(git_pathspec_match_list **)malloc(sizeof(git_pathspec_match_list *));
if (git_pathspec_match_diff(result_c, diff.c_ptr_,
static_cast<uint32_t>(flags), c_ptr_))
throw git_exception();
return pathspec::match_list(*result_c);
}
pathspec::match_list pathspec::match_index(const index &index,
pathspec::flag flags) {
git_pathspec_match_list **result_c =
(git_pathspec_match_list **)malloc(sizeof(git_pathspec_match_list *));
if (git_pathspec_match_index(result_c, index.c_ptr_,
static_cast<uint32_t>(flags), c_ptr_))
throw git_exception();
return pathspec::match_list(*result_c);
}
pathspec::match_list pathspec::match_tree(const tree &tree,
pathspec::flag flags) {
git_pathspec_match_list **result_c =
(git_pathspec_match_list **)malloc(sizeof(git_pathspec_match_list *));
if (git_pathspec_match_tree(result_c, tree.c_ptr_,
static_cast<uint32_t>(flags), c_ptr_))
throw git_exception();
return pathspec::match_list(*result_c);
}
pathspec::match_list pathspec::match_workdir(const repository &repo,
pathspec::flag flags) {
git_pathspec_match_list **result_c =
(git_pathspec_match_list **)malloc(sizeof(git_pathspec_match_list *));
if (git_pathspec_match_workdir(result_c, repo.c_ptr_,
static_cast<uint32_t>(flags), c_ptr_))
throw git_exception();
return pathspec::match_list(*result_c);
}
bool pathspec::matches_path(pathspec::flag flags,
const std::string &path) const {
return git_pathspec_matches_path(c_ptr_, static_cast<uint32_t>(flags),
path.c_str());
}
const git_pathspec *pathspec::c_ptr() const { return c_ptr_; }