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.sys.merge; 8 9 10 private static import libgit2_d.buffer; 11 private static import libgit2_d.index; 12 private static import libgit2_d.merge; 13 private static import libgit2_d.types; 14 15 /** 16 * @file git2/sys/merge.h 17 * @brief Git merge driver backend and plugin routines 18 * @defgroup git_merge Git merge driver APIs 19 * @ingroup Git 20 * @{ 21 */ 22 extern (C): 23 nothrow @nogc: 24 package(libgit2_d): 25 26 /** 27 * Look up a merge driver by name 28 * 29 * Params: 30 * name = The name of the merge driver 31 * 32 * Returns: Pointer to the merge driver object or null if not found 33 */ 34 //GIT_EXTERN 35 .git_merge_driver* git_merge_driver_lookup(const (char)* name); 36 37 enum GIT_MERGE_DRIVER_TEXT = "text"; 38 enum GIT_MERGE_DRIVER_BINARY = "binary"; 39 enum GIT_MERGE_DRIVER_UNION = "union"; 40 41 /** 42 * A merge driver source represents the file to be merged 43 */ 44 struct git_merge_driver_source; 45 46 /** 47 * Get the repository that the source data is coming from. 48 */ 49 //GIT_EXTERN 50 libgit2_d.types.git_repository* git_merge_driver_source_repo(const (.git_merge_driver_source)* src); 51 52 /** 53 * Gets the ancestor of the file to merge. 54 */ 55 //GIT_EXTERN 56 const (libgit2_d.index.git_index_entry)* git_merge_driver_source_ancestor(const (.git_merge_driver_source)* src); 57 58 /** 59 * Gets the ours side of the file to merge. 60 */ 61 //GIT_EXTERN 62 const (libgit2_d.index.git_index_entry)* git_merge_driver_source_ours(const (.git_merge_driver_source)* src); 63 64 /** 65 * Gets the theirs side of the file to merge. 66 */ 67 //GIT_EXTERN 68 const (libgit2_d.index.git_index_entry)* git_merge_driver_source_theirs(const (.git_merge_driver_source)* src); 69 70 /** 71 * Gets the merge file options that the merge was invoked with 72 */ 73 //GIT_EXTERN 74 const (libgit2_d.merge.git_merge_file_options)* git_merge_driver_source_file_options(const (.git_merge_driver_source)* src); 75 76 /** 77 * Initialize callback on merge driver 78 * 79 * Specified as `driver.initialize`, this is an optional callback invoked 80 * before a merge driver is first used. It will be called once at most 81 * per library lifetime. 82 * 83 * If non-null, the merge driver's `initialize` callback will be invoked 84 * right before the first use of the driver, so you can defer expensive 85 * initialization operations (in case libgit2 is being used in a way that 86 * doesn't need the merge driver). 87 */ 88 alias git_merge_driver_init_fn = int function(.git_merge_driver* self); 89 90 /** 91 * Shutdown callback on merge driver 92 * 93 * Specified as `driver.shutdown`, this is an optional callback invoked 94 * when the merge driver is unregistered or when libgit2 is shutting down. 95 * It will be called once at most and should release resources as needed. 96 * This may be called even if the `initialize` callback was not made. 97 * 98 * Typically this function will free the `git_merge_driver` object itself. 99 */ 100 alias git_merge_driver_shutdown_fn = void function(.git_merge_driver* self); 101 102 /** 103 * Callback to perform the merge. 104 * 105 * Specified as `driver.apply`, this is the callback that actually does the 106 * merge. If it can successfully perform a merge, it should populate 107 * `path_out` with a pointer to the filename to accept, `mode_out` with 108 * the resultant mode, and `merged_out` with the buffer of the merged file 109 * and then return 0. If the driver returns `git_error_code.GIT_PASSTHROUGH`, then the 110 * default merge driver should instead be run. It can also return 111 * `git_error_code.GIT_EMERGECONFLICT` if the driver is not able to produce a merge result, 112 * and the file will remain conflicted. Any other errors will fail and 113 * return to the caller. 114 * 115 * The `filter_name` contains the name of the filter that was invoked, as 116 * specified by the file's attributes. 117 * 118 * The `src` contains the data about the file to be merged. 119 */ 120 alias git_merge_driver_apply_fn = int function(.git_merge_driver* self, const (char)** path_out, uint* mode_out, libgit2_d.buffer.git_buf* merged_out, const (char)* filter_name, const (.git_merge_driver_source)* src); 121 122 /** 123 * Merge driver structure used to register custom merge drivers. 124 * 125 * To associate extra data with a driver, allocate extra data and put the 126 * `git_merge_driver` struct at the start of your data buffer, then cast 127 * the `self` pointer to your larger structure when your callback is invoked. 128 */ 129 struct git_merge_driver 130 { 131 /** 132 * The `version` should be set to `GIT_MERGE_DRIVER_VERSION`. 133 */ 134 uint version_; 135 136 /** 137 * Called when the merge driver is first used for any file. 138 */ 139 .git_merge_driver_init_fn initialize; 140 141 /** 142 * Called when the merge driver is unregistered from the system. 143 */ 144 .git_merge_driver_shutdown_fn shutdown; 145 146 /** 147 * Called to merge the contents of a conflict. If this function 148 * returns `git_error_code.GIT_PASSTHROUGH` then the default (`text`) merge driver 149 * will instead be invoked. If this function returns 150 * `git_error_code.GIT_EMERGECONFLICT` then the file will remain conflicted. 151 */ 152 .git_merge_driver_apply_fn apply; 153 } 154 155 enum GIT_MERGE_DRIVER_VERSION = 1; 156 157 /** 158 * Register a merge driver under a given name. 159 * 160 * As mentioned elsewhere, the initialize callback will not be invoked 161 * immediately. It is deferred until the driver is used in some way. 162 * 163 * Currently the merge driver registry is not thread safe, so any 164 * registering or deregistering of merge drivers must be done outside of 165 * any possible usage of the drivers (i.e. during application setup or 166 * shutdown). 167 * 168 * Params: 169 * name = The name of this driver to match an attribute. Attempting to register with an in-use name will return git_error_code.GIT_EEXISTS. 170 * driver = The merge driver definition. This pointer will be stored as is by libgit2 so it must be a durable allocation (either static or on the heap). 171 * 172 * Returns: 0 on successful registry, error code <0 on failure 173 */ 174 //GIT_EXTERN 175 int git_merge_driver_register(const (char)* name, .git_merge_driver* driver); 176 177 /** 178 * Remove the merge driver with the given name. 179 * 180 * Attempting to remove the builtin libgit2 merge drivers is not permitted 181 * and will return an error. 182 * 183 * Currently the merge driver registry is not thread safe, so any 184 * registering or deregistering of drivers must be done outside of any 185 * possible usage of the drivers (i.e. during application setup or shutdown). 186 * 187 * Params: 188 * name = The name under which the merge driver was registered 189 * 190 * Returns: 0 on success, error code <0 on failure 191 */ 192 //GIT_EXTERN 193 int git_merge_driver_unregister(const (char)* name); 194 195 /** @} */