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.pack; 8 9 10 private static import libgit2_d.buffer; 11 private static import libgit2_d.indexer; 12 private static import libgit2_d.oid; 13 private static import libgit2_d.types; 14 15 /** 16 * @file git2/pack.h 17 * @brief Git pack management routines 18 * 19 * Packing objects 20 * --------------- 21 * 22 * Creation of packfiles requires two steps: 23 * 24 * - First, insert all the objects you want to put into the packfile 25 * using `git_packbuilder_insert` and `git_packbuilder_insert_tree`. 26 * It's important to add the objects in recency order ("in the order 27 * that they are 'reachable' from head"). 28 * 29 * "ANY order will give you a working pack, ... [but it is] the thing 30 * that gives packs good locality. It keeps the objects close to the 31 * head (whether they are old or new, but they are _reachable_ from the 32 * head) at the head of the pack. So packs actually have absolutely 33 * _wonderful_ IO patterns." - Linus Torvalds 34 * git.git/Documentation/technical/pack-heuristics.txt 35 * 36 * - Second, use `git_packbuilder_write` or `git_packbuilder_foreach` to 37 * write the resulting packfile. 38 * 39 * libgit2 will take care of the delta ordering and generation. 40 * `git_packbuilder_set_threads` can be used to adjust the number of 41 * threads used for the process. 42 * 43 * See tests/pack/packbuilder.c for an example. 44 * 45 * @ingroup Git 46 * @{ 47 */ 48 extern (C): 49 nothrow @nogc: 50 public: 51 52 /** 53 * Stages that are reported by the packbuilder progress callback. 54 */ 55 enum git_packbuilder_stage_t 56 { 57 GIT_PACKBUILDER_ADDING_OBJECTS = 0, 58 GIT_PACKBUILDER_DELTAFICATION = 1, 59 } 60 61 /** 62 * Initialize a new packbuilder 63 * 64 * Params: 65 * out_ = The new packbuilder object 66 * repo = The repository 67 * 68 * Returns: 0 or an error code 69 */ 70 //GIT_EXTERN 71 int git_packbuilder_new(libgit2_d.types.git_packbuilder** out_, libgit2_d.types.git_repository* repo); 72 73 /** 74 * Set number of threads to spawn 75 * 76 * By default, libgit2 won't spawn any threads at all; 77 * when set to 0, libgit2 will autodetect the number of 78 * CPUs. 79 * 80 * Params: 81 * pb = The packbuilder 82 * n = Number of threads to spawn 83 * 84 * Returns: number of actual threads to be used 85 */ 86 //GIT_EXTERN 87 uint git_packbuilder_set_threads(libgit2_d.types.git_packbuilder* pb, uint n); 88 89 /** 90 * Insert a single object 91 * 92 * For an optimal pack it's mandatory to insert objects in recency order, 93 * commits followed by trees and blobs. 94 * 95 * Params: 96 * pb = The packbuilder 97 * id = The oid of the commit 98 * name = The name; might be null 99 * 100 * Returns: 0 or an error code 101 */ 102 //GIT_EXTERN 103 int git_packbuilder_insert(libgit2_d.types.git_packbuilder* pb, const (libgit2_d.oid.git_oid)* id, const (char)* name); 104 105 /** 106 * Insert a root tree object 107 * 108 * This will add the tree as well as all referenced trees and blobs. 109 * 110 * Params: 111 * pb = The packbuilder 112 * id = The oid of the root tree 113 * 114 * Returns: 0 or an error code 115 */ 116 //GIT_EXTERN 117 int git_packbuilder_insert_tree(libgit2_d.types.git_packbuilder* pb, const (libgit2_d.oid.git_oid)* id); 118 119 /** 120 * Insert a commit object 121 * 122 * This will add a commit as well as the completed referenced tree. 123 * 124 * Params: 125 * pb = The packbuilder 126 * id = The oid of the commit 127 * 128 * Returns: 0 or an error code 129 */ 130 //GIT_EXTERN 131 int git_packbuilder_insert_commit(libgit2_d.types.git_packbuilder* pb, const (libgit2_d.oid.git_oid)* id); 132 133 /** 134 * Insert objects as given by the walk 135 * 136 * Those commits and all objects they reference will be inserted into 137 * the packbuilder. 138 * 139 * Params: 140 * pb = the packbuilder 141 * walk = the revwalk to use to fill the packbuilder 142 * 143 * Returns: 0 or an error code 144 */ 145 //GIT_EXTERN 146 int git_packbuilder_insert_walk(libgit2_d.types.git_packbuilder* pb, libgit2_d.types.git_revwalk* walk); 147 148 /** 149 * Recursively insert an object and its referenced objects 150 * 151 * Insert the object as well as any object it references. 152 * 153 * Params: 154 * pb = the packbuilder 155 * id = the id of the root object to insert 156 * name = optional name for the object 157 * 158 * Returns: 0 or an error code 159 */ 160 //GIT_EXTERN 161 int git_packbuilder_insert_recur(libgit2_d.types.git_packbuilder* pb, const (libgit2_d.oid.git_oid)* id, const (char)* name); 162 163 /** 164 * Write the contents of the packfile to an in-memory buffer 165 * 166 * The contents of the buffer will become a valid packfile, even though there 167 * will be no attached index 168 * 169 * Params: 170 * buf = Buffer where to write the packfile 171 * pb = The packbuilder 172 */ 173 //GIT_EXTERN 174 int git_packbuilder_write_buf(libgit2_d.buffer.git_buf* buf, libgit2_d.types.git_packbuilder* pb); 175 176 /** 177 * Write the new pack and corresponding index file to path. 178 * 179 * Params: 180 * pb = The packbuilder 181 * path = to the directory where the packfile and index should be stored 182 * mode = permissions to use creating a packfile or 0 for defaults 183 * progress_cb = function to call with progress information from the indexer (optional) 184 * progress_cb_payload = payload for the progress callback (optional) 185 * 186 * Returns: 0 or an error code 187 */ 188 //GIT_EXTERN 189 int git_packbuilder_write(libgit2_d.types.git_packbuilder* pb, const (char)* path, uint mode, libgit2_d.indexer.git_indexer_progress_cb progress_cb, void* progress_cb_payload); 190 191 /** 192 * Get the packfile's hash 193 * 194 * A packfile's name is derived from the sorted hashing of all object 195 * names. This is only correct after the packfile has been written. 196 * 197 * Params: 198 * pb = The packbuilder object 199 */ 200 //GIT_EXTERN 201 const (libgit2_d.oid.git_oid)* git_packbuilder_hash(libgit2_d.types.git_packbuilder* pb); 202 203 /** 204 * Callback used to iterate over packed objects 205 * 206 * @see git_packbuilder_foreach 207 * 208 * Params: 209 * buf = A pointer to the object's data 210 * size = The size of the underlying object 211 * payload = Payload passed to git_packbuilder_foreach 212 * 213 * Returns: non-zero to terminate the iteration 214 */ 215 alias git_packbuilder_foreach_cb = int function(void* buf, size_t size, void* payload); 216 217 /** 218 * Create the new pack and pass each object to the callback 219 * 220 * Params: 221 * pb = the packbuilder 222 * cb = the callback to call with each packed object's buffer 223 * payload = the callback's data 224 * 225 * Returns: 0 or an error code 226 */ 227 //GIT_EXTERN 228 int git_packbuilder_foreach(libgit2_d.types.git_packbuilder* pb, .git_packbuilder_foreach_cb cb, void* payload); 229 230 /** 231 * Get the total number of objects the packbuilder will write out 232 * 233 * Params: 234 * pb = the packbuilder 235 * 236 * Returns: the number of objects in the packfile 237 */ 238 //GIT_EXTERN 239 size_t git_packbuilder_object_count(libgit2_d.types.git_packbuilder* pb); 240 241 /** 242 * Get the number of objects the packbuilder has already written out 243 * 244 * Params: 245 * pb = the packbuilder 246 * 247 * Returns: the number of objects which have already been written 248 */ 249 //GIT_EXTERN 250 size_t git_packbuilder_written(libgit2_d.types.git_packbuilder* pb); 251 252 /** 253 * Packbuilder progress notification function 254 */ 255 alias git_packbuilder_progress = int function(int stage, uint current, uint total, void* payload); 256 257 /** 258 * Set the callbacks for a packbuilder 259 * 260 * Params: 261 * pb = The packbuilder object 262 * progress_cb = Function to call with progress information during pack building. Be aware that this is called inline with pack building operations, so performance may be affected. 263 * progress_cb_payload = Payload for progress callback. 264 * 265 * Returns: 0 or an error code 266 */ 267 //GIT_EXTERN 268 int git_packbuilder_set_callbacks(libgit2_d.types.git_packbuilder* pb, .git_packbuilder_progress progress_cb, void* progress_cb_payload); 269 270 /** 271 * Free the packbuilder and all associated data 272 * 273 * Params: 274 * pb = The packbuilder 275 */ 276 //GIT_EXTERN 277 void git_packbuilder_free(libgit2_d.types.git_packbuilder* pb); 278 279 /** @} */