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 * @param delta The delta to be applied 34 * @param payload User-specified payload 35 */ 36 alias git_apply_delta_cb = int function(const (libgit2_d.diff.git_diff_delta)* delta, void* payload); 37 38 /** 39 * When applying a patch, callback that will be made per hunk. 40 * 41 * When the callback: 42 * - returns < 0, the apply process will be aborted. 43 * - returns > 0, the hunk will not be applied, but the apply process 44 * continues 45 * - returns 0, the hunk is applied, and the apply process continues. 46 * 47 * @param hunk The hunk to be applied 48 * @param payload User-specified payload 49 */ 50 alias git_apply_hunk_cb = int function(const (libgit2_d.diff.git_diff_hunk)* hunk, void* payload); 51 52 /** 53 * Flags controlling the behavior of git_apply 54 */ 55 enum git_apply_flags_t 56 { 57 /** 58 * Don't actually make changes, just test that the patch applies. 59 * This is the equivalent of `git apply --check`. 60 */ 61 GIT_APPLY_CHECK = 1 << 0, 62 } 63 64 /** 65 * Apply options structure 66 * 67 * Initialize with `GIT_APPLY_OPTIONS_INIT`. Alternatively, you can 68 * use `git_apply_options_init`. 69 * 70 * @see git_apply_to_tree, git_apply 71 */ 72 struct git_apply_options 73 { 74 /** 75 * The version 76 */ 77 uint version_; 78 79 /** 80 * When applying a patch, callback that will be made per delta (file). 81 */ 82 .git_apply_delta_cb delta_cb; 83 84 /** 85 * When applying a patch, callback that will be made per hunk. 86 */ 87 .git_apply_hunk_cb hunk_cb; 88 89 /** 90 * Payload passed to both delta_cb & hunk_cb. 91 */ 92 void* payload; 93 94 /** 95 * Bitmask of git_apply_flags_t 96 */ 97 uint flags; 98 } 99 100 enum GIT_APPLY_OPTIONS_VERSION = 1; 101 102 pragma(inline, true) 103 pure nothrow @safe @nogc 104 .git_apply_options GIT_APPLY_OPTIONS_INIT() 105 106 do 107 { 108 .git_apply_options OUTPUT = 109 { 110 version_: .GIT_APPLY_OPTIONS_VERSION, 111 }; 112 113 return OUTPUT; 114 } 115 116 //GIT_EXTERN 117 int git_apply_options_init(.git_apply_options* opts, uint version_); 118 119 /** 120 * Apply a `git_diff` to a `git_tree`, and return the resulting image 121 * as an index. 122 * 123 * @param out_ the postimage of the application 124 * @param repo the repository to apply 125 * @param preimage the tree to apply the diff to 126 * @param diff the diff to apply 127 * @param options the options for the apply (or null for defaults) 128 */ 129 //GIT_EXTERN 130 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); 131 132 /** 133 * Possible application locations for git_apply 134 */ 135 enum git_apply_location_t 136 { 137 /** 138 * Apply the patch to the workdir, leaving the index untouched. 139 * This is the equivalent of `git apply` with no location argument. 140 */ 141 GIT_APPLY_LOCATION_WORKDIR = 0, 142 143 /** 144 * Apply the patch to the index, leaving the working directory 145 * untouched. This is the equivalent of `git apply --cached`. 146 */ 147 GIT_APPLY_LOCATION_INDEX = 1, 148 149 /** 150 * Apply the patch to both the working directory and the index. 151 * This is the equivalent of `git apply --index`. 152 */ 153 GIT_APPLY_LOCATION_BOTH = 2, 154 } 155 156 /** 157 * Apply a `git_diff` to the given repository, making changes directly 158 * in the working directory, the index, or both. 159 * 160 * @param repo the repository to apply to 161 * @param diff the diff to apply 162 * @param location the location to apply (workdir, index or both) 163 * @param options the options for the apply (or null for defaults) 164 */ 165 //GIT_EXTERN 166 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); 167 168 /** @} */