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 pathpatch.hpp
More file actions
94 lines (74 loc) · 3.08 KB
/
Copy pathpatch.hpp
File metadata and controls
94 lines (74 loc) · 3.08 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
#pragma once
#include <cppgit2/data_buffer.hpp>
#include <cppgit2/diff.hpp>
#include <cppgit2/libgit2_api.hpp>
#include <cppgit2/ownership.hpp>
#include <functional>
#include <git2.h>
#include <string>
#include <tuple>
namespace cppgit2 {
class patch : public libgit2_api {
public:
// Default construct a patch object
patch();
// Construct from libgit2 C ptr
patch(git_patch *c_ptr, ownership owner = ownership::libgit2);
// Directly generate a patch from the difference between a blob and a buffer.
patch(const blob &old_blob, const std::string &old_as_path,
const void *buffer, size_t buffer_length,
const std::string &buffer_as_path,
const diff::options &options = diff::options());
// Directly generate a patch from the difference between two blobs.
patch(const blob &old_blob, const std::string &old_as_path,
const blob &new_blob, const std::string &new_as_path,
const diff::options &options = diff::options());
// Directly generate a patch from the difference between two buffers.
patch(const void *old_buffer, size_t old_buffer_length,
const std::string &old_as_path, const void *new_buffer,
size_t new_buffer_length, const std::string &new_as_path,
const diff::options &options = diff::options());
// Return a patch for an entry in the diff list.
// The git_patch is a newly created object contains the text diffs for the
// delta.
patch(const diff &diff, size_t index);
// Cleanup patch object
~patch();
// Get the delta associated with a patch.
// This delta points to internal data, owned by libgit2
diff::delta delta() const;
// Get the information about a hunk in a patch
// Returns a pair of results: {hunk, lines_in_hunk}
std::pair<diff::hunk, size_t> hunk(size_t hunk_index) const;
// Get data about a line in a hunk of a patch.
diff::line line_in_hunk(size_t hunk_index, size_t line_of_hunk) const;
// Get line counts of each type in a patch.
// Returns {Count of context lines in output,
// Count of addition lines in output,
// Count of deletion lines in output}
// This helps imitate a diff --numstat type of output
std::tuple<size_t, size_t, size_t> line_stats() const;
// Get the number of hunks in a patch
size_t num_hunks() const;
// Get the number of lines in a hunk.
size_t num_lines_in_hunk(size_t hunk_index) const;
// Serialize the patch to text via callback.
void print(std::function<void(const diff::delta &, const diff::hunk &,
const diff::line &)>
line_callback);
// Look up size of patch diff data in bytes
//
// This returns the raw size of the patch data.
// This only includes the actual data from the lines of the diff,
// not the file or hunk headers.
size_t size(bool include_context, bool include_hunk_headers,
bool include_file_headers) const;
// Get the content of a patch as a single diff text.
data_buffer to_buffer();
// Access to libgit2 C ptr
const git_patch *c_ptr() const;
private:
ownership owner_;
git_patch *c_ptr_;
};
} // namespace cppgit2