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