2 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
7 #ifndef INCLUDE_git_apply_h__
8 #define INCLUDE_git_apply_h__
17 * @brief Git patch application routines
18 * @defgroup git_apply Git patch application routines
25 * When applying a patch, callback that will be made per delta (file).
28 * - returns < 0, the apply process will be aborted.
29 * - returns > 0, the delta will not be applied, but the apply process
31 * - returns 0, the delta is applied, and the apply process continues.
33 * @param delta The delta to be applied
34 * @param payload User-specified payload
36 typedef int GIT_CALLBACK(git_apply_delta_cb
)(
37 const git_diff_delta
*delta
,
41 * When applying a patch, callback that will be made per hunk.
44 * - returns < 0, the apply process will be aborted.
45 * - returns > 0, the hunk will not be applied, but the apply process
47 * - returns 0, the hunk is applied, and the apply process continues.
49 * @param hunk The hunk to be applied
50 * @param payload User-specified payload
52 typedef int GIT_CALLBACK(git_apply_hunk_cb
)(
53 const git_diff_hunk
*hunk
,
56 /** Flags controlling the behavior of git_apply */
59 * Don't actually make changes, just test that the patch applies.
60 * This is the equivalent of `git apply --check`.
62 GIT_APPLY_CHECK
= (1 << 0),
66 * Apply options structure
68 * Initialize with `GIT_APPLY_OPTIONS_INIT`. Alternatively, you can
69 * use `git_apply_options_init`.
71 * @see git_apply_to_tree, git_apply
74 unsigned int version
; /**< The version */
76 /** When applying a patch, callback that will be made per delta (file). */
77 git_apply_delta_cb delta_cb
;
79 /** When applying a patch, callback that will be made per hunk. */
80 git_apply_hunk_cb hunk_cb
;
82 /** Payload passed to both delta_cb & hunk_cb. */
85 /** Bitmask of git_apply_flags_t */
89 #define GIT_APPLY_OPTIONS_VERSION 1
90 #define GIT_APPLY_OPTIONS_INIT {GIT_APPLY_OPTIONS_VERSION}
92 GIT_EXTERN(int) git_apply_options_init(git_apply_options
*opts
, unsigned int version
);
95 * Apply a `git_diff` to a `git_tree`, and return the resulting image
98 * @param out the postimage of the application
99 * @param repo the repository to apply
100 * @param preimage the tree to apply the diff to
101 * @param diff the diff to apply
102 * @param options the options for the apply (or null for defaults)
104 GIT_EXTERN(int) git_apply_to_tree(
106 git_repository
*repo
,
109 const git_apply_options
*options
);
111 /** Possible application locations for git_apply */
114 * Apply the patch to the workdir, leaving the index untouched.
115 * This is the equivalent of `git apply` with no location argument.
117 GIT_APPLY_LOCATION_WORKDIR
= 0,
120 * Apply the patch to the index, leaving the working directory
121 * untouched. This is the equivalent of `git apply --cached`.
123 GIT_APPLY_LOCATION_INDEX
= 1,
126 * Apply the patch to both the working directory and the index.
127 * This is the equivalent of `git apply --index`.
129 GIT_APPLY_LOCATION_BOTH
= 2,
130 } git_apply_location_t
;
133 * Apply a `git_diff` to the given repository, making changes directly
134 * in the working directory, the index, or both.
136 * @param repo the repository to apply to
137 * @param diff the diff to apply
138 * @param location the location to apply (workdir, index or both)
139 * @param options the options for the apply (or null for defaults)
141 GIT_EXTERN(int) git_apply(
142 git_repository
*repo
,
144 git_apply_location_t location
,
145 const git_apply_options
*options
);