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  * @param stats Structure containing information about the state of the tran    sfer
71  * @param payload Payload provided by caller
72  */
73 alias git_indexer_progress_cb = int function(const (.git_indexer_progress)* stats, void* payload);
74 
75 /**
76  * Options for indexer configuration
77  */
78 struct git_indexer_options
79 {
80 	uint version_;
81 
82 	/**
83 	 * progress_cb function to call with progress information
84 	 */
85 	.git_indexer_progress_cb progress_cb;
86 
87 	/**
88 	 * progress_cb_payload payload for the progress callback
89 	 */
90 	void* progress_cb_payload;
91 
92 	/**
93 	 * Do connectivity checks for the received pack
94 	 */
95 	ubyte verify;
96 }
97 
98 enum GIT_INDEXER_OPTIONS_VERSION = 1;
99 
100 pragma(inline, true)
101 pure nothrow @safe @nogc
102 .git_indexer_options GIT_INDEXER_OPTIONS_INIT()
103 
104 	do
105 	{
106 		.git_indexer_options OUTPUT =
107 		{
108 			version_: .GIT_INDEXER_OPTIONS_VERSION,
109 		};
110 
111 		return OUTPUT;
112 	}
113 
114 /**
115  * Initializes a `git_indexer_options` with default values. Equivalent to
116  * creating an instance with GIT_INDEXER_OPTIONS_INIT.
117  *
118  * @param opts the `git_indexer_options` struct to initialize.
119  * @param version Version of struct; pass `GIT_INDEXER_OPTIONS_VERSION`
120  * @return Zero on success; -1 on failure.
121  */
122 //GIT_EXTERN
123 int git_indexer_options_init(.git_indexer_options* opts, uint version_);
124 
125 /**
126  * Create a new indexer instance
127  *
128  * @param out_ where to store the indexer instance
129  * @param path to the directory where the packfile should be stored
130  * @param mode permissions to use creating packfile or 0 for defaults
131  * @param odb object database from which to read base objects when
132  * fixing thin packs. Pass null if no thin pack is expected (an error
133  * will be returned if there are bases missing)
134  * @param opts Optional structure containing additional options. See
135  * `git_indexer_options` above.
136  */
137 //GIT_EXTERN
138 int git_indexer_new(.git_indexer** out_, const (char)* path, uint mode, libgit2_d.types.git_odb* odb, .git_indexer_options* opts);
139 
140 /**
141  * Add data to the indexer
142  *
143  * @param idx the indexer
144  * @param data the data to add
145  * @param size the size of the data in bytes
146  * @param stats stat storage
147  */
148 //GIT_EXTERN
149 int git_indexer_append(.git_indexer* idx, const (void)* data, size_t size, .git_indexer_progress* stats);
150 
151 /**
152  * Finalize the pack and index
153  *
154  * Resolve any pending deltas and write out the index file
155  *
156  * @param idx the indexer
157  */
158 //GIT_EXTERN
159 int git_indexer_commit(.git_indexer* idx, .git_indexer_progress* stats);
160 
161 /**
162  * Get the packfile's hash
163  *
164  * A packfile's name is derived from the sorted hashing of all object
165  * names. This is only correct after the index has been finalized.
166  *
167  * @param idx the indexer instance
168  */
169 //GIT_EXTERN
170 const (libgit2_d.oid.git_oid)* git_indexer_hash(const (.git_indexer)* idx);
171 
172 /**
173  * Free the indexer and its resources
174  *
175  * @param idx the indexer to free
176  */
177 //GIT_EXTERN
178 void git_indexer_free(.git_indexer* idx);