1 /*
2  * Copyright (C) the libgit2 contributors. All rights reserved.
3  *
4  * This file is part of libgit2, distributed under the GNU GPL v2 with
5  * a Linking Exception. For full terms see the included COPYING file.
6  */
7 module libgit2_d.apply;
8 
9 
10 private static import libgit2_d.diff;
11 private static import libgit2_d.types;
12 
13 /**
14  * @file git2/apply.h
15  * @brief Git patch application routines
16  * @defgroup git_apply Git patch application routines
17  * @ingroup Git
18  * @{
19  */
20 extern (C):
21 nothrow @nogc:
22 public:
23 
24 /**
25  * When applying a patch, callback that will be made per delta (file).
26  *
27  * When the callback:
28  * - returns < 0, the apply process will be aborted.
29  * - returns > 0, the delta will not be applied, but the apply process
30  *      continues
31  * - returns 0, the delta is applied, and the apply process continues.
32  *
33  * Params:
34  *      delta = The delta to be applied
35  *      payload = User-specified payload
36  */
37 alias git_apply_delta_cb = int function(const (libgit2_d.diff.git_diff_delta)* delta, void* payload);
38 
39 /**
40  * When applying a patch, callback that will be made per hunk.
41  *
42  * When the callback:
43  * - returns < 0, the apply process will be aborted.
44  * - returns > 0, the hunk will not be applied, but the apply process
45  *      continues
46  * - returns 0, the hunk is applied, and the apply process continues.
47  *
48  * Params:
49  *      hunk = The hunk to be applied
50  *      payload = User-specified payload
51  */
52 alias git_apply_hunk_cb = int function(const (libgit2_d.diff.git_diff_hunk)* hunk, void* payload);
53 
54 /**
55  * Flags controlling the behavior of git_apply
56  */
57 enum git_apply_flags_t
58 {
59 	/**
60 	 * Don't actually make changes, just test that the patch applies.
61 	 * This is the equivalent of `git apply --check`.
62 	 */
63 	GIT_APPLY_CHECK = 1 << 0,
64 }
65 
66 //Declaration name in C language
67 enum
68 {
69 	GIT_APPLY_CHECK = .git_apply_flags_t.GIT_APPLY_CHECK,
70 }
71 
72 /**
73  * Apply options structure
74  *
75  * Initialize with `GIT_APPLY_OPTIONS_INIT`. Alternatively, you can
76  * use `git_apply_options_init`.
77  *
78  * @see git_apply_to_tree, git_apply
79  */
80 struct git_apply_options
81 {
82 	/**
83 	 * The version
84 	 */
85 	uint version_;
86 
87 	/**
88 	 * When applying a patch, callback that will be made per delta (file).
89 	 */
90 	.git_apply_delta_cb delta_cb;
91 
92 	/**
93 	 * When applying a patch, callback that will be made per hunk.
94 	 */
95 	.git_apply_hunk_cb hunk_cb;
96 
97 	/**
98 	 * Payload passed to both delta_cb & hunk_cb.
99 	 */
100 	void* payload;
101 
102 	/**
103 	 * Bitmask of git_apply_flags_t
104 	 */
105 	uint flags;
106 }
107 
108 enum GIT_APPLY_OPTIONS_VERSION = 1;
109 
110 pragma(inline, true)
111 pure nothrow @safe @nogc
112 .git_apply_options GIT_APPLY_OPTIONS_INIT()
113 
114 	do
115 	{
116 		.git_apply_options OUTPUT =
117 		{
118 			version_: .GIT_APPLY_OPTIONS_VERSION,
119 		};
120 
121 		return OUTPUT;
122 	}
123 
124 //GIT_EXTERN
125 int git_apply_options_init(.git_apply_options* opts, uint version_);
126 
127 /**
128  * Apply a `git_diff` to a `git_tree`, and return the resulting image
129  * as an index.
130  *
131  * Params:
132  *      out_ = the postimage of the application
133  *      repo = the repository to apply
134  *      preimage = the tree to apply the diff to
135  *      diff = the diff to apply
136  *      options = the options for the apply (or null for defaults)
137  */
138 //GIT_EXTERN
139 int git_apply_to_tree(libgit2_d.types.git_index** out_, libgit2_d.types.git_repository* repo, libgit2_d.types.git_tree* preimage, libgit2_d.diff.git_diff* diff, const (.git_apply_options)* options);
140 
141 /**
142  * Possible application locations for git_apply
143  */
144 enum git_apply_location_t
145 {
146 	/**
147 	 * Apply the patch to the workdir, leaving the index untouched.
148 	 * This is the equivalent of `git apply` with no location argument.
149 	 */
150 	GIT_APPLY_LOCATION_WORKDIR = 0,
151 
152 	/**
153 	 * Apply the patch to the index, leaving the working directory
154 	 * untouched.  This is the equivalent of `git apply --cached`.
155 	 */
156 	GIT_APPLY_LOCATION_INDEX = 1,
157 
158 	/**
159 	 * Apply the patch to both the working directory and the index.
160 	 * This is the equivalent of `git apply --index`.
161 	 */
162 	GIT_APPLY_LOCATION_BOTH = 2,
163 }
164 
165 //Declaration name in C language
166 enum
167 {
168 	GIT_APPLY_LOCATION_WORKDIR = .git_apply_location_t.GIT_APPLY_LOCATION_WORKDIR,
169 	GIT_APPLY_LOCATION_INDEX = .git_apply_location_t.GIT_APPLY_LOCATION_INDEX,
170 	GIT_APPLY_LOCATION_BOTH = .git_apply_location_t.GIT_APPLY_LOCATION_BOTH,
171 }
172 
173 /**
174  * Apply a `git_diff` to the given repository, making changes directly
175  * in the working directory, the index, or both.
176  *
177  * Params:
178  *      repo = the repository to apply to
179  *      diff = the diff to apply
180  *      location = the location to apply (workdir, index or both)
181  *      options = the options for the apply (or null for defaults)
182  */
183 //GIT_EXTERN
184 int git_apply(libgit2_d.types.git_repository* repo, libgit2_d.diff.git_diff* diff, .git_apply_location_t location, const (.git_apply_options)* options);
185 
186 /** @} */