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.refdb_backend; 8 9 10 private static import libgit2_d.oid; 11 private static import libgit2_d.types; 12 13 /** 14 * @file git2/refdb_backend.h 15 * @brief Git custom refs backend functions 16 * @defgroup git_refdb_backend Git custom refs backend API 17 * @ingroup Git 18 * @{ 19 */ 20 extern (C): 21 nothrow @nogc: 22 package(libgit2_d): 23 24 /** 25 * Every backend's iterator must have a pointer to itself as the first 26 * element, so the API can talk to it. You'd define your iterator as 27 * 28 * struct my_iterator { 29 * git_reference_iterator parent; 30 * ... 31 * } 32 * 33 * and assign `iter->parent.backend` to your `git_refdb_backend`. 34 */ 35 struct git_reference_iterator 36 { 37 libgit2_d.types.git_refdb* db; 38 39 /** 40 * Return the current reference and advance the iterator. 41 */ 42 int function(libgit2_d.types.git_reference** ref_, .git_reference_iterator* iter) next; 43 44 /** 45 * Return the name of the current reference and advance the iterator 46 */ 47 int function(const (char)** ref_name, .git_reference_iterator* iter) next_name; 48 49 /** 50 * Free the iterator 51 */ 52 void function(.git_reference_iterator* iter) free; 53 } 54 55 /** 56 * An instance for a custom backend 57 */ 58 struct git_refdb_backend 59 { 60 /** 61 * The backend API version 62 */ 63 uint version_; 64 65 /** 66 * Queries the refdb backend for the existence of a reference. 67 * 68 * A refdb implementation must provide this function. 69 */ 70 int function(int* exists, .git_refdb_backend* backend, const (char)* ref_name) exists; 71 72 /** 73 * Queries the refdb backend for a given reference. 74 * 75 * A refdb implementation must provide this function. 76 */ 77 int function(libgit2_d.types.git_reference** out_, .git_refdb_backend* backend, const (char)* ref_name) lookup; 78 79 /** 80 * Allocate an iterator object for the backend. 81 * 82 * A refdb implementation must provide this function. 83 */ 84 int function(.git_reference_iterator** iter, .git_refdb_backend* backend, const (char)* glob) iterator; 85 86 /** 87 * Writes the given reference to the refdb. 88 * 89 * A refdb implementation must provide this function. 90 */ 91 int function(.git_refdb_backend* backend, const (libgit2_d.types.git_reference)* ref_, int force, const (libgit2_d.types.git_signature)* who, const (char)* message, const (libgit2_d.oid.git_oid)* old, const (char)* old_target) write; 92 93 /** 94 * Rename a reference in the refdb. 95 * 96 * A refdb implementation must provide this function. 97 */ 98 int function(libgit2_d.types.git_reference** out_, .git_refdb_backend* backend, const (char)* old_name, const (char)* new_name, int force, const (libgit2_d.types.git_signature)* who, const (char)* message) rename; 99 100 /** 101 * Deletes the given reference from the refdb. 102 * 103 * If it exists, its reflog should be deleted as well. 104 * 105 * A refdb implementation must provide this function. 106 */ 107 int function(.git_refdb_backend* backend, const (char)* ref_name, const (libgit2_d.oid.git_oid)* old_id, const (char)* old_target) del; 108 109 /** 110 * Suggests that the given refdb compress or optimize its references. 111 * 112 * This mechanism is implementation specific. For on-disk reference 113 * databases, this may pack all loose references. 114 * 115 * A refdb implementation may provide this function; if it is not 116 * provided, nothing will be done. 117 */ 118 int function(.git_refdb_backend* backend) compress; 119 120 /** 121 * Query whether a particular reference has a log (may be empty) 122 * 123 * A refdb implementation must provide this function. 124 */ 125 int function(.git_refdb_backend* backend, const (char)* refname) has_log; 126 127 /** 128 * Make sure a particular reference will have a reflog which 129 * will be appended to on writes. 130 * 131 * A refdb implementation must provide this function. 132 */ 133 int function(.git_refdb_backend* backend, const (char)* refname) ensure_log; 134 135 /** 136 * Frees any resources held by the refdb (including the `git_refdb_backend` 137 * itself). 138 * 139 * A refdb backend implementation must provide this function. 140 */ 141 void function(.git_refdb_backend* backend) free; 142 143 /** 144 * Read the reflog for the given reference name. 145 * 146 * A refdb implementation must provide this function. 147 */ 148 int function(libgit2_d.types.git_reflog** out_, .git_refdb_backend* backend, const (char)* name) reflog_read; 149 150 /** 151 * Write a reflog to disk. 152 * 153 * A refdb implementation must provide this function. 154 */ 155 int function(.git_refdb_backend* backend, libgit2_d.types.git_reflog* reflog) reflog_write; 156 157 /** 158 * Rename a reflog. 159 * 160 * A refdb implementation must provide this function. 161 */ 162 int function(.git_refdb_backend* _backend, const (char)* old_name, const (char)* new_name) reflog_rename; 163 164 /** 165 * Remove a reflog. 166 * 167 * A refdb implementation must provide this function. 168 */ 169 int function(.git_refdb_backend* backend, const (char)* name) reflog_delete; 170 171 /** 172 * Lock a reference. 173 * 174 * The opaque parameter will be passed to the unlock function. 175 * 176 * A refdb implementation may provide this function; if it is not 177 * provided, the transaction API will fail to work. 178 */ 179 int function(void** payload_out, .git_refdb_backend* backend, const (char)* refname) lock; 180 181 /** 182 * Unlock a reference. 183 * 184 * Only one of target or symbolic_target will be set. 185 * `success` will be true if the reference should be update, false if 186 * the lock must be discarded. 187 * 188 * A refdb implementation must provide this function if a `lock` 189 * implementation is provided. 190 */ 191 int function(.git_refdb_backend* backend, void* payload, int success, int update_reflog, const (libgit2_d.types.git_reference)* ref_, const (libgit2_d.types.git_signature)* sig, const (char)* message) unlock; 192 } 193 194 enum GIT_REFDB_BACKEND_VERSION = 1; 195 196 pragma(inline, true) 197 pure nothrow @safe @nogc 198 .git_refdb_backend GIT_REFDB_BACKEND_INIT() 199 200 do 201 { 202 .git_refdb_backend OUTPUT = 203 { 204 version_: .GIT_REFDB_BACKEND_VERSION, 205 }; 206 207 return OUTPUT; 208 } 209 210 /** 211 * Initializes a `git_refdb_backend` with default values. Equivalent to 212 * creating an instance with GIT_REFDB_BACKEND_INIT. 213 * 214 * @param backend the `git_refdb_backend` struct to initialize 215 * @param version Version of struct; pass `GIT_REFDB_BACKEND_VERSION` 216 * @return Zero on success; -1 on failure. 217 */ 218 //GIT_EXTERN 219 int git_refdb_init_backend(.git_refdb_backend* backend, uint version_); 220 221 /** 222 * Constructors for default filesystem-based refdb backend 223 * 224 * Under normal usage, this is called for you when the repository is 225 * opened / created, but you can use this to explicitly construct a 226 * filesystem refdb backend for a repository. 227 * 228 * @param backend_out Output pointer to the git_refdb_backend object 229 * @param repo Git repository to access 230 * @return 0 on success, <0 error code on failure 231 */ 232 //GIT_EXTERN 233 int git_refdb_backend_fs(.git_refdb_backend** backend_out, libgit2_d.types.git_repository* repo); 234 235 /** 236 * Sets the custom backend to an existing reference DB 237 * 238 * The `git_refdb` will take ownership of the `git_refdb_backend` so you 239 * should NOT free it after calling this function. 240 * 241 * @param refdb database to add the backend to 242 * @param backend pointer to a git_refdb_backend instance 243 * @return 0 on success; error code otherwise 244 */ 245 //GIT_EXTERN 246 int git_refdb_set_backend(libgit2_d.types.git_refdb* refdb, .git_refdb_backend* backend);