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 /** 67 * Apply options structure 68 * 69 * Initialize with `GIT_APPLY_OPTIONS_INIT`. Alternatively, you can 70 * use `git_apply_options_init`. 71 * 72 * @see git_apply_to_tree, git_apply 73 */ 74 struct git_apply_options 75 { 76 /** 77 * The version 78 */ 79 uint version_; 80 81 /** 82 * When applying a patch, callback that will be made per delta (file). 83 */ 84 .git_apply_delta_cb delta_cb; 85 86 /** 87 * When applying a patch, callback that will be made per hunk. 88 */ 89 .git_apply_hunk_cb hunk_cb; 90 91 /** 92 * Payload passed to both delta_cb & hunk_cb. 93 */ 94 void* payload; 95 96 /** 97 * Bitmask of git_apply_flags_t 98 */ 99 uint flags; 100 } 101 102 enum GIT_APPLY_OPTIONS_VERSION = 1; 103 104 pragma(inline, true) 105 pure nothrow @safe @nogc 106 .git_apply_options GIT_APPLY_OPTIONS_INIT() 107 108 do 109 { 110 .git_apply_options OUTPUT = 111 { 112 version_: .GIT_APPLY_OPTIONS_VERSION, 113 }; 114 115 return OUTPUT; 116 } 117 118 //GIT_EXTERN 119 int git_apply_options_init(.git_apply_options* opts, uint version_); 120 121 /** 122 * Apply a `git_diff` to a `git_tree`, and return the resulting image 123 * as an index. 124 * 125 * Params: 126 * out_ = the postimage of the application 127 * repo = the repository to apply 128 * preimage = the tree to apply the diff to 129 * diff = the diff to apply 130 * options = the options for the apply (or null for defaults) 131 */ 132 //GIT_EXTERN 133 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); 134 135 /** 136 * Possible application locations for git_apply 137 */ 138 enum git_apply_location_t 139 { 140 /** 141 * Apply the patch to the workdir, leaving the index untouched. 142 * This is the equivalent of `git apply` with no location argument. 143 */ 144 GIT_APPLY_LOCATION_WORKDIR = 0, 145 146 /** 147 * Apply the patch to the index, leaving the working directory 148 * untouched. This is the equivalent of `git apply --cached`. 149 */ 150 GIT_APPLY_LOCATION_INDEX = 1, 151 152 /** 153 * Apply the patch to both the working directory and the index. 154 * This is the equivalent of `git apply --index`. 155 */ 156 GIT_APPLY_LOCATION_BOTH = 2, 157 } 158 159 /** 160 * Apply a `git_diff` to the given repository, making changes directly 161 * in the working directory, the index, or both. 162 * 163 * Params: 164 * repo = the repository to apply to 165 * diff = the diff to apply 166 * location = the location to apply (workdir, index or both) 167 * options = the options for the apply (or null for defaults) 168 */ 169 //GIT_EXTERN 170 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); 171 172 /** @} */