6 * from git:git-compat-util.h
11 #if defined(__GNUC__) && (__GNUC__ < 3)
14 #define FLEX_ARRAY /* empty */
29 #include <sys/param.h>
30 #include <netinet/in.h>
31 #include <sys/types.h>
36 /* On most systems <limits.h> would have given us this, but
37 * not on some systems (e.g. GNU/Hurd).
44 #define NORETURN __attribute__((__noreturn__))
48 #define __attribute__(x)
53 extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
56 static inline char* xstrdup(const char *str)
58 char *ret = strdup(str);
60 die("Out of memory, strdup failed");
64 static inline void *xmalloc(size_t size)
66 void *ret = malloc(size);
70 die("Out of memory, malloc failed");
72 memset(ret, 0xA5, size);
77 static inline void *xrealloc(void *ptr, size_t size)
79 void *ret = realloc(ptr, size);
81 ret = realloc(ptr, 1);
83 die("Out of memory, realloc failed");
87 static inline void *xcalloc(size_t nmemb, size_t size)
89 void *ret = calloc(nmemb, size);
90 if (!ret && (!nmemb || !size))
93 die("Out of memory, calloc failed");
97 static inline ssize_t xread(int fd, void *buf, size_t len)
101 nr = read(fd, buf, len);
102 if ((nr < 0) && (errno == EAGAIN || errno == EINTR))
108 static inline ssize_t xwrite(int fd, const void *buf, size_t len)
112 nr = write(fd, buf, len);
113 if ((nr < 0) && (errno == EAGAIN || errno == EINTR))
127 /* Convert to/from hex/sha1 representation */
128 #define MINIMUM_ABBREV 4
129 #define DEFAULT_ABBREV 7
131 extern int sha1_object_info(const unsigned char *, char *, unsigned long *);
133 extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size);
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! */
147 struct object_list *next;
153 struct object *ref[FLEX_ARRAY]; /* more */
156 struct object_array {
159 struct object_array_entry {
169 * The object type is stored in 3 bits.
174 unsigned type : TYPE_BITS;
175 unsigned flags : FLAG_BITS;
176 unsigned char sha1[20];
185 struct object object;
193 /* from git:commit.h */
197 struct commit_list *next;
201 struct object object;
204 struct commit_list *parents;
210 struct commit *lookup_commit(const unsigned char *sha1);
211 struct commit *lookup_commit_reference(const unsigned char *sha1);
212 struct commit *lookup_commit_reference_gently(const unsigned char *sha1,
215 int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size);
216 int parse_commit(struct commit *item);
218 struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p);
219 struct commit_list * insert_by_date(struct commit *item, struct commit_list **list);
221 void free_commit_list(struct commit_list *list);
223 void sort_by_date(struct commit_list **list);
229 CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM,
236 CMIT_FMT_UNSPECIFIED,
239 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);
242 typedef void (*topo_sort_set_fn_t)(struct commit*, void *data);
243 typedef void* (*topo_sort_get_fn_t)(struct commit*);
255 struct diff_queue_struct;
257 typedef void (*change_fn_t)(struct diff_options *options,
258 unsigned old_mode, unsigned new_mode,
259 const unsigned char *old_sha1,
260 const unsigned char *new_sha1,
261 const char *base, const char *path);
263 typedef void (*add_remove_fn_t)(struct diff_options *options,
264 int addremove, unsigned mode,
265 const unsigned char *sha1,
266 const char *base, const char *path);
268 typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
269 struct diff_options *options, void *data);
271 #define DIFF_FORMAT_RAW 0x0001
272 #define DIFF_FORMAT_DIFFSTAT 0x0002
273 #define DIFF_FORMAT_NUMSTAT 0x0004
274 #define DIFF_FORMAT_SUMMARY 0x0008
275 #define DIFF_FORMAT_PATCH 0x0010
277 /* These override all above */
278 #define DIFF_FORMAT_NAME 0x0100
279 #define DIFF_FORMAT_NAME_STATUS 0x0200
280 #define DIFF_FORMAT_CHECKDIFF 0x0400
282 /* Same as output_format = 0 but we know that -s flag was given
283 * and we should not give default value to output_format.
285 #define DIFF_FORMAT_NO_OUTPUT 0x0800
287 #define DIFF_FORMAT_CALLBACK 0x1000
289 struct diff_options {
291 const char *orderfile;
293 const char *single_follow;
294 unsigned recursive:1,
300 find_copies_harder:1,
306 int line_termination;
315 const char *stat_sep;
325 add_remove_fn_t add_remove;
326 diff_format_fn_t format_callback;
327 void *format_callback_data;
348 typedef int each_ref_fn(const char *refname, const unsigned char *sha1, int flags, void *cb_data);
349 extern int head_ref(each_ref_fn, void *);
350 extern int for_each_ref(each_ref_fn, void *);
351 extern int for_each_tag_ref(each_ref_fn, void *);
352 extern int for_each_branch_ref(each_ref_fn, void *);
353 extern int for_each_remote_ref(each_ref_fn, void *);
358 * from git:revision.h
364 typedef void (prune_fn_t)(struct rev_info *revs, struct commit *commit);
368 struct commit_list *commits;
369 struct object_array pending;
371 /* Basic information */
374 prune_fn_t *prune_fn;
376 /* Traversal flags */
377 unsigned int dense:1,
380 remove_empty_trees:1,
389 unpacked:1, /* see also ignore_packed below */
401 dense_combined_merges:1,
402 always_show_header:1;
405 unsigned int shown_one:1,
409 const char **ignore_packed; /* pretend objects in these are unpacked */
410 int num_ignore_packed;
413 enum cmit_fmt commit_format;
414 struct log_info *loginfo;
416 const char *mime_boundary;
417 const char *message_id;
418 const char *ref_message_id;
419 const char *add_signoff;
420 const char *extra_headers;
422 /* Filter by commit log message */
423 struct grep_opt *grep_filter;
427 unsigned long max_age;
428 unsigned long min_age;
430 /* diff info for patches and for paths limiting */
431 struct diff_options diffopt;
432 struct diff_options pruning;
434 topo_sort_set_fn_t topo_setter;
435 topo_sort_get_fn_t topo_getter;
439 extern void init_revisions(struct rev_info *revs, const char *prefix);
440 extern int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def);
441 extern int handle_revision_arg(const char *arg, struct rev_info *revs,int flags,int cant_be_filename);
443 extern void prepare_revision_walk(struct rev_info *revs);
444 extern struct commit *get_revision(struct rev_info *revs);