]> git.proxmox.com Git - libgit2.git/blob - include/git2/types.h
Merge pull request #4097 from implausible/fix/auto-detect-proxy-callbacks
[libgit2.git] / include / git2 / types.h
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 #ifndef INCLUDE_git_types_h__
8 #define INCLUDE_git_types_h__
9
10 #include "common.h"
11
12 /**
13 * @file git2/types.h
14 * @brief libgit2 base & compatibility types
15 * @ingroup Git
16 * @{
17 */
18 GIT_BEGIN_DECL
19
20 /**
21 * Cross-platform compatibility types for off_t / time_t
22 *
23 * NOTE: This needs to be in a public header so that both the library
24 * implementation and client applications both agree on the same types.
25 * Otherwise we get undefined behavior.
26 *
27 * Use the "best" types that each platform provides. Currently we truncate
28 * these intermediate representations for compatibility with the git ABI, but
29 * if and when it changes to support 64 bit types, our code will naturally
30 * adapt.
31 * NOTE: These types should match those that are returned by our internal
32 * stat() functions, for all platforms.
33 */
34 #include <sys/types.h>
35 #ifdef __amigaos4__
36 #include <stdint.h>
37 #endif
38
39 #if defined(_MSC_VER)
40
41 typedef __int64 git_off_t;
42 typedef __time64_t git_time_t;
43
44 #elif defined(__MINGW32__)
45
46 typedef off64_t git_off_t;
47 typedef __time64_t git_time_t;
48
49 #elif defined(__HAIKU__)
50
51 typedef __haiku_std_int64 git_off_t;
52 typedef __haiku_std_int64 git_time_t;
53
54 #else /* POSIX */
55
56 /*
57 * Note: Can't use off_t since if a client program includes <sys/types.h>
58 * before us (directly or indirectly), they'll get 32 bit off_t in their client
59 * app, even though /we/ define _FILE_OFFSET_BITS=64.
60 */
61 typedef int64_t git_off_t;
62 typedef int64_t git_time_t;
63
64 #endif
65
66 /** Basic type (loose or packed) of any Git object. */
67 typedef enum {
68 GIT_OBJ_ANY = -2, /**< Object can be any of the following */
69 GIT_OBJ_BAD = -1, /**< Object is invalid. */
70 GIT_OBJ__EXT1 = 0, /**< Reserved for future use. */
71 GIT_OBJ_COMMIT = 1, /**< A commit object. */
72 GIT_OBJ_TREE = 2, /**< A tree (directory listing) object. */
73 GIT_OBJ_BLOB = 3, /**< A file revision object. */
74 GIT_OBJ_TAG = 4, /**< An annotated tag object. */
75 GIT_OBJ__EXT2 = 5, /**< Reserved for future use. */
76 GIT_OBJ_OFS_DELTA = 6, /**< A delta, base is given by an offset. */
77 GIT_OBJ_REF_DELTA = 7, /**< A delta, base is given by object id. */
78 } git_otype;
79
80 /** An open object database handle. */
81 typedef struct git_odb git_odb;
82
83 /** A custom backend in an ODB */
84 typedef struct git_odb_backend git_odb_backend;
85
86 /** An object read from the ODB */
87 typedef struct git_odb_object git_odb_object;
88
89 /** A stream to read/write from the ODB */
90 typedef struct git_odb_stream git_odb_stream;
91
92 /** A stream to write a packfile to the ODB */
93 typedef struct git_odb_writepack git_odb_writepack;
94
95 /** An open refs database handle. */
96 typedef struct git_refdb git_refdb;
97
98 /** A custom backend for refs */
99 typedef struct git_refdb_backend git_refdb_backend;
100
101 /**
102 * Representation of an existing git repository,
103 * including all its object contents
104 */
105 typedef struct git_repository git_repository;
106
107 /** Representation of a working tree */
108 typedef struct git_worktree git_worktree;
109
110 /** Representation of a generic object in a repository */
111 typedef struct git_object git_object;
112
113 /** Representation of an in-progress walk through the commits in a repo */
114 typedef struct git_revwalk git_revwalk;
115
116 /** Parsed representation of a tag object. */
117 typedef struct git_tag git_tag;
118
119 /** In-memory representation of a blob object. */
120 typedef struct git_blob git_blob;
121
122 /** Parsed representation of a commit object. */
123 typedef struct git_commit git_commit;
124
125 /** Representation of each one of the entries in a tree object. */
126 typedef struct git_tree_entry git_tree_entry;
127
128 /** Representation of a tree object. */
129 typedef struct git_tree git_tree;
130
131 /** Constructor for in-memory trees */
132 typedef struct git_treebuilder git_treebuilder;
133
134 /** Memory representation of an index file. */
135 typedef struct git_index git_index;
136
137 /** An iterator for conflicts in the index. */
138 typedef struct git_index_conflict_iterator git_index_conflict_iterator;
139
140 /** Memory representation of a set of config files */
141 typedef struct git_config git_config;
142
143 /** Interface to access a configuration file */
144 typedef struct git_config_backend git_config_backend;
145
146 /** Representation of a reference log entry */
147 typedef struct git_reflog_entry git_reflog_entry;
148
149 /** Representation of a reference log */
150 typedef struct git_reflog git_reflog;
151
152 /** Representation of a git note */
153 typedef struct git_note git_note;
154
155 /** Representation of a git packbuilder */
156 typedef struct git_packbuilder git_packbuilder;
157
158 /** Time in a signature */
159 typedef struct git_time {
160 git_time_t time; /**< time in seconds from epoch */
161 int offset; /**< timezone offset, in minutes */
162 } git_time;
163
164 /** An action signature (e.g. for committers, taggers, etc) */
165 typedef struct git_signature {
166 char *name; /**< full name of the author */
167 char *email; /**< email of the author */
168 git_time when; /**< time when the action happened */
169 } git_signature;
170
171 /** In-memory representation of a reference. */
172 typedef struct git_reference git_reference;
173
174 /** Iterator for references */
175 typedef struct git_reference_iterator git_reference_iterator;
176
177 /** Transactional interface to references */
178 typedef struct git_transaction git_transaction;
179
180 /** Annotated commits, the input to merge and rebase. */
181 typedef struct git_annotated_commit git_annotated_commit;
182
183 /** Merge result */
184 typedef struct git_merge_result git_merge_result;
185
186 /** Representation of a status collection */
187 typedef struct git_status_list git_status_list;
188
189 /** Representation of a rebase */
190 typedef struct git_rebase git_rebase;
191
192 /** Basic type of any Git reference. */
193 typedef enum {
194 GIT_REF_INVALID = 0, /**< Invalid reference */
195 GIT_REF_OID = 1, /**< A reference which points at an object id */
196 GIT_REF_SYMBOLIC = 2, /**< A reference which points at another reference */
197 GIT_REF_LISTALL = GIT_REF_OID|GIT_REF_SYMBOLIC,
198 } git_ref_t;
199
200 /** Basic type of any Git branch. */
201 typedef enum {
202 GIT_BRANCH_LOCAL = 1,
203 GIT_BRANCH_REMOTE = 2,
204 GIT_BRANCH_ALL = GIT_BRANCH_LOCAL|GIT_BRANCH_REMOTE,
205 } git_branch_t;
206
207 /** Valid modes for index and tree entries. */
208 typedef enum {
209 GIT_FILEMODE_UNREADABLE = 0000000,
210 GIT_FILEMODE_TREE = 0040000,
211 GIT_FILEMODE_BLOB = 0100644,
212 GIT_FILEMODE_BLOB_EXECUTABLE = 0100755,
213 GIT_FILEMODE_LINK = 0120000,
214 GIT_FILEMODE_COMMIT = 0160000,
215 } git_filemode_t;
216
217 /*
218 * A refspec specifies the mapping between remote and local reference
219 * names when fetch or pushing.
220 */
221 typedef struct git_refspec git_refspec;
222
223 /**
224 * Git's idea of a remote repository. A remote can be anonymous (in
225 * which case it does not have backing configuration entires).
226 */
227 typedef struct git_remote git_remote;
228
229 /**
230 * Interface which represents a transport to communicate with a
231 * remote.
232 */
233 typedef struct git_transport git_transport;
234
235 /**
236 * Preparation for a push operation. Can be used to configure what to
237 * push and the level of parallelism of the packfile builder.
238 */
239 typedef struct git_push git_push;
240
241 /* documentation in the definition */
242 typedef struct git_remote_head git_remote_head;
243 typedef struct git_remote_callbacks git_remote_callbacks;
244
245 /**
246 * This is passed as the first argument to the callback to allow the
247 * user to see the progress.
248 *
249 * - total_objects: number of objects in the packfile being downloaded
250 * - indexed_objects: received objects that have been hashed
251 * - received_objects: objects which have been downloaded
252 * - local_objects: locally-available objects that have been injected
253 * in order to fix a thin pack.
254 * - received-bytes: size of the packfile received up to now
255 */
256 typedef struct git_transfer_progress {
257 unsigned int total_objects;
258 unsigned int indexed_objects;
259 unsigned int received_objects;
260 unsigned int local_objects;
261 unsigned int total_deltas;
262 unsigned int indexed_deltas;
263 size_t received_bytes;
264 } git_transfer_progress;
265
266 /**
267 * Type for progress callbacks during indexing. Return a value less than zero
268 * to cancel the transfer.
269 *
270 * @param stats Structure containing information about the state of the transfer
271 * @param payload Payload provided by caller
272 */
273 typedef int (*git_transfer_progress_cb)(const git_transfer_progress *stats, void *payload);
274
275 /**
276 * Type for messages delivered by the transport. Return a negative value
277 * to cancel the network operation.
278 *
279 * @param str The message from the transport
280 * @param len The length of the message
281 * @param payload Payload provided by the caller
282 */
283 typedef int (*git_transport_message_cb)(const char *str, int len, void *payload);
284
285
286 /**
287 * Type of host certificate structure that is passed to the check callback
288 */
289 typedef enum git_cert_t {
290 /**
291 * No information about the certificate is available. This may
292 * happen when using curl.
293 */
294 GIT_CERT_NONE,
295 /**
296 * The `data` argument to the callback will be a pointer to
297 * the DER-encoded data.
298 */
299 GIT_CERT_X509,
300 /**
301 * The `data` argument to the callback will be a pointer to a
302 * `git_cert_hostkey` structure.
303 */
304 GIT_CERT_HOSTKEY_LIBSSH2,
305 /**
306 * The `data` argument to the callback will be a pointer to a
307 * `git_strarray` with `name:content` strings containing
308 * information about the certificate. This is used when using
309 * curl.
310 */
311 GIT_CERT_STRARRAY,
312 } git_cert_t;
313
314 /**
315 * Parent type for `git_cert_hostkey` and `git_cert_x509`.
316 */
317 typedef struct {
318 /**
319 * Type of certificate. A `GIT_CERT_` value.
320 */
321 git_cert_t cert_type;
322 } git_cert;
323
324 /**
325 * Callback for the user's custom certificate checks.
326 *
327 * @param cert The host certificate
328 * @param valid Whether the libgit2 checks (OpenSSL or WinHTTP) think
329 * this certificate is valid
330 * @param host Hostname of the host libgit2 connected to
331 * @param payload Payload provided by the caller
332 */
333 typedef int (*git_transport_certificate_check_cb)(git_cert *cert, int valid, const char *host, void *payload);
334
335 /**
336 * Opaque structure representing a submodule.
337 */
338 typedef struct git_submodule git_submodule;
339
340 /**
341 * Submodule update values
342 *
343 * These values represent settings for the `submodule.$name.update`
344 * configuration value which says how to handle `git submodule update` for
345 * this submodule. The value is usually set in the ".gitmodules" file and
346 * copied to ".git/config" when the submodule is initialized.
347 *
348 * You can override this setting on a per-submodule basis with
349 * `git_submodule_set_update()` and write the changed value to disk using
350 * `git_submodule_save()`. If you have overwritten the value, you can
351 * revert it by passing `GIT_SUBMODULE_UPDATE_RESET` to the set function.
352 *
353 * The values are:
354 *
355 * - GIT_SUBMODULE_UPDATE_CHECKOUT: the default; when a submodule is
356 * updated, checkout the new detached HEAD to the submodule directory.
357 * - GIT_SUBMODULE_UPDATE_REBASE: update by rebasing the current checked
358 * out branch onto the commit from the superproject.
359 * - GIT_SUBMODULE_UPDATE_MERGE: update by merging the commit in the
360 * superproject into the current checkout out branch of the submodule.
361 * - GIT_SUBMODULE_UPDATE_NONE: do not update this submodule even when
362 * the commit in the superproject is updated.
363 * - GIT_SUBMODULE_UPDATE_DEFAULT: not used except as static initializer
364 * when we don't want any particular update rule to be specified.
365 */
366 typedef enum {
367 GIT_SUBMODULE_UPDATE_CHECKOUT = 1,
368 GIT_SUBMODULE_UPDATE_REBASE = 2,
369 GIT_SUBMODULE_UPDATE_MERGE = 3,
370 GIT_SUBMODULE_UPDATE_NONE = 4,
371
372 GIT_SUBMODULE_UPDATE_DEFAULT = 0
373 } git_submodule_update_t;
374
375 /**
376 * Submodule ignore values
377 *
378 * These values represent settings for the `submodule.$name.ignore`
379 * configuration value which says how deeply to look at the working
380 * directory when getting submodule status.
381 *
382 * You can override this value in memory on a per-submodule basis with
383 * `git_submodule_set_ignore()` and can write the changed value to disk
384 * with `git_submodule_save()`. If you have overwritten the value, you
385 * can revert to the on disk value by using `GIT_SUBMODULE_IGNORE_RESET`.
386 *
387 * The values are:
388 *
389 * - GIT_SUBMODULE_IGNORE_UNSPECIFIED: use the submodule's configuration
390 * - GIT_SUBMODULE_IGNORE_NONE: don't ignore any change - i.e. even an
391 * untracked file, will mark the submodule as dirty. Ignored files are
392 * still ignored, of course.
393 * - GIT_SUBMODULE_IGNORE_UNTRACKED: ignore untracked files; only changes
394 * to tracked files, or the index or the HEAD commit will matter.
395 * - GIT_SUBMODULE_IGNORE_DIRTY: ignore changes in the working directory,
396 * only considering changes if the HEAD of submodule has moved from the
397 * value in the superproject.
398 * - GIT_SUBMODULE_IGNORE_ALL: never check if the submodule is dirty
399 * - GIT_SUBMODULE_IGNORE_DEFAULT: not used except as static initializer
400 * when we don't want any particular ignore rule to be specified.
401 */
402 typedef enum {
403 GIT_SUBMODULE_IGNORE_UNSPECIFIED = -1, /**< use the submodule's configuration */
404
405 GIT_SUBMODULE_IGNORE_NONE = 1, /**< any change or untracked == dirty */
406 GIT_SUBMODULE_IGNORE_UNTRACKED = 2, /**< dirty if tracked files change */
407 GIT_SUBMODULE_IGNORE_DIRTY = 3, /**< only dirty if HEAD moved */
408 GIT_SUBMODULE_IGNORE_ALL = 4, /**< never dirty */
409 } git_submodule_ignore_t;
410
411 /**
412 * Options for submodule recurse.
413 *
414 * Represent the value of `submodule.$name.fetchRecurseSubmodules`
415 *
416 * * GIT_SUBMODULE_RECURSE_NO - do no recurse into submodules
417 * * GIT_SUBMODULE_RECURSE_YES - recurse into submodules
418 * * GIT_SUBMODULE_RECURSE_ONDEMAND - recurse into submodules only when
419 * commit not already in local clone
420 */
421 typedef enum {
422 GIT_SUBMODULE_RECURSE_NO = 0,
423 GIT_SUBMODULE_RECURSE_YES = 1,
424 GIT_SUBMODULE_RECURSE_ONDEMAND = 2,
425 } git_submodule_recurse_t;
426
427 /** A type to write in a streaming fashion, for example, for filters. */
428 typedef struct git_writestream git_writestream;
429
430 struct git_writestream {
431 int (*write)(git_writestream *stream, const char *buffer, size_t len);
432 int (*close)(git_writestream *stream);
433 void (*free)(git_writestream *stream);
434 };
435
436 /** @} */
437 GIT_END_DECL
438
439 #endif