diff options
Diffstat (limited to 'git.h')
-rw-r--r-- | git.h | 399 |
1 files changed, 399 insertions, 0 deletions
diff --git a/git.h b/git.h new file mode 100644 index 0000000..443f216 --- /dev/null +++ b/git.h | |||
@@ -0,0 +1,399 @@ | |||
1 | #ifndef GIT_H | ||
2 | #define GIT_H | ||
3 | |||
4 | |||
5 | /* | ||
6 | * from git:git-compat-util.h | ||
7 | */ | ||
8 | |||
9 | |||
10 | #ifndef FLEX_ARRAY | ||
11 | #if defined(__GNUC__) && (__GNUC__ < 3) | ||
12 | #define FLEX_ARRAY 0 | ||
13 | #else | ||
14 | #define FLEX_ARRAY /* empty */ | ||
15 | #endif | ||
16 | #endif | ||
17 | |||
18 | |||
19 | #include <unistd.h> | ||
20 | #include <stdio.h> | ||
21 | #include <sys/stat.h> | ||
22 | #include <fcntl.h> | ||
23 | #include <stddef.h> | ||
24 | #include <stdlib.h> | ||
25 | #include <stdarg.h> | ||
26 | #include <string.h> | ||
27 | #include <errno.h> | ||
28 | #include <limits.h> | ||
29 | #include <sys/param.h> | ||
30 | #include <netinet/in.h> | ||
31 | #include <sys/types.h> | ||
32 | #include <dirent.h> | ||
33 | #include <time.h> | ||
34 | |||
35 | |||
36 | static inline char* xstrdup(const char *str) | ||
37 | { | ||
38 | char *ret = strdup(str); | ||
39 | if (!ret) | ||
40 | die("Out of memory, strdup failed"); | ||
41 | return ret; | ||
42 | } | ||
43 | |||
44 | static inline void *xmalloc(size_t size) | ||
45 | { | ||
46 | void *ret = malloc(size); | ||
47 | if (!ret && !size) | ||
48 | ret = malloc(1); | ||
49 | if (!ret) | ||
50 | die("Out of memory, malloc failed"); | ||
51 | #ifdef XMALLOC_POISON | ||
52 | memset(ret, 0xA5, size); | ||
53 | #endif | ||
54 | return ret; | ||
55 | } | ||
56 | |||
57 | static inline void *xrealloc(void *ptr, size_t size) | ||
58 | { | ||
59 | void *ret = realloc(ptr, size); | ||
60 | if (!ret && !size) | ||
61 | ret = realloc(ptr, 1); | ||
62 | if (!ret) | ||
63 | die("Out of memory, realloc failed"); | ||
64 | return ret; | ||
65 | } | ||
66 | |||
67 | static inline void *xcalloc(size_t nmemb, size_t size) | ||
68 | { | ||
69 | void *ret = calloc(nmemb, size); | ||
70 | if (!ret && (!nmemb || !size)) | ||
71 | ret = calloc(1, 1); | ||
72 | if (!ret) | ||
73 | die("Out of memory, calloc failed"); | ||
74 | return ret; | ||
75 | } | ||
76 | |||
77 | static inline ssize_t xread(int fd, void *buf, size_t len) | ||
78 | { | ||
79 | ssize_t nr; | ||
80 | while (1) { | ||
81 | nr = read(fd, buf, len); | ||
82 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | ||
83 | continue; | ||
84 | return nr; | ||
85 | } | ||
86 | } | ||
87 | |||
88 | static inline ssize_t xwrite(int fd, const void *buf, size_t len) | ||
89 | { | ||
90 | ssize_t nr; | ||
91 | while (1) { | ||
92 | nr = write(fd, buf, len); | ||
93 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | ||
94 | continue; | ||
95 | return nr; | ||
96 | } | ||
97 | } | ||
98 | |||
99 | |||
100 | |||
101 | |||
102 | /* | ||
103 | * from git:cache.h | ||
104 | */ | ||
105 | |||
106 | |||
107 | /* Convert to/from hex/sha1 representation */ | ||
108 | #define MINIMUM_ABBREV 4 | ||
109 | #define DEFAULT_ABBREV 7 | ||
110 | |||
111 | |||
112 | extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size); | ||
113 | |||
114 | |||
115 | |||
116 | |||
117 | /* | ||
118 | * from git:object.h | ||
119 | */ | ||
120 | |||
121 | struct object_list { | ||
122 | struct object *item; | ||
123 | struct object_list *next; | ||
124 | }; | ||
125 | |||
126 | struct object_refs { | ||
127 | unsigned count; | ||
128 | struct object *base; | ||
129 | struct object *ref[FLEX_ARRAY]; /* more */ | ||
130 | }; | ||
131 | |||
132 | struct object_array { | ||
133 | unsigned int nr; | ||
134 | unsigned int alloc; | ||
135 | struct object_array_entry { | ||
136 | struct object *item; | ||
137 | const char *name; | ||
138 | } *objects; | ||
139 | }; | ||
140 | |||
141 | #define TYPE_BITS 3 | ||
142 | #define FLAG_BITS 27 | ||
143 | |||
144 | /* | ||
145 | * The object type is stored in 3 bits. | ||
146 | */ | ||
147 | struct object { | ||
148 | unsigned parsed : 1; | ||
149 | unsigned used : 1; | ||
150 | unsigned type : TYPE_BITS; | ||
151 | unsigned flags : FLAG_BITS; | ||
152 | unsigned char sha1[20]; | ||
153 | }; | ||
154 | |||
155 | |||
156 | /* | ||
157 | * from git:tree.h | ||
158 | */ | ||
159 | |||
160 | struct tree { | ||
161 | struct object object; | ||
162 | void *buffer; | ||
163 | unsigned long size; | ||
164 | }; | ||
165 | |||
166 | |||
167 | |||
168 | |||
169 | /* from git:commit.h */ | ||
170 | |||
171 | struct commit_list { | ||
172 | struct commit *item; | ||
173 | struct commit_list *next; | ||
174 | }; | ||
175 | |||
176 | struct commit { | ||
177 | struct object object; | ||
178 | void *util; | ||
179 | unsigned long date; | ||
180 | struct commit_list *parents; | ||
181 | struct tree *tree; | ||
182 | char *buffer; | ||
183 | }; | ||
184 | |||
185 | |||
186 | /* Commit formats */ | ||
187 | enum cmit_fmt { | ||
188 | CMIT_FMT_RAW, | ||
189 | CMIT_FMT_MEDIUM, | ||
190 | CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM, | ||
191 | CMIT_FMT_SHORT, | ||
192 | CMIT_FMT_FULL, | ||
193 | CMIT_FMT_FULLER, | ||
194 | CMIT_FMT_ONELINE, | ||
195 | CMIT_FMT_EMAIL, | ||
196 | |||
197 | CMIT_FMT_UNSPECIFIED, | ||
198 | }; | ||
199 | |||
200 | |||
201 | |||
202 | struct commit *lookup_commit(const unsigned char *sha1); | ||
203 | struct commit *lookup_commit_reference(const unsigned char *sha1); | ||
204 | struct commit *lookup_commit_reference_gently(const unsigned char *sha1, | ||
205 | int quiet); | ||
206 | |||
207 | typedef void (*topo_sort_set_fn_t)(struct commit*, void *data); | ||
208 | typedef void* (*topo_sort_get_fn_t)(struct commit*); | ||
209 | |||
210 | |||
211 | |||
212 | |||
213 | /* | ||
214 | * from git:diff.h | ||
215 | */ | ||
216 | |||
217 | |||
218 | struct rev_info; | ||
219 | struct diff_options; | ||
220 | struct diff_queue_struct; | ||
221 | |||
222 | typedef void (*change_fn_t)(struct diff_options *options, | ||
223 | unsigned old_mode, unsigned new_mode, | ||
224 | const unsigned char *old_sha1, | ||
225 | const unsigned char *new_sha1, | ||
226 | const char *base, const char *path); | ||
227 | |||
228 | typedef void (*add_remove_fn_t)(struct diff_options *options, | ||
229 | int addremove, unsigned mode, | ||
230 | const unsigned char *sha1, | ||
231 | const char *base, const char *path); | ||
232 | |||
233 | typedef void (*diff_format_fn_t)(struct diff_queue_struct *q, | ||
234 | struct diff_options *options, void *data); | ||
235 | |||
236 | #define DIFF_FORMAT_RAW 0x0001 | ||
237 | #define DIFF_FORMAT_DIFFSTAT 0x0002 | ||
238 | #define DIFF_FORMAT_NUMSTAT 0x0004 | ||
239 | #define DIFF_FORMAT_SUMMARY 0x0008 | ||
240 | #define DIFF_FORMAT_PATCH 0x0010 | ||
241 | |||
242 | /* These override all above */ | ||
243 | #define DIFF_FORMAT_NAME 0x0100 | ||
244 | #define DIFF_FORMAT_NAME_STATUS 0x0200 | ||
245 | #define DIFF_FORMAT_CHECKDIFF 0x0400 | ||
246 | |||
247 | /* Same as output_format = 0 but we know that -s flag was given | ||
248 | * and we should not give default value to output_format. | ||
249 | */ | ||
250 | #define DIFF_FORMAT_NO_OUTPUT 0x0800 | ||
251 | |||
252 | #define DIFF_FORMAT_CALLBACK 0x1000 | ||
253 | |||
254 | struct diff_options { | ||
255 | const char *filter; | ||
256 | const char *orderfile; | ||
257 | const char *pickaxe; | ||
258 | const char *single_follow; | ||
259 | unsigned recursive:1, | ||
260 | tree_in_recursive:1, | ||
261 | binary:1, | ||
262 | text:1, | ||
263 | full_index:1, | ||
264 | silent_on_remove:1, | ||
265 | find_copies_harder:1, | ||
266 | color_diff:1, | ||
267 | color_diff_words:1; | ||
268 | int context; | ||
269 | int break_opt; | ||
270 | int detect_rename; | ||
271 | int line_termination; | ||
272 | int output_format; | ||
273 | int pickaxe_opts; | ||
274 | int rename_score; | ||
275 | int reverse_diff; | ||
276 | int rename_limit; | ||
277 | int setup; | ||
278 | int abbrev; | ||
279 | const char *msg_sep; | ||
280 | const char *stat_sep; | ||
281 | long xdl_opts; | ||
282 | |||
283 | int stat_width; | ||
284 | int stat_name_width; | ||
285 | |||
286 | int nr_paths; | ||
287 | const char **paths; | ||
288 | int *pathlens; | ||
289 | change_fn_t change; | ||
290 | add_remove_fn_t add_remove; | ||
291 | diff_format_fn_t format_callback; | ||
292 | void *format_callback_data; | ||
293 | }; | ||
294 | |||
295 | enum color_diff { | ||
296 | DIFF_RESET = 0, | ||
297 | DIFF_PLAIN = 1, | ||
298 | DIFF_METAINFO = 2, | ||
299 | DIFF_FRAGINFO = 3, | ||
300 | DIFF_FILE_OLD = 4, | ||
301 | DIFF_FILE_NEW = 5, | ||
302 | DIFF_COMMIT = 6, | ||
303 | DIFF_WHITESPACE = 7, | ||
304 | }; | ||
305 | |||
306 | |||
307 | |||
308 | |||
309 | |||
310 | |||
311 | |||
312 | /* | ||
313 | * from git:revision.h | ||
314 | */ | ||
315 | |||
316 | struct rev_info; | ||
317 | struct log_info; | ||
318 | |||
319 | typedef void (prune_fn_t)(struct rev_info *revs, struct commit *commit); | ||
320 | |||
321 | struct rev_info { | ||
322 | /* Starting list */ | ||
323 | struct commit_list *commits; | ||
324 | struct object_array pending; | ||
325 | |||
326 | /* Basic information */ | ||
327 | const char *prefix; | ||
328 | void *prune_data; | ||
329 | prune_fn_t *prune_fn; | ||
330 | |||
331 | /* Traversal flags */ | ||
332 | unsigned int dense:1, | ||
333 | no_merges:1, | ||
334 | no_walk:1, | ||
335 | remove_empty_trees:1, | ||
336 | simplify_history:1, | ||
337 | lifo:1, | ||
338 | topo_order:1, | ||
339 | tag_objects:1, | ||
340 | tree_objects:1, | ||
341 | blob_objects:1, | ||
342 | edge_hint:1, | ||
343 | limited:1, | ||
344 | unpacked:1, /* see also ignore_packed below */ | ||
345 | boundary:1, | ||
346 | parents:1; | ||
347 | |||
348 | /* Diff flags */ | ||
349 | unsigned int diff:1, | ||
350 | full_diff:1, | ||
351 | show_root_diff:1, | ||
352 | no_commit_id:1, | ||
353 | verbose_header:1, | ||
354 | ignore_merges:1, | ||
355 | combine_merges:1, | ||
356 | dense_combined_merges:1, | ||
357 | always_show_header:1; | ||
358 | |||
359 | /* Format info */ | ||
360 | unsigned int shown_one:1, | ||
361 | abbrev_commit:1, | ||
362 | relative_date:1; | ||
363 | |||
364 | const char **ignore_packed; /* pretend objects in these are unpacked */ | ||
365 | int num_ignore_packed; | ||
366 | |||
367 | unsigned int abbrev; | ||
368 | enum cmit_fmt commit_format; | ||
369 | struct log_info *loginfo; | ||
370 | int nr, total; | ||
371 | const char *mime_boundary; | ||
372 | const char *message_id; | ||
373 | const char *ref_message_id; | ||
374 | const char *add_signoff; | ||
375 | const char *extra_headers; | ||
376 | |||
377 | /* Filter by commit log message */ | ||
378 | struct grep_opt *grep_filter; | ||
379 | |||
380 | /* special limits */ | ||
381 | int max_count; | ||
382 | unsigned long max_age; | ||
383 | unsigned long min_age; | ||
384 | |||
385 | /* diff info for patches and for paths limiting */ | ||
386 | struct diff_options diffopt; | ||
387 | struct diff_options pruning; | ||
388 | |||
389 | topo_sort_set_fn_t topo_setter; | ||
390 | topo_sort_get_fn_t topo_getter; | ||
391 | }; | ||
392 | |||
393 | |||
394 | extern struct commit *get_revision(struct rev_info *revs); | ||
395 | |||
396 | |||
397 | |||
398 | |||
399 | #endif /* GIT_H */ | ||