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