|
||||
File indexing completed on 2025-01-18 09:59:36
0001 /* 0002 * Copyright (C) the libgit2 contributors. All rights reserved. 0003 * 0004 * This file is part of libgit2, distributed under the GNU GPL v2 with 0005 * a Linking Exception. For full terms see the included COPYING file. 0006 */ 0007 #ifndef INCLUDE_sys_git_refdb_backend_h__ 0008 #define INCLUDE_sys_git_refdb_backend_h__ 0009 0010 #include "git2/common.h" 0011 #include "git2/types.h" 0012 #include "git2/oid.h" 0013 0014 /** 0015 * @file git2/refdb_backend.h 0016 * @brief Git custom refs backend functions 0017 * @defgroup git_refdb_backend Git custom refs backend API 0018 * @ingroup Git 0019 * @{ 0020 */ 0021 GIT_BEGIN_DECL 0022 0023 0024 /** 0025 * Every backend's iterator must have a pointer to itself as the first 0026 * element, so the API can talk to it. You'd define your iterator as 0027 * 0028 * struct my_iterator { 0029 * git_reference_iterator parent; 0030 * ... 0031 * } 0032 * 0033 * and assign `iter->parent.backend` to your `git_refdb_backend`. 0034 */ 0035 struct git_reference_iterator { 0036 git_refdb *db; 0037 0038 /** 0039 * Return the current reference and advance the iterator. 0040 */ 0041 int GIT_CALLBACK(next)( 0042 git_reference **ref, 0043 git_reference_iterator *iter); 0044 0045 /** 0046 * Return the name of the current reference and advance the iterator 0047 */ 0048 int GIT_CALLBACK(next_name)( 0049 const char **ref_name, 0050 git_reference_iterator *iter); 0051 0052 /** 0053 * Free the iterator 0054 */ 0055 void GIT_CALLBACK(free)( 0056 git_reference_iterator *iter); 0057 }; 0058 0059 /** An instance for a custom backend */ 0060 struct git_refdb_backend { 0061 unsigned int version; /**< The backend API version */ 0062 0063 /** 0064 * Queries the refdb backend for the existence of a reference. 0065 * 0066 * A refdb implementation must provide this function. 0067 * 0068 * @arg exists The implementation shall set this to `0` if a ref does 0069 * not exist, otherwise to `1`. 0070 * @arg ref_name The reference's name that should be checked for 0071 * existence. 0072 * @return `0` on success, a negative error value code. 0073 */ 0074 int GIT_CALLBACK(exists)( 0075 int *exists, 0076 git_refdb_backend *backend, 0077 const char *ref_name); 0078 0079 /** 0080 * Queries the refdb backend for a given reference. 0081 * 0082 * A refdb implementation must provide this function. 0083 * 0084 * @arg out The implementation shall set this to the allocated 0085 * reference, if it could be found, otherwise to `NULL`. 0086 * @arg ref_name The reference's name that should be checked for 0087 * existence. 0088 * @return `0` on success, `GIT_ENOTFOUND` if the reference does 0089 * exist, otherwise a negative error code. 0090 */ 0091 int GIT_CALLBACK(lookup)( 0092 git_reference **out, 0093 git_refdb_backend *backend, 0094 const char *ref_name); 0095 0096 /** 0097 * Allocate an iterator object for the backend. 0098 * 0099 * A refdb implementation must provide this function. 0100 * 0101 * @arg out The implementation shall set this to the allocated 0102 * reference iterator. A custom structure may be used with an 0103 * embedded `git_reference_iterator` structure. Both `next` 0104 * and `next_name` functions of `git_reference_iterator` need 0105 * to be populated. 0106 * @arg glob A pattern to filter references by. If given, the iterator 0107 * shall only return references that match the glob when 0108 * passed to `wildmatch`. 0109 * @return `0` on success, otherwise a negative error code. 0110 */ 0111 int GIT_CALLBACK(iterator)( 0112 git_reference_iterator **iter, 0113 struct git_refdb_backend *backend, 0114 const char *glob); 0115 0116 /** 0117 * Writes the given reference to the refdb. 0118 * 0119 * A refdb implementation must provide this function. 0120 * 0121 * @arg ref The reference to persist. May either be a symbolic or 0122 * direct reference. 0123 * @arg force Whether to write the reference if a reference with the 0124 * same name already exists. 0125 * @arg who The person updating the reference. Shall be used to create 0126 * a reflog entry. 0127 * @arg message The message detailing what kind of reference update is 0128 * performed. Shall be used to create a reflog entry. 0129 * @arg old If not `NULL` and `force` is not set, then the 0130 * implementation needs to ensure that the reference is currently at 0131 * the given OID before writing the new value. If both `old` 0132 * and `old_target` are `NULL`, then the reference should not 0133 * exist at the point of writing. 0134 * @arg old_target If not `NULL` and `force` is not set, then the 0135 * implementation needs to ensure that the symbolic 0136 * reference is currently at the given target before 0137 * writing the new value. If both `old` and 0138 * `old_target` are `NULL`, then the reference should 0139 * not exist at the point of writing. 0140 * @return `0` on success, otherwise a negative error code. 0141 */ 0142 int GIT_CALLBACK(write)(git_refdb_backend *backend, 0143 const git_reference *ref, int force, 0144 const git_signature *who, const char *message, 0145 const git_oid *old, const char *old_target); 0146 0147 /** 0148 * Rename a reference in the refdb. 0149 * 0150 * A refdb implementation must provide this function. 0151 * 0152 * @arg out The implementation shall set this to the newly created 0153 * reference or `NULL` on error. 0154 * @arg old_name The current name of the reference that is to be renamed. 0155 * @arg new_name The new name that the old reference shall be renamed to. 0156 * @arg force Whether to write the reference if a reference with the 0157 * target name already exists. 0158 * @arg who The person updating the reference. Shall be used to create 0159 * a reflog entry. 0160 * @arg message The message detailing what kind of reference update is 0161 * performed. Shall be used to create a reflog entry. 0162 * @return `0` on success, otherwise a negative error code. 0163 */ 0164 int GIT_CALLBACK(rename)( 0165 git_reference **out, git_refdb_backend *backend, 0166 const char *old_name, const char *new_name, int force, 0167 const git_signature *who, const char *message); 0168 0169 /** 0170 * Deletes the given reference from the refdb. 0171 * 0172 * If it exists, its reflog should be deleted as well. 0173 * 0174 * A refdb implementation must provide this function. 0175 * 0176 * @arg ref_name The name of the reference name that shall be deleted. 0177 * @arg old_id If not `NULL` and `force` is not set, then the 0178 * implementation needs to ensure that the reference is currently at 0179 * the given OID before writing the new value. 0180 * @arg old_target If not `NULL` and `force` is not set, then the 0181 * implementation needs to ensure that the symbolic 0182 * reference is currently at the given target before 0183 * writing the new value. 0184 * @return `0` on success, otherwise a negative error code. 0185 */ 0186 int GIT_CALLBACK(del)(git_refdb_backend *backend, const char *ref_name, const git_oid *old_id, const char *old_target); 0187 0188 /** 0189 * Suggests that the given refdb compress or optimize its references. 0190 * 0191 * This mechanism is implementation specific. For on-disk reference 0192 * databases, this may pack all loose references. 0193 * 0194 * A refdb implementation may provide this function; if it is not 0195 * provided, nothing will be done. 0196 * 0197 * @return `0` on success a negative error code otherwise 0198 */ 0199 int GIT_CALLBACK(compress)(git_refdb_backend *backend); 0200 0201 /** 0202 * Query whether a particular reference has a log (may be empty) 0203 * 0204 * Shall return 1 if it has a reflog, 0 it it doesn't and negative in 0205 * case an error occurred. 0206 * 0207 * A refdb implementation must provide this function. 0208 * 0209 * @return `0` on success, `1` if the reflog for the given reference 0210 * exists, a negative error code otherwise 0211 */ 0212 int GIT_CALLBACK(has_log)(git_refdb_backend *backend, const char *refname); 0213 0214 /** 0215 * Make sure a particular reference will have a reflog which 0216 * will be appended to on writes. 0217 * 0218 * A refdb implementation must provide this function. 0219 * 0220 * @return `0` on success, a negative error code otherwise 0221 */ 0222 int GIT_CALLBACK(ensure_log)(git_refdb_backend *backend, const char *refname); 0223 0224 /** 0225 * Frees any resources held by the refdb (including the `git_refdb_backend` 0226 * itself). 0227 * 0228 * A refdb backend implementation must provide this function. 0229 */ 0230 void GIT_CALLBACK(free)(git_refdb_backend *backend); 0231 0232 /** 0233 * Read the reflog for the given reference name. 0234 * 0235 * A refdb implementation must provide this function. 0236 * 0237 * @return `0` on success, a negative error code otherwise 0238 */ 0239 int GIT_CALLBACK(reflog_read)(git_reflog **out, git_refdb_backend *backend, const char *name); 0240 0241 /** 0242 * Write a reflog to disk. 0243 * 0244 * A refdb implementation must provide this function. 0245 * 0246 * @arg reflog The complete reference log for a given reference. Note 0247 * that this may contain entries that have already been 0248 * written to disk. 0249 * @return `0` on success, a negative error code otherwise 0250 */ 0251 int GIT_CALLBACK(reflog_write)(git_refdb_backend *backend, git_reflog *reflog); 0252 0253 /** 0254 * Rename a reflog. 0255 * 0256 * A refdb implementation must provide this function. 0257 * 0258 * @arg old_name The name of old reference whose reflog shall be renamed from. 0259 * @arg new_name The name of new reference whose reflog shall be renamed to. 0260 * @return `0` on success, a negative error code otherwise 0261 */ 0262 int GIT_CALLBACK(reflog_rename)(git_refdb_backend *_backend, const char *old_name, const char *new_name); 0263 0264 /** 0265 * Remove a reflog. 0266 * 0267 * A refdb implementation must provide this function. 0268 * 0269 * @arg name The name of the reference whose reflog shall be deleted. 0270 * @return `0` on success, a negative error code otherwise 0271 */ 0272 int GIT_CALLBACK(reflog_delete)(git_refdb_backend *backend, const char *name); 0273 0274 /** 0275 * Lock a reference. 0276 * 0277 * A refdb implementation may provide this function; if it is not 0278 * provided, the transaction API will fail to work. 0279 * 0280 * @arg payload_out Opaque parameter that will be passed verbosely to 0281 * `unlock`. 0282 * @arg refname Reference that shall be locked. 0283 * @return `0` on success, a negative error code otherwise 0284 */ 0285 int GIT_CALLBACK(lock)(void **payload_out, git_refdb_backend *backend, const char *refname); 0286 0287 /** 0288 * Unlock a reference. 0289 * 0290 * Only one of target or symbolic_target will be set. 0291 * `success` will be true if the reference should be update, false if 0292 * the lock must be discarded. 0293 * 0294 * A refdb implementation must provide this function if a `lock` 0295 * implementation is provided. 0296 * 0297 * @arg payload The payload returned by `lock`. 0298 * @arg success `1` if a reference should be updated, `2` if 0299 * a reference should be deleted, `0` if the lock must be 0300 * discarded. 0301 * @arg update_reflog `1` in case the reflog should be updated, `0` 0302 * otherwise. 0303 * @arg ref The reference which should be unlocked. 0304 * @arg who The person updating the reference. Shall be used to create 0305 * a reflog entry in case `update_reflog` is set. 0306 * @arg message The message detailing what kind of reference update is 0307 * performed. Shall be used to create a reflog entry in 0308 * case `update_reflog` is set. 0309 * @return `0` on success, a negative error code otherwise 0310 */ 0311 int GIT_CALLBACK(unlock)(git_refdb_backend *backend, void *payload, int success, int update_reflog, 0312 const git_reference *ref, const git_signature *sig, const char *message); 0313 }; 0314 0315 #define GIT_REFDB_BACKEND_VERSION 1 0316 #define GIT_REFDB_BACKEND_INIT {GIT_REFDB_BACKEND_VERSION} 0317 0318 /** 0319 * Initializes a `git_refdb_backend` with default values. Equivalent to 0320 * creating an instance with GIT_REFDB_BACKEND_INIT. 0321 * 0322 * @param backend the `git_refdb_backend` struct to initialize 0323 * @param version Version of struct; pass `GIT_REFDB_BACKEND_VERSION` 0324 * @return Zero on success; -1 on failure. 0325 */ 0326 GIT_EXTERN(int) git_refdb_init_backend( 0327 git_refdb_backend *backend, 0328 unsigned int version); 0329 0330 /** 0331 * Constructors for default filesystem-based refdb backend 0332 * 0333 * Under normal usage, this is called for you when the repository is 0334 * opened / created, but you can use this to explicitly construct a 0335 * filesystem refdb backend for a repository. 0336 * 0337 * @param backend_out Output pointer to the git_refdb_backend object 0338 * @param repo Git repository to access 0339 * @return 0 on success, <0 error code on failure 0340 */ 0341 GIT_EXTERN(int) git_refdb_backend_fs( 0342 git_refdb_backend **backend_out, 0343 git_repository *repo); 0344 0345 /** 0346 * Sets the custom backend to an existing reference DB 0347 * 0348 * The `git_refdb` will take ownership of the `git_refdb_backend` so you 0349 * should NOT free it after calling this function. 0350 * 0351 * @param refdb database to add the backend to 0352 * @param backend pointer to a git_refdb_backend instance 0353 * @return 0 on success; error code otherwise 0354 */ 0355 GIT_EXTERN(int) git_refdb_set_backend( 0356 git_refdb *refdb, 0357 git_refdb_backend *backend); 0358 0359 GIT_END_DECL 0360 0361 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |