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; /**< time in seconds from epoch */
63 
64 #endif
65 
66 /** The maximum size of an object */
67 typedef uint64_t git_object_size_t;
68 
69 #include "buffer.h"
70 #include "oid.h"
71 
72 /** Basic type (loose or packed) of any Git object. */
73 typedef enum {
74 	GIT_OBJECT_ANY =      -2, /**< Object can be any of the following */
75 	GIT_OBJECT_INVALID =  -1, /**< Object is invalid. */
76 	GIT_OBJECT_COMMIT =    1, /**< A commit object. */
77 	GIT_OBJECT_TREE =      2, /**< A tree (directory listing) object. */
78 	GIT_OBJECT_BLOB =      3, /**< A file revision object. */
79 	GIT_OBJECT_TAG =       4, /**< An annotated tag object. */
80 	GIT_OBJECT_OFS_DELTA = 6, /**< A delta, base is given by an offset. */
81 	GIT_OBJECT_REF_DELTA = 7, /**< A delta, base is given by object id. */
82 } git_object_t;
83 
84 /** An open object database handle. */
85 typedef struct git_odb git_odb;
86 
87 /** A custom backend in an ODB */
88 typedef struct git_odb_backend git_odb_backend;
89 
90 /** An object read from the ODB */
91 typedef struct git_odb_object git_odb_object;
92 
93 /** A stream to read/write from the ODB */
94 typedef struct git_odb_stream git_odb_stream;
95 
96 /** A stream to write a packfile to the ODB */
97 typedef struct git_odb_writepack git_odb_writepack;
98 
99 /** a writer for multi-pack-index files. */
100 typedef struct git_midx_writer git_midx_writer;
101 
102 /** An open refs database handle. */
103 typedef struct git_refdb git_refdb;
104 
105 /** A custom backend for refs */
106 typedef struct git_refdb_backend git_refdb_backend;
107 
108 /** A git commit-graph */
109 typedef struct git_commit_graph git_commit_graph;
110 
111 /** a writer for commit-graph files. */
112 typedef struct git_commit_graph_writer git_commit_graph_writer;
113 
114 /**
115  * Representation of an existing git repository,
116  * including all its object contents
117  */
118 typedef struct git_repository git_repository;
119 
120 /** Representation of a working tree */
121 typedef struct git_worktree git_worktree;
122 
123 /** Representation of a generic object in a repository */
124 typedef struct git_object git_object;
125 
126 /** Representation of an in-progress walk through the commits in a repo */
127 typedef struct git_revwalk git_revwalk;
128 
129 /** Parsed representation of a tag object. */
130 typedef struct git_tag git_tag;
131 
132 /** In-memory representation of a blob object. */
133 typedef struct git_blob git_blob;
134 
135 /** Parsed representation of a commit object. */
136 typedef struct git_commit git_commit;
137 
138 /** Representation of each one of the entries in a tree object. */
139 typedef struct git_tree_entry git_tree_entry;
140 
141 /** Representation of a tree object. */
142 typedef struct git_tree git_tree;
143 
144 /** Constructor for in-memory trees */
145 typedef struct git_treebuilder git_treebuilder;
146 
147 /** Memory representation of an index file. */
148 typedef struct git_index git_index;
149 
150 /** An iterator for entries in the index. */
151 typedef struct git_index_iterator git_index_iterator;
152 
153 /** An iterator for conflicts in the index. */
154 typedef struct git_index_conflict_iterator git_index_conflict_iterator;
155 
156 /** Memory representation of a set of config files */
157 typedef struct git_config git_config;
158 
159 /** Interface to access a configuration file */
160 typedef struct git_config_backend git_config_backend;
161 
162 /** Representation of a reference log entry */
163 typedef struct git_reflog_entry git_reflog_entry;
164 
165 /** Representation of a reference log */
166 typedef struct git_reflog git_reflog;
167 
168 /** Representation of a git note */
169 typedef struct git_note git_note;
170 
171 /** Representation of a git packbuilder */
172 typedef struct git_packbuilder git_packbuilder;
173 
174 /** Time in a signature */
175 typedef struct git_time {
176 	git_time_t time; /**< time in seconds from epoch */
177 	int offset; /**< timezone offset, in minutes */
178 	char sign; /**< indicator for questionable '-0000' offsets in signature */
179 } git_time;
180 
181 /** An action signature (e.g. for committers, taggers, etc) */
182 typedef struct git_signature {
183 	char *name; /**< full name of the author */
184 	char *email; /**< email of the author */
185 	git_time when; /**< time when the action happened */
186 } git_signature;
187 
188 /** In-memory representation of a reference. */
189 typedef struct git_reference git_reference;
190 
191 /** Iterator for references */
192 typedef struct git_reference_iterator  git_reference_iterator;
193 
194 /** Transactional interface to references */
195 typedef struct git_transaction git_transaction;
196 
197 /** Annotated commits, the input to merge and rebase. */
198 typedef struct git_annotated_commit git_annotated_commit;
199 
200 /** Representation of a status collection */
201 typedef struct git_status_list git_status_list;
202 
203 /** Representation of a rebase */
204 typedef struct git_rebase git_rebase;
205 
206 /** Basic type of any Git reference. */
207 typedef enum {
208 	GIT_REFERENCE_INVALID  = 0, /**< Invalid reference */
209 	GIT_REFERENCE_DIRECT   = 1, /**< A reference that points at an object id */
210 	GIT_REFERENCE_SYMBOLIC = 2, /**< A reference that points at another reference */
211 	GIT_REFERENCE_ALL      = GIT_REFERENCE_DIRECT | GIT_REFERENCE_SYMBOLIC,
212 } git_reference_t;
213 
214 /** Basic type of any Git branch. */
215 typedef enum {
216 	GIT_BRANCH_LOCAL = 1,
217 	GIT_BRANCH_REMOTE = 2,
218 	GIT_BRANCH_ALL = GIT_BRANCH_LOCAL|GIT_BRANCH_REMOTE,
219 } git_branch_t;
220 
221 /** Valid modes for index and tree entries. */
222 typedef enum {
223 	GIT_FILEMODE_UNREADABLE          = 0000000,
224 	GIT_FILEMODE_TREE                = 0040000,
225 	GIT_FILEMODE_BLOB                = 0100644,
226 	GIT_FILEMODE_BLOB_EXECUTABLE     = 0100755,
227 	GIT_FILEMODE_LINK                = 0120000,
228 	GIT_FILEMODE_COMMIT              = 0160000,
229 } git_filemode_t;
230 
231 /**
232  * A refspec specifies the mapping between remote and local reference
233  * names when fetch or pushing.
234  */
235 typedef struct git_refspec git_refspec;
236 
237 /**
238  * Git's idea of a remote repository. A remote can be anonymous (in
239  * which case it does not have backing configuration entires).
240  */
241 typedef struct git_remote git_remote;
242 
243 /**
244  * Interface which represents a transport to communicate with a
245  * remote.
246  */
247 typedef struct git_transport git_transport;
248 
249 /**
250  * Preparation for a push operation. Can be used to configure what to
251  * push and the level of parallelism of the packfile builder.
252  */
253 typedef struct git_push git_push;
254 
255 /* documentation in the definition */
256 typedef struct git_remote_head git_remote_head;
257 typedef struct git_remote_callbacks git_remote_callbacks;
258 
259 /**
260  * Parent type for `git_cert_hostkey` and `git_cert_x509`.
261  */
262 typedef struct git_cert git_cert;
263 
264 /**
265  * Opaque structure representing a submodule.
266  */
267 typedef struct git_submodule git_submodule;
268 
269 /**
270  * Submodule update values
271  *
272  * These values represent settings for the `submodule.$name.update`
273  * configuration value which says how to handle `git submodule update` for
274  * this submodule.  The value is usually set in the ".gitmodules" file and
275  * copied to ".git/config" when the submodule is initialized.
276  *
277  * You can override this setting on a per-submodule basis with
278  * `git_submodule_set_update()` and write the changed value to disk using
279  * `git_submodule_save()`.  If you have overwritten the value, you can
280  * revert it by passing `GIT_SUBMODULE_UPDATE_RESET` to the set function.
281  *
282  * The values are:
283  *
284  * - GIT_SUBMODULE_UPDATE_CHECKOUT: the default; when a submodule is
285  *   updated, checkout the new detached HEAD to the submodule directory.
286  * - GIT_SUBMODULE_UPDATE_REBASE: update by rebasing the current checked
287  *   out branch onto the commit from the superproject.
288  * - GIT_SUBMODULE_UPDATE_MERGE: update by merging the commit in the
289  *   superproject into the current checkout out branch of the submodule.
290  * - GIT_SUBMODULE_UPDATE_NONE: do not update this submodule even when
291  *   the commit in the superproject is updated.
292  * - GIT_SUBMODULE_UPDATE_DEFAULT: not used except as static initializer
293  *   when we don't want any particular update rule to be specified.
294  */
295 typedef enum {
296 	GIT_SUBMODULE_UPDATE_CHECKOUT = 1,
297 	GIT_SUBMODULE_UPDATE_REBASE   = 2,
298 	GIT_SUBMODULE_UPDATE_MERGE    = 3,
299 	GIT_SUBMODULE_UPDATE_NONE     = 4,
300 
301 	GIT_SUBMODULE_UPDATE_DEFAULT  = 0
302 } git_submodule_update_t;
303 
304 /**
305  * Submodule ignore values
306  *
307  * These values represent settings for the `submodule.$name.ignore`
308  * configuration value which says how deeply to look at the working
309  * directory when getting submodule status.
310  *
311  * You can override this value in memory on a per-submodule basis with
312  * `git_submodule_set_ignore()` and can write the changed value to disk
313  * with `git_submodule_save()`.  If you have overwritten the value, you
314  * can revert to the on disk value by using `GIT_SUBMODULE_IGNORE_RESET`.
315  *
316  * The values are:
317  *
318  * - GIT_SUBMODULE_IGNORE_UNSPECIFIED: use the submodule's configuration
319  * - GIT_SUBMODULE_IGNORE_NONE: don't ignore any change - i.e. even an
320  *   untracked file, will mark the submodule as dirty.  Ignored files are
321  *   still ignored, of course.
322  * - GIT_SUBMODULE_IGNORE_UNTRACKED: ignore untracked files; only changes
323  *   to tracked files, or the index or the HEAD commit will matter.
324  * - GIT_SUBMODULE_IGNORE_DIRTY: ignore changes in the working directory,
325  *   only considering changes if the HEAD of submodule has moved from the
326  *   value in the superproject.
327  * - GIT_SUBMODULE_IGNORE_ALL: never check if the submodule is dirty
328  * - GIT_SUBMODULE_IGNORE_DEFAULT: not used except as static initializer
329  *   when we don't want any particular ignore rule to be specified.
330  */
331 typedef enum {
332 	GIT_SUBMODULE_IGNORE_UNSPECIFIED  = -1, /**< use the submodule's configuration */
333 
334 	GIT_SUBMODULE_IGNORE_NONE      = 1,  /**< any change or untracked == dirty */
335 	GIT_SUBMODULE_IGNORE_UNTRACKED = 2,  /**< dirty if tracked files change */
336 	GIT_SUBMODULE_IGNORE_DIRTY     = 3,  /**< only dirty if HEAD moved */
337 	GIT_SUBMODULE_IGNORE_ALL       = 4,  /**< never dirty */
338 } git_submodule_ignore_t;
339 
340 /**
341  * Options for submodule recurse.
342  *
343  * Represent the value of `submodule.$name.fetchRecurseSubmodules`
344  *
345  * * GIT_SUBMODULE_RECURSE_NO    - do no recurse into submodules
346  * * GIT_SUBMODULE_RECURSE_YES   - recurse into submodules
347  * * GIT_SUBMODULE_RECURSE_ONDEMAND - recurse into submodules only when
348  *                                    commit not already in local clone
349  */
350 typedef enum {
351 	GIT_SUBMODULE_RECURSE_NO = 0,
352 	GIT_SUBMODULE_RECURSE_YES = 1,
353 	GIT_SUBMODULE_RECURSE_ONDEMAND = 2,
354 } git_submodule_recurse_t;
355 
356 typedef struct git_writestream git_writestream;
357 
358 /** A type to write in a streaming fashion, for example, for filters. */
359 struct git_writestream {
360 	int GIT_CALLBACK(write)(git_writestream *stream, const char *buffer, size_t len);
361 	int GIT_CALLBACK(close)(git_writestream *stream);
362 	void GIT_CALLBACK(free)(git_writestream *stream);
363 };
364 
365 /** Representation of .mailmap file state. */
366 typedef struct git_mailmap git_mailmap;
367 
368 /** @} */
369 GIT_END_DECL
370 
371 #endif
372