]> gitweb.ps.run Git - ps-cgit/blob - git.h
gitweb ripoff: set tr:hover to highligt current row
[ps-cgit] / git.h
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 /* On most systems <limits.h> would have given us this, but
37  * not on some systems (e.g. GNU/Hurd).
38  */
39 #ifndef PATH_MAX
40 #define PATH_MAX 4096
41 #endif
42
43 #ifdef __GNUC__
44 #define NORETURN __attribute__((__noreturn__))
45 #else
46 #define NORETURN
47 #ifndef __attribute__
48 #define __attribute__(x)
49 #endif
50 #endif
51
52
53 extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
54
55
56 static inline char* xstrdup(const char *str)
57 {
58         char *ret = strdup(str);
59         if (!ret)
60                 die("Out of memory, strdup failed");
61         return ret;
62 }
63
64 static inline void *xmalloc(size_t size)
65 {
66         void *ret = malloc(size);
67         if (!ret && !size)
68                 ret = malloc(1);
69         if (!ret)
70                 die("Out of memory, malloc failed");
71 #ifdef XMALLOC_POISON
72         memset(ret, 0xA5, size);
73 #endif
74         return ret;
75 }
76
77 static inline void *xrealloc(void *ptr, size_t size)
78 {
79         void *ret = realloc(ptr, size);
80         if (!ret && !size)
81                 ret = realloc(ptr, 1);
82         if (!ret)
83                 die("Out of memory, realloc failed");
84         return ret;
85 }
86
87 static inline void *xcalloc(size_t nmemb, size_t size)
88 {
89         void *ret = calloc(nmemb, size);
90         if (!ret && (!nmemb || !size))
91                 ret = calloc(1, 1);
92         if (!ret)
93                 die("Out of memory, calloc failed");
94         return ret;
95 }
96
97 static inline ssize_t xread(int fd, void *buf, size_t len)
98 {
99         ssize_t nr;
100         while (1) {
101                 nr = read(fd, buf, len);
102                 if ((nr < 0) && (errno == EAGAIN || errno == EINTR))
103                         continue;
104                 return nr;
105         }
106 }
107
108 static inline ssize_t xwrite(int fd, const void *buf, size_t len)
109 {
110         ssize_t nr;
111         while (1) {
112                 nr = write(fd, buf, len);
113                 if ((nr < 0) && (errno == EAGAIN || errno == EINTR))
114                         continue;
115                 return nr;
116         }
117 }
118
119
120
121
122 /*
123  * from git:cache.h
124  */
125
126
127 /* Convert to/from hex/sha1 representation */
128 #define MINIMUM_ABBREV 4
129 #define DEFAULT_ABBREV 7
130
131 extern int sha1_object_info(const unsigned char *, char *, unsigned long *);
132
133 extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size);
134
135 extern int get_sha1(const char *str, unsigned char *sha1);
136 extern int get_sha1_hex(const char *hex, unsigned char *sha1);
137 extern char *sha1_to_hex(const unsigned char *sha1);    /* static buffer result! */
138
139
140
141 /*
142  * from git:object.h 
143  */
144
145 struct object_list {
146         struct object *item;
147         struct object_list *next;
148 };
149
150 struct object_refs {
151         unsigned count;
152         struct object *base;
153         struct object *ref[FLEX_ARRAY]; /* more */
154 };
155
156 struct object_array {
157         unsigned int nr;
158         unsigned int alloc;
159         struct object_array_entry {
160                 struct object *item;
161                 const char *name;
162         } *objects;
163 };
164
165 #define TYPE_BITS   3
166 #define FLAG_BITS  27
167
168 /*
169  * The object type is stored in 3 bits.
170  */
171 struct object {
172         unsigned parsed : 1;
173         unsigned used : 1;
174         unsigned type : TYPE_BITS;
175         unsigned flags : FLAG_BITS;
176         unsigned char sha1[20];
177 };
178
179
180 /*
181  * from git:tree.h
182  */
183
184 struct tree {
185         struct object object;
186         void *buffer;
187         unsigned long size;
188 };
189
190
191 struct tree *lookup_tree(const unsigned char *sha1);
192 int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
193 int parse_tree(struct tree *tree);
194 struct tree *parse_tree_indirect(const unsigned char *sha1);
195
196 typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int);
197
198 extern int read_tree_recursive(struct tree *tree,
199                                const char *base, int baselen,
200                                int stage, const char **match,
201                                read_tree_fn_t fn);
202
203 extern int read_tree(struct tree *tree, int stage, const char **paths);
204
205
206 /* from git:commit.h */
207
208 struct commit_list {
209         struct commit *item;
210         struct commit_list *next;
211 };
212
213 struct commit {
214         struct object object;
215         void *util;
216         unsigned long date;
217         struct commit_list *parents;
218         struct tree *tree;
219         char *buffer;
220 };
221
222
223 struct commit *lookup_commit(const unsigned char *sha1);
224 struct commit *lookup_commit_reference(const unsigned char *sha1);
225 struct commit *lookup_commit_reference_gently(const unsigned char *sha1,
226                                               int quiet);
227
228 int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size);
229 int parse_commit(struct commit *item);
230
231 struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p);
232 struct commit_list * insert_by_date(struct commit *item, struct commit_list **list);
233
234 void free_commit_list(struct commit_list *list);
235
236 void sort_by_date(struct commit_list **list);
237
238 /* Commit formats */
239 enum cmit_fmt {
240         CMIT_FMT_RAW,
241         CMIT_FMT_MEDIUM,
242         CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM,
243         CMIT_FMT_SHORT,
244         CMIT_FMT_FULL,
245         CMIT_FMT_FULLER,
246         CMIT_FMT_ONELINE,
247         CMIT_FMT_EMAIL,
248
249         CMIT_FMT_UNSPECIFIED,
250 };
251
252 extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *, unsigned long len, char *buf, unsigned long space, int abbrev, const char *subject, const char *after_subject, int relative_date);
253
254
255 typedef void (*topo_sort_set_fn_t)(struct commit*, void *data);
256 typedef void* (*topo_sort_get_fn_t)(struct commit*);
257
258
259
260
261 /*
262  *  from git:diff.h
263  */
264
265
266 struct rev_info;
267 struct diff_options;
268 struct diff_queue_struct;
269
270 typedef void (*change_fn_t)(struct diff_options *options,
271                  unsigned old_mode, unsigned new_mode,
272                  const unsigned char *old_sha1,
273                  const unsigned char *new_sha1,
274                  const char *base, const char *path);
275
276 typedef void (*add_remove_fn_t)(struct diff_options *options,
277                     int addremove, unsigned mode,
278                     const unsigned char *sha1,
279                     const char *base, const char *path);
280
281 typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
282                 struct diff_options *options, void *data);
283
284 #define DIFF_FORMAT_RAW         0x0001
285 #define DIFF_FORMAT_DIFFSTAT    0x0002
286 #define DIFF_FORMAT_NUMSTAT     0x0004
287 #define DIFF_FORMAT_SUMMARY     0x0008
288 #define DIFF_FORMAT_PATCH       0x0010
289
290 /* These override all above */
291 #define DIFF_FORMAT_NAME        0x0100
292 #define DIFF_FORMAT_NAME_STATUS 0x0200
293 #define DIFF_FORMAT_CHECKDIFF   0x0400
294
295 /* Same as output_format = 0 but we know that -s flag was given
296  * and we should not give default value to output_format.
297  */
298 #define DIFF_FORMAT_NO_OUTPUT   0x0800
299
300 #define DIFF_FORMAT_CALLBACK    0x1000
301
302 struct diff_options {
303         const char *filter;
304         const char *orderfile;
305         const char *pickaxe;
306         const char *single_follow;
307         unsigned recursive:1,
308                  tree_in_recursive:1,
309                  binary:1,
310                  text:1,
311                  full_index:1,
312                  silent_on_remove:1,
313                  find_copies_harder:1,
314                  color_diff:1,
315                  color_diff_words:1;
316         int context;
317         int break_opt;
318         int detect_rename;
319         int line_termination;
320         int output_format;
321         int pickaxe_opts;
322         int rename_score;
323         int reverse_diff;
324         int rename_limit;
325         int setup;
326         int abbrev;
327         const char *msg_sep;
328         const char *stat_sep;
329         long xdl_opts;
330
331         int stat_width;
332         int stat_name_width;
333
334         int nr_paths;
335         const char **paths;
336         int *pathlens;
337         change_fn_t change;
338         add_remove_fn_t add_remove;
339         diff_format_fn_t format_callback;
340         void *format_callback_data;
341 };
342
343 enum color_diff {
344         DIFF_RESET = 0,
345         DIFF_PLAIN = 1,
346         DIFF_METAINFO = 2,
347         DIFF_FRAGINFO = 3,
348         DIFF_FILE_OLD = 4,
349         DIFF_FILE_NEW = 5,
350         DIFF_COMMIT = 6,
351         DIFF_WHITESPACE = 7,
352 };
353
354
355
356
357 /*
358  * from git:refs.g
359  */
360
361 typedef int each_ref_fn(const char *refname, const unsigned char *sha1, int flags, void *cb_data);
362 extern int head_ref(each_ref_fn, void *);
363 extern int for_each_ref(each_ref_fn, void *);
364 extern int for_each_tag_ref(each_ref_fn, void *);
365 extern int for_each_branch_ref(each_ref_fn, void *);
366 extern int for_each_remote_ref(each_ref_fn, void *);
367
368
369
370 /*
371  * from git:revision.h
372  */
373
374 struct rev_info;
375 struct log_info;
376
377 typedef void (prune_fn_t)(struct rev_info *revs, struct commit *commit);
378
379 struct rev_info {
380         /* Starting list */
381         struct commit_list *commits;
382         struct object_array pending;
383
384         /* Basic information */
385         const char *prefix;
386         void *prune_data;
387         prune_fn_t *prune_fn;
388
389         /* Traversal flags */
390         unsigned int    dense:1,
391                         no_merges:1,
392                         no_walk:1,
393                         remove_empty_trees:1,
394                         simplify_history:1,
395                         lifo:1,
396                         topo_order:1,
397                         tag_objects:1,
398                         tree_objects:1,
399                         blob_objects:1,
400                         edge_hint:1,
401                         limited:1,
402                         unpacked:1, /* see also ignore_packed below */
403                         boundary:1,
404                         parents:1;
405
406         /* Diff flags */
407         unsigned int    diff:1,
408                         full_diff:1,
409                         show_root_diff:1,
410                         no_commit_id:1,
411                         verbose_header:1,
412                         ignore_merges:1,
413                         combine_merges:1,
414                         dense_combined_merges:1,
415                         always_show_header:1;
416
417         /* Format info */
418         unsigned int    shown_one:1,
419                         abbrev_commit:1,
420                         relative_date:1;
421
422         const char **ignore_packed; /* pretend objects in these are unpacked */
423         int num_ignore_packed;
424
425         unsigned int    abbrev;
426         enum cmit_fmt   commit_format;
427         struct log_info *loginfo;
428         int             nr, total;
429         const char      *mime_boundary;
430         const char      *message_id;
431         const char      *ref_message_id;
432         const char      *add_signoff;
433         const char      *extra_headers;
434
435         /* Filter by commit log message */
436         struct grep_opt *grep_filter;
437
438         /* special limits */
439         int max_count;
440         unsigned long max_age;
441         unsigned long min_age;
442
443         /* diff info for patches and for paths limiting */
444         struct diff_options diffopt;
445         struct diff_options pruning;
446
447         topo_sort_set_fn_t topo_setter;
448         topo_sort_get_fn_t topo_getter;
449 };
450
451
452 extern void init_revisions(struct rev_info *revs, const char *prefix);
453 extern int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def);
454 extern int handle_revision_arg(const char *arg, struct rev_info *revs,int flags,int cant_be_filename);
455
456 extern void prepare_revision_walk(struct rev_info *revs);
457 extern struct commit *get_revision(struct rev_info *revs);
458
459
460
461
462 #endif /* GIT_H */