summaryrefslogtreecommitdiffabout
path: root/git.h
Side-by-side diff
Diffstat (limited to 'git.h') (more/less context) (ignore whitespace changes)
-rw-r--r--git.h60
1 files changed, 55 insertions, 5 deletions
diff --git a/git.h b/git.h
index 443f216..dfa3542 100644
--- a/git.h
+++ b/git.h
@@ -12,48 +12,68 @@
#define FLEX_ARRAY 0
#else
#define FLEX_ARRAY /* empty */
#endif
#endif
#include <unistd.h>
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <dirent.h>
#include <time.h>
+/* On most systems <limits.h> would have given us this, but
+ * not on some systems (e.g. GNU/Hurd).
+ */
+#ifndef PATH_MAX
+#define PATH_MAX 4096
+#endif
+
+#ifdef __GNUC__
+#define NORETURN __attribute__((__noreturn__))
+#else
+#define NORETURN
+#ifndef __attribute__
+#define __attribute__(x)
+#endif
+#endif
+
+
+extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
+
+
static inline char* xstrdup(const char *str)
{
char *ret = strdup(str);
if (!ret)
die("Out of memory, strdup failed");
return ret;
}
static inline void *xmalloc(size_t size)
{
void *ret = malloc(size);
if (!ret && !size)
ret = malloc(1);
if (!ret)
die("Out of memory, malloc failed");
#ifdef XMALLOC_POISON
memset(ret, 0xA5, size);
#endif
return ret;
}
static inline void *xrealloc(void *ptr, size_t size)
{
void *ret = realloc(ptr, size);
@@ -87,51 +107,55 @@ static inline ssize_t xread(int fd, void *buf, size_t len)
static inline ssize_t xwrite(int fd, const void *buf, size_t len)
{
ssize_t nr;
while (1) {
nr = write(fd, buf, len);
if ((nr < 0) && (errno == EAGAIN || errno == EINTR))
continue;
return nr;
}
}
/*
* from git:cache.h
*/
/* Convert to/from hex/sha1 representation */
#define MINIMUM_ABBREV 4
#define DEFAULT_ABBREV 7
+extern int sha1_object_info(const unsigned char *, char *, unsigned long *);
extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size);
+extern int get_sha1(const char *str, unsigned char *sha1);
+extern int get_sha1_hex(const char *hex, unsigned char *sha1);
+extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
/*
* from git:object.h
*/
struct object_list {
struct object *item;
struct object_list *next;
};
struct object_refs {
unsigned count;
struct object *base;
struct object *ref[FLEX_ARRAY]; /* more */
};
struct object_array {
unsigned int nr;
unsigned int alloc;
struct object_array_entry {
struct object *item;
const char *name;
@@ -162,69 +186,80 @@ struct tree {
void *buffer;
unsigned long size;
};
/* from git:commit.h */
struct commit_list {
struct commit *item;
struct commit_list *next;
};
struct commit {
struct object object;
void *util;
unsigned long date;
struct commit_list *parents;
struct tree *tree;
char *buffer;
};
+struct commit *lookup_commit(const unsigned char *sha1);
+struct commit *lookup_commit_reference(const unsigned char *sha1);
+struct commit *lookup_commit_reference_gently(const unsigned char *sha1,
+ int quiet);
+
+int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size);
+int parse_commit(struct commit *item);
+
+struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p);
+struct commit_list * insert_by_date(struct commit *item, struct commit_list **list);
+
+void free_commit_list(struct commit_list *list);
+
+void sort_by_date(struct commit_list **list);
+
/* Commit formats */
enum cmit_fmt {
CMIT_FMT_RAW,
CMIT_FMT_MEDIUM,
CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM,
CMIT_FMT_SHORT,
CMIT_FMT_FULL,
CMIT_FMT_FULLER,
CMIT_FMT_ONELINE,
CMIT_FMT_EMAIL,
CMIT_FMT_UNSPECIFIED,
};
+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);
-struct commit *lookup_commit(const unsigned char *sha1);
-struct commit *lookup_commit_reference(const unsigned char *sha1);
-struct commit *lookup_commit_reference_gently(const unsigned char *sha1,
- int quiet);
-
typedef void (*topo_sort_set_fn_t)(struct commit*, void *data);
typedef void* (*topo_sort_get_fn_t)(struct commit*);
/*
* from git:diff.h
*/
struct rev_info;
struct diff_options;
struct diff_queue_struct;
typedef void (*change_fn_t)(struct diff_options *options,
unsigned old_mode, unsigned new_mode,
const unsigned char *old_sha1,
const unsigned char *new_sha1,
const char *base, const char *path);
typedef void (*add_remove_fn_t)(struct diff_options *options,
int addremove, unsigned mode,
const unsigned char *sha1,
@@ -285,48 +320,58 @@ struct diff_options {
int nr_paths;
const char **paths;
int *pathlens;
change_fn_t change;
add_remove_fn_t add_remove;
diff_format_fn_t format_callback;
void *format_callback_data;
};
enum color_diff {
DIFF_RESET = 0,
DIFF_PLAIN = 1,
DIFF_METAINFO = 2,
DIFF_FRAGINFO = 3,
DIFF_FILE_OLD = 4,
DIFF_FILE_NEW = 5,
DIFF_COMMIT = 6,
DIFF_WHITESPACE = 7,
};
+/*
+ * from git:refs.g
+ */
+
+typedef int each_ref_fn(const char *refname, const unsigned char *sha1, int flags, void *cb_data);
+extern int head_ref(each_ref_fn, void *);
+extern int for_each_ref(each_ref_fn, void *);
+extern int for_each_tag_ref(each_ref_fn, void *);
+extern int for_each_branch_ref(each_ref_fn, void *);
+extern int for_each_remote_ref(each_ref_fn, void *);
/*
* from git:revision.h
*/
struct rev_info;
struct log_info;
typedef void (prune_fn_t)(struct rev_info *revs, struct commit *commit);
struct rev_info {
/* Starting list */
struct commit_list *commits;
struct object_array pending;
/* Basic information */
const char *prefix;
void *prune_data;
prune_fn_t *prune_fn;
/* Traversal flags */
unsigned int dense:1,
@@ -370,30 +415,35 @@ struct rev_info {
int nr, total;
const char *mime_boundary;
const char *message_id;
const char *ref_message_id;
const char *add_signoff;
const char *extra_headers;
/* Filter by commit log message */
struct grep_opt *grep_filter;
/* special limits */
int max_count;
unsigned long max_age;
unsigned long min_age;
/* diff info for patches and for paths limiting */
struct diff_options diffopt;
struct diff_options pruning;
topo_sort_set_fn_t topo_setter;
topo_sort_get_fn_t topo_getter;
};
+extern void init_revisions(struct rev_info *revs, const char *prefix);
+extern int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def);
+extern int handle_revision_arg(const char *arg, struct rev_info *revs,int flags,int cant_be_filename);
+
+extern void prepare_revision_walk(struct rev_info *revs);
extern struct commit *get_revision(struct rev_info *revs);
#endif /* GIT_H */