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 /** 8 * License: GPL-2.0(Linking Exception) 9 */ 10 module libgit2.indexer; 11 12 13 private static import libgit2.oid; 14 private static import libgit2.types; 15 private import libgit2.common: GIT_EXTERN; 16 17 extern (C): 18 nothrow @nogc: 19 public: 20 21 /** 22 * A git indexer object 23 */ 24 struct git_indexer; 25 26 /** 27 * This structure is used to provide callers information about the 28 * progress of indexing a packfile, either directly or part of a 29 * fetch or clone that downloads a packfile. 30 */ 31 struct git_indexer_progress 32 { 33 /** 34 * number of objects in the packfile being indexed 35 */ 36 uint total_objects; 37 38 /** 39 * received objects that have been hashed 40 */ 41 uint indexed_objects; 42 43 /** 44 * received_objects: objects which have been downloaded 45 */ 46 uint received_objects; 47 48 /** 49 * locally-available objects that have been injected in order 50 * to fix a thin pack 51 */ 52 uint local_objects; 53 54 /** 55 * number of deltas in the packfile being indexed 56 */ 57 uint total_deltas; 58 59 /** 60 * received deltas that have been indexed 61 */ 62 uint indexed_deltas; 63 64 /** 65 * size of the packfile received up to now 66 */ 67 size_t received_bytes; 68 } 69 70 /** 71 * Type for progress callbacks during indexing. Return a value less 72 * than zero to cancel the indexing or download. 73 */ 74 /* 75 * Params: 76 * stats = Structure containing information about the state of the transfer 77 * payload = Payload provided by caller 78 */ 79 alias git_indexer_progress_cb = int function(const (.git_indexer_progress)* stats, void* payload); 80 81 /** 82 * Options for indexer configuration 83 */ 84 struct git_indexer_options 85 { 86 uint version_; 87 88 version (GIT_EXPERIMENTAL_SHA256) { 89 /** 90 * permissions to use creating packfile or 0 for defaults 91 */ 92 uint mode; 93 94 /** 95 * object database from which to read base objects when 96 * fixing thin packs. This can be NULL if there are no thin 97 * packs; if a thin pack is encountered, an error will be 98 * returned if there are bases missing. 99 */ 100 git_odb* odb; 101 } 102 103 /** 104 * progress_cb function to call with progress information 105 */ 106 .git_indexer_progress_cb progress_cb; 107 108 /** 109 * progress_cb_payload payload for the progress callback 110 */ 111 void* progress_cb_payload; 112 113 /** 114 * Do connectivity checks for the received pack 115 */ 116 ubyte verify; 117 } 118 119 enum GIT_INDEXER_OPTIONS_VERSION = 1; 120 121 pragma(inline, true) 122 pure nothrow @safe @nogc @live 123 .git_indexer_options GIT_INDEXER_OPTIONS_INIT() 124 125 do 126 { 127 .git_indexer_options OUTPUT = 128 { 129 version_: .GIT_INDEXER_OPTIONS_VERSION, 130 }; 131 132 return OUTPUT; 133 } 134 135 /** 136 * Initializes a `git_indexer_options` with default values. Equivalent to 137 * creating an instance with GIT_INDEXER_OPTIONS_INIT. 138 * 139 * Returns: Zero on success; -1 on failure. 140 */ 141 /* 142 * Params: 143 * opts = the `git_indexer_options` struct to initialize. 144 * version_ = Version of struct; pass `GIT_INDEXER_OPTIONS_VERSION` 145 */ 146 @GIT_EXTERN 147 int git_indexer_options_init(.git_indexer_options* opts, uint version_); 148 149 version (GIT_EXPERIMENTAL_SHA256) { 150 /** 151 * Create a new indexer instance 152 * 153 * @param out_ where to store the indexer instance 154 * @param path to the directory where the packfile should be stored 155 * @param oid_type the oid type to use for objects 156 * @return 0 or an error code. 157 */ 158 @GIT_EXTERN 159 int git_indexer_new(.git_indexer** out_, const (char)* path, libgit2.oid.git_oid_t oid_type, .git_indexer_options* opts); 160 } else { 161 /** 162 * Create a new indexer instance 163 * 164 * Params: 165 * out_ = where to store the indexer instance 166 * path = to the directory where the packfile should be stored 167 * mode = permissions to use creating packfile or 0 for defaults 168 * odb = object database from which to read base objects when fixing thin packs. Pass null if no thin pack is expected (an error will be returned if there are bases missing) 169 * opts = Optional structure containing additional options. See `git_indexer_options` above. 170 * 171 * Returns: 0 or an error code. 172 */ 173 @GIT_EXTERN 174 int git_indexer_new(.git_indexer** out_, const (char)* path, uint mode, libgit2.types.git_odb* odb, .git_indexer_options* opts); 175 } 176 177 /** 178 * Add data to the indexer 179 * 180 * Params: 181 * idx = the indexer 182 * data = the data to add 183 * size = the size of the data in bytes 184 * stats = stat storage 185 * 186 * Returns: 0 or an error code. 187 */ 188 @GIT_EXTERN 189 int git_indexer_append(.git_indexer* idx, const (void)* data, size_t size, .git_indexer_progress* stats); 190 191 /** 192 * Finalize the pack and index 193 * 194 * Resolve any pending deltas and write out the index file 195 * 196 * Params: 197 * idx = the indexer 198 * stats = Stat storage. 199 * 200 * Returns: 0 or an error code. 201 */ 202 @GIT_EXTERN 203 int git_indexer_commit(.git_indexer* idx, .git_indexer_progress* stats); 204 205 version (GIT_DEPRECATE_HARD) { 206 } else { 207 /** 208 * Get the packfile's hash 209 * 210 * A packfile's name is derived from the sorted hashing of all object 211 * names. This is only correct after the index has been finalized. 212 * 213 * @deprecated use git_indexer_name 214 * @param idx the indexer instance 215 * @return the packfile's hash 216 */ 217 @GIT_EXTERN 218 const (libgit2.oid.git_oid)* git_indexer_hash(const (.git_indexer)* idx); 219 } 220 221 /** 222 * Get the unique name for the resulting packfile. 223 * 224 * The packfile's name is derived from the packfile's content. 225 * This is only correct after the index has been finalized. 226 * 227 * Params: 228 * idx = the indexer instance 229 * 230 * Returns: a null terminated string for the packfile name 231 */ 232 @GIT_EXTERN 233 const (char)* git_indexer_name(const (.git_indexer)* idx); 234 235 /** 236 * Free the indexer and its resources 237 * 238 * Params: 239 * idx = the indexer to free 240 */ 241 @GIT_EXTERN 242 void git_indexer_free(.git_indexer* idx);