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.indexer; 8 9 10 private static import libgit2_d.oid; 11 private static import libgit2_d.types; 12 13 extern (C): 14 nothrow @nogc: 15 public: 16 17 /** 18 * A git indexer object 19 */ 20 struct git_indexer; 21 22 /** 23 * This structure is used to provide callers information about the 24 * progress of indexing a packfile, either directly or part of a 25 * fetch or clone that downloads a packfile. 26 */ 27 struct git_indexer_progress 28 { 29 /** 30 * number of objects in the packfile being indexed 31 */ 32 uint total_objects; 33 34 /** 35 * received objects that have been hashed 36 */ 37 uint indexed_objects; 38 39 /** 40 * received_objects: objects which have been downloaded 41 */ 42 uint received_objects; 43 44 /** 45 * locally-available objects that have been injected in order 46 * to fix a thin pack 47 */ 48 uint local_objects; 49 50 /** 51 * number of deltas in the packfile being indexed 52 */ 53 uint total_deltas; 54 55 /** 56 * received deltas that have been indexed 57 */ 58 uint indexed_deltas; 59 60 /** 61 * size of the packfile received up to now 62 */ 63 size_t received_bytes; 64 } 65 66 /** 67 * Type for progress callbacks during indexing. Return a value less 68 * than zero to cancel the indexing or download. 69 * 70 * Params: 71 * stats = Structure containing information about the state of the tran sfer 72 * payload = Payload provided by caller 73 */ 74 alias git_indexer_progress_cb = int function(const (.git_indexer_progress)* stats, void* payload); 75 76 /** 77 * Options for indexer configuration 78 */ 79 struct git_indexer_options 80 { 81 uint version_; 82 83 /** 84 * progress_cb function to call with progress information 85 */ 86 .git_indexer_progress_cb progress_cb; 87 88 /** 89 * progress_cb_payload payload for the progress callback 90 */ 91 void* progress_cb_payload; 92 93 /** 94 * Do connectivity checks for the received pack 95 */ 96 ubyte verify; 97 } 98 99 enum GIT_INDEXER_OPTIONS_VERSION = 1; 100 101 pragma(inline, true) 102 pure nothrow @safe @nogc 103 .git_indexer_options GIT_INDEXER_OPTIONS_INIT() 104 105 do 106 { 107 .git_indexer_options OUTPUT = 108 { 109 version_: .GIT_INDEXER_OPTIONS_VERSION, 110 }; 111 112 return OUTPUT; 113 } 114 115 /** 116 * Initializes a `git_indexer_options` with default values. Equivalent to 117 * creating an instance with GIT_INDEXER_OPTIONS_INIT. 118 * 119 * Params: 120 * opts = the `git_indexer_options` struct to initialize. 121 * version = Version of struct; pass `GIT_INDEXER_OPTIONS_VERSION` 122 * 123 * Returns: Zero on success; -1 on failure. 124 */ 125 //GIT_EXTERN 126 int git_indexer_options_init(.git_indexer_options* opts, uint version_); 127 128 /** 129 * Create a new indexer instance 130 * 131 * Params: 132 * out_ = where to store the indexer instance 133 * path = to the directory where the packfile should be stored 134 * mode = permissions to use creating packfile or 0 for defaults 135 * 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) 136 * opts = Optional structure containing additional options. See `git_indexer_options` above. 137 */ 138 //GIT_EXTERN 139 int git_indexer_new(.git_indexer** out_, const (char)* path, uint mode, libgit2_d.types.git_odb* odb, .git_indexer_options* opts); 140 141 /** 142 * Add data to the indexer 143 * 144 * Params: 145 * idx = the indexer 146 * data = the data to add 147 * size = the size of the data in bytes 148 * stats = stat storage 149 */ 150 //GIT_EXTERN 151 int git_indexer_append(.git_indexer* idx, const (void)* data, size_t size, .git_indexer_progress* stats); 152 153 /** 154 * Finalize the pack and index 155 * 156 * Resolve any pending deltas and write out the index file 157 * 158 * Params: 159 * idx = the indexer 160 */ 161 //GIT_EXTERN 162 int git_indexer_commit(.git_indexer* idx, .git_indexer_progress* stats); 163 164 /** 165 * Get the packfile's hash 166 * 167 * A packfile's name is derived from the sorted hashing of all object 168 * names. This is only correct after the index has been finalized. 169 * 170 * Params: 171 * idx = the indexer instance 172 */ 173 //GIT_EXTERN 174 const (libgit2_d.oid.git_oid)* git_indexer_hash(const (.git_indexer)* idx); 175 176 /** 177 * Free the indexer and its resources 178 * 179 * Params: 180 * idx = the indexer to free 181 */ 182 //GIT_EXTERN 183 void git_indexer_free(.git_indexer* idx);