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 * @param out_ The new packbuilder object 65 * @param repo The repository 66 * 67 * @return 0 or an error code 68 */ 69 //GIT_EXTERN 70 int git_packbuilder_new(libgit2_d.types.git_packbuilder** out_, libgit2_d.types.git_repository* repo); 71 72 /** 73 * Set number of threads to spawn 74 * 75 * By default, libgit2 won't spawn any threads at all; 76 * when set to 0, libgit2 will autodetect the number of 77 * CPUs. 78 * 79 * @param pb The packbuilder 80 * @param n Number of threads to spawn 81 * @return number of actual threads to be used 82 */ 83 //GIT_EXTERN 84 uint git_packbuilder_set_threads(libgit2_d.types.git_packbuilder* pb, uint n); 85 86 /** 87 * Insert a single object 88 * 89 * For an optimal pack it's mandatory to insert objects in recency order, 90 * commits followed by trees and blobs. 91 * 92 * @param pb The packbuilder 93 * @param id The oid of the commit 94 * @param name The name; might be null 95 * 96 * @return 0 or an error code 97 */ 98 //GIT_EXTERN 99 int git_packbuilder_insert(libgit2_d.types.git_packbuilder* pb, const (libgit2_d.oid.git_oid)* id, const (char)* name); 100 101 /** 102 * Insert a root tree object 103 * 104 * This will add the tree as well as all referenced trees and blobs. 105 * 106 * @param pb The packbuilder 107 * @param id The oid of the root tree 108 * 109 * @return 0 or an error code 110 */ 111 //GIT_EXTERN 112 int git_packbuilder_insert_tree(libgit2_d.types.git_packbuilder* pb, const (libgit2_d.oid.git_oid)* id); 113 114 /** 115 * Insert a commit object 116 * 117 * This will add a commit as well as the completed referenced tree. 118 * 119 * @param pb The packbuilder 120 * @param id The oid of the commit 121 * 122 * @return 0 or an error code 123 */ 124 //GIT_EXTERN 125 int git_packbuilder_insert_commit(libgit2_d.types.git_packbuilder* pb, const (libgit2_d.oid.git_oid)* id); 126 127 /** 128 * Insert objects as given by the walk 129 * 130 * Those commits and all objects they reference will be inserted into 131 * the packbuilder. 132 * 133 * @param pb the packbuilder 134 * @param walk the revwalk to use to fill the packbuilder 135 * 136 * @return 0 or an error code 137 */ 138 //GIT_EXTERN 139 int git_packbuilder_insert_walk(libgit2_d.types.git_packbuilder* pb, libgit2_d.types.git_revwalk* walk); 140 141 /** 142 * Recursively insert an object and its referenced objects 143 * 144 * Insert the object as well as any object it references. 145 * 146 * @param pb the packbuilder 147 * @param id the id of the root object to insert 148 * @param name optional name for the object 149 * @return 0 or an error code 150 */ 151 //GIT_EXTERN 152 int git_packbuilder_insert_recur(libgit2_d.types.git_packbuilder* pb, const (libgit2_d.oid.git_oid)* id, const (char)* name); 153 154 /** 155 * Write the contents of the packfile to an in-memory buffer 156 * 157 * The contents of the buffer will become a valid packfile, even though there 158 * will be no attached index 159 * 160 * @param buf Buffer where to write the packfile 161 * @param pb The packbuilder 162 */ 163 //GIT_EXTERN 164 int git_packbuilder_write_buf(libgit2_d.buffer.git_buf* buf, libgit2_d.types.git_packbuilder* pb); 165 166 /** 167 * Write the new pack and corresponding index file to path. 168 * 169 * @param pb The packbuilder 170 * @param path to the directory where the packfile and index should be stored 171 * @param mode permissions to use creating a packfile or 0 for defaults 172 * @param progress_cb function to call with progress information from the 173 * indexer (optional) 174 * @param progress_cb_payload payload for the progress callback (optional) 175 * 176 * @return 0 or an error code 177 */ 178 //GIT_EXTERN 179 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); 180 181 /** 182 * Get the packfile's hash 183 * 184 * A packfile's name is derived from the sorted hashing of all object 185 * names. This is only correct after the packfile has been written. 186 * 187 * @param pb The packbuilder object 188 */ 189 //GIT_EXTERN 190 const (libgit2_d.oid.git_oid)* git_packbuilder_hash(libgit2_d.types.git_packbuilder* pb); 191 192 /** 193 * Callback used to iterate over packed objects 194 * 195 * @see git_packbuilder_foreach 196 * 197 * @param buf A pointer to the object's data 198 * @param size The size of the underlying object 199 * @param payload Payload passed to git_packbuilder_foreach 200 * @return non-zero to terminate the iteration 201 */ 202 alias git_packbuilder_foreach_cb = int function(void* buf, size_t size, void* payload); 203 204 /** 205 * Create the new pack and pass each object to the callback 206 * 207 * @param pb the packbuilder 208 * @param cb the callback to call with each packed object's buffer 209 * @param payload the callback's data 210 * @return 0 or an error code 211 */ 212 //GIT_EXTERN 213 int git_packbuilder_foreach(libgit2_d.types.git_packbuilder* pb, .git_packbuilder_foreach_cb cb, void* payload); 214 215 /** 216 * Get the total number of objects the packbuilder will write out 217 * 218 * @param pb the packbuilder 219 * @return the number of objects in the packfile 220 */ 221 //GIT_EXTERN 222 size_t git_packbuilder_object_count(libgit2_d.types.git_packbuilder* pb); 223 224 /** 225 * Get the number of objects the packbuilder has already written out 226 * 227 * @param pb the packbuilder 228 * @return the number of objects which have already been written 229 */ 230 //GIT_EXTERN 231 size_t git_packbuilder_written(libgit2_d.types.git_packbuilder* pb); 232 233 /** 234 * Packbuilder progress notification function 235 */ 236 alias git_packbuilder_progress = int function(int stage, uint current, uint total, void* payload); 237 238 /** 239 * Set the callbacks for a packbuilder 240 * 241 * @param pb The packbuilder object 242 * @param progress_cb Function to call with progress information during 243 * pack building. Be aware that this is called inline with pack building 244 * operations, so performance may be affected. 245 * @param progress_cb_payload Payload for progress callback. 246 * @return 0 or an error code 247 */ 248 //GIT_EXTERN 249 int git_packbuilder_set_callbacks(libgit2_d.types.git_packbuilder* pb, .git_packbuilder_progress progress_cb, void* progress_cb_payload); 250 251 /** 252 * Free the packbuilder and all associated data 253 * 254 * @param pb The packbuilder 255 */ 256 //GIT_EXTERN 257 void git_packbuilder_free(libgit2_d.types.git_packbuilder* pb); 258 259 /** @} */