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
))
133 /* 5 for future expansion */
140 /* Convert to/from hex/sha1 representation */
141 #define MINIMUM_ABBREV 4
142 #define DEFAULT_ABBREV 7
144 extern const unsigned char null_sha1
[20];
146 extern int sha1_object_info(const unsigned char *, char *, unsigned long *);
148 extern void * read_sha1_file(const unsigned char *sha1
, char *type
, unsigned long *size
);
150 extern int get_sha1(const char *str
, unsigned char *sha1
);
151 extern int get_sha1_hex(const char *hex
, unsigned char *sha1
);
152 extern char *sha1_to_hex(const unsigned char *sha1
); /* static buffer result! */
154 static inline int is_null_sha1(const unsigned char *sha1
)
156 return !memcmp(sha1
, null_sha1
, 20);
158 static inline int hashcmp(const unsigned char *sha1
, const unsigned char *sha2
)
160 return memcmp(sha1
, sha2
, 20);
162 static inline void hashcpy(unsigned char *sha_dst
, const unsigned char *sha_src
)
164 memcpy(sha_dst
, sha_src
, 20);
166 static inline void hashclr(unsigned char *hash
)
176 enum grep_pat_token
{
193 struct grep_pat
*next
;
196 enum grep_pat_token token
;
201 enum grep_expr_node
{
209 struct grep_pat
*pattern_list
;
210 struct grep_pat
**pattern_tail
;
211 struct grep_expr
*pattern_expression
;
216 unsigned status_only
:1;
217 unsigned name_only
:1;
218 unsigned unmatch_name_only
:1;
220 unsigned word_regexp
:1;
222 unsigned all_match
:1;
223 #define GREP_BINARY_DEFAULT 0
224 #define GREP_BINARY_NOMATCH 1
225 #define GREP_BINARY_TEXT 2
231 unsigned pre_context
;
232 unsigned post_context
;
236 extern void compile_grep_patterns(struct grep_opt
*opt
);
237 extern void free_grep_patterns(struct grep_opt
*opt
);
244 extern const char *type_names
[9];
248 struct object_list
*next
;
254 struct object
*ref
[FLEX_ARRAY
]; /* more */
257 struct object_array
{
260 struct object_array_entry
{
270 * The object type is stored in 3 bits.
275 unsigned type
: TYPE_BITS
;
276 unsigned flags
: FLAG_BITS
;
277 unsigned char sha1
[20];
286 struct object object
;
292 struct tree
*lookup_tree(const unsigned char *sha1
);
293 int parse_tree_buffer(struct tree
*item
, void *buffer
, unsigned long size
);
294 int parse_tree(struct tree
*tree
);
295 struct tree
*parse_tree_indirect(const unsigned char *sha1
);
297 typedef int (*read_tree_fn_t
)(const unsigned char *, const char *, int, const char *, unsigned int, int);
299 extern int read_tree_recursive(struct tree
*tree
,
300 const char *base
, int baselen
,
301 int stage
, const char **match
,
304 extern int read_tree(struct tree
*tree
, int stage
, const char **paths
);
307 /* from git:commit.h */
311 struct commit_list
*next
;
315 struct object object
;
318 struct commit_list
*parents
;
324 struct commit
*lookup_commit(const unsigned char *sha1
);
325 struct commit
*lookup_commit_reference(const unsigned char *sha1
);
326 struct commit
*lookup_commit_reference_gently(const unsigned char *sha1
,
329 int parse_commit_buffer(struct commit
*item
, void *buffer
, unsigned long size
);
330 int parse_commit(struct commit
*item
);
332 struct commit_list
* commit_list_insert(struct commit
*item
, struct commit_list
**list_p
);
333 struct commit_list
* insert_by_date(struct commit
*item
, struct commit_list
**list
);
335 void free_commit_list(struct commit_list
*list
);
337 void sort_by_date(struct commit_list
**list
);
343 CMIT_FMT_DEFAULT
= CMIT_FMT_MEDIUM
,
350 CMIT_FMT_UNSPECIFIED
,
353 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
);
356 typedef void (*topo_sort_set_fn_t
)(struct commit
*, void *data
);
357 typedef void* (*topo_sort_get_fn_t
)(struct commit
*);
365 extern const char *tag_type
;
368 struct object object
;
369 struct object
*tagged
;
371 char *signature
; /* not actually implemented */
374 extern struct tag
*lookup_tag(const unsigned char *sha1
);
375 extern int parse_tag_buffer(struct tag
*item
, void *data
, unsigned long size
);
376 extern int parse_tag(struct tag
*item
);
377 extern struct object
*deref_tag(struct object
*, const char *, int);
381 * from git:diffcore.h
384 struct diff_filespec
{
385 unsigned char sha1
[20];
390 int xfrm_flags
; /* for use by the xfrm */
391 unsigned short mode
; /* file mode */
392 unsigned sha1_valid
: 1; /* if true, use sha1 and trust mode;
393 * if false, use the name and read from
396 #define DIFF_FILE_VALID(spec) (((spec)->mode) != 0)
397 unsigned should_free
: 1; /* data should be free()'ed */
398 unsigned should_munmap
: 1; /* data should be munmap()'ed */
401 struct diff_filepair
{
402 struct diff_filespec
*one
;
403 struct diff_filespec
*two
;
404 unsigned short int score
;
405 char status
; /* M C R N D U (see Documentation/diff-format.txt) */
406 unsigned source_stays
: 1; /* all of R/C are copies */
407 unsigned broken_pair
: 1;
408 unsigned renamed_pair
: 1;
411 #define DIFF_PAIR_UNMERGED(p) \
412 (!DIFF_FILE_VALID((p)->one) && !DIFF_FILE_VALID((p)->two))
414 #define DIFF_PAIR_RENAME(p) ((p)->renamed_pair)
416 #define DIFF_PAIR_BROKEN(p) \
417 ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \
418 ((p)->broken_pair != 0) )
420 #define DIFF_PAIR_TYPE_CHANGED(p) \
421 ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode))
423 #define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode)
425 extern void diff_free_filepair(struct diff_filepair
*);
427 extern int diff_unmodified_pair(struct diff_filepair
*);
429 struct diff_queue_struct
{
430 struct diff_filepair
**queue
;
443 struct diff_queue_struct
;
445 typedef void (*change_fn_t
)(struct diff_options
*options
,
446 unsigned old_mode
, unsigned new_mode
,
447 const unsigned char *old_sha1
,
448 const unsigned char *new_sha1
,
449 const char *base
, const char *path
);
451 typedef void (*add_remove_fn_t
)(struct diff_options
*options
,
452 int addremove
, unsigned mode
,
453 const unsigned char *sha1
,
454 const char *base
, const char *path
);
456 typedef void (*diff_format_fn_t
)(struct diff_queue_struct
*q
,
457 struct diff_options
*options
, void *data
);
459 #define DIFF_FORMAT_RAW 0x0001
460 #define DIFF_FORMAT_DIFFSTAT 0x0002
461 #define DIFF_FORMAT_NUMSTAT 0x0004
462 #define DIFF_FORMAT_SUMMARY 0x0008
463 #define DIFF_FORMAT_PATCH 0x0010
465 /* These override all above */
466 #define DIFF_FORMAT_NAME 0x0100
467 #define DIFF_FORMAT_NAME_STATUS 0x0200
468 #define DIFF_FORMAT_CHECKDIFF 0x0400
470 /* Same as output_format = 0 but we know that -s flag was given
471 * and we should not give default value to output_format.
473 #define DIFF_FORMAT_NO_OUTPUT 0x0800
475 #define DIFF_FORMAT_CALLBACK 0x1000
477 struct diff_options
{
479 const char *orderfile
;
481 const char *single_follow
;
482 unsigned recursive
:1,
488 find_copies_harder
:1,
494 int line_termination
;
503 const char *stat_sep
;
513 add_remove_fn_t add_remove
;
514 diff_format_fn_t format_callback
;
515 void *format_callback_data
;
530 extern int diff_tree_sha1(const unsigned char *old
, const unsigned char *new,
531 const char *base
, struct diff_options
*opt
);
533 extern int diff_root_tree_sha1(const unsigned char *new, const char *base
,
534 struct diff_options
*opt
);
536 extern int git_diff_ui_config(const char *var
, const char *value
);
537 extern void diff_setup(struct diff_options
*);
538 extern int diff_opt_parse(struct diff_options
*, const char **, int);
539 extern int diff_setup_done(struct diff_options
*);
542 extern void diffcore_std(struct diff_options
*);
543 extern void diff_flush(struct diff_options
*);
546 /* diff-raw status letters */
547 #define DIFF_STATUS_ADDED 'A'
548 #define DIFF_STATUS_COPIED 'C'
549 #define DIFF_STATUS_DELETED 'D'
550 #define DIFF_STATUS_MODIFIED 'M'
551 #define DIFF_STATUS_RENAMED 'R'
552 #define DIFF_STATUS_TYPE_CHANGED 'T'
553 #define DIFF_STATUS_UNKNOWN 'X'
554 #define DIFF_STATUS_UNMERGED 'U'
562 typedef int each_ref_fn(const char *refname
, const unsigned char *sha1
, int flags
, void *cb_data
);
563 extern int head_ref(each_ref_fn
, void *);
564 extern int for_each_ref(each_ref_fn
, void *);
565 extern int for_each_tag_ref(each_ref_fn
, void *);
566 extern int for_each_branch_ref(each_ref_fn
, void *);
567 extern int for_each_remote_ref(each_ref_fn
, void *);
572 * from git:revision.h
578 typedef void (prune_fn_t
)(struct rev_info
*revs
, struct commit
*commit
);
582 struct commit_list
*commits
;
583 struct object_array pending
;
585 /* Basic information */
588 prune_fn_t
*prune_fn
;
590 /* Traversal flags */
591 unsigned int dense
:1,
594 remove_empty_trees
:1,
603 unpacked
:1, /* see also ignore_packed below */
615 dense_combined_merges
:1,
616 always_show_header
:1;
619 unsigned int shown_one
:1,
623 const char **ignore_packed
; /* pretend objects in these are unpacked */
624 int num_ignore_packed
;
627 enum cmit_fmt commit_format
;
628 struct log_info
*loginfo
;
630 const char *mime_boundary
;
631 const char *message_id
;
632 const char *ref_message_id
;
633 const char *add_signoff
;
634 const char *extra_headers
;
636 /* Filter by commit log message */
637 struct grep_opt
*grep_filter
;
641 unsigned long max_age
;
642 unsigned long min_age
;
644 /* diff info for patches and for paths limiting */
645 struct diff_options diffopt
;
646 struct diff_options pruning
;
648 topo_sort_set_fn_t topo_setter
;
649 topo_sort_get_fn_t topo_getter
;
653 extern void init_revisions(struct rev_info
*revs
, const char *prefix
);
654 extern int setup_revisions(int argc
, const char **argv
, struct rev_info
*revs
, const char *def
);
655 extern int handle_revision_arg(const char *arg
, struct rev_info
*revs
,int flags
,int cant_be_filename
);
657 extern void prepare_revision_walk(struct rev_info
*revs
);
658 extern struct commit
*get_revision(struct rev_info
*revs
);
662 /* from git:log-tree.h */
664 int log_tree_commit(struct rev_info
*, struct commit
*);