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