summaryrefslogtreecommitdiffabout
path: root/git.h
Unidiff
Diffstat (limited to 'git.h') (more/less context) (ignore whitespace changes)
-rw-r--r--git.h68
1 files changed, 67 insertions, 1 deletions
diff --git a/git.h b/git.h
index 922a167..b1e4828 100644
--- a/git.h
+++ b/git.h
@@ -1,222 +1,288 @@
1#ifndef GIT_H 1#ifndef GIT_H
2#define GIT_H 2#define GIT_H
3 3
4 4
5/* 5/*
6 * from git:git-compat-util.h 6 * from git:git-compat-util.h
7 */ 7 */
8 8
9 9
10#ifndef FLEX_ARRAY 10#ifndef FLEX_ARRAY
11#if defined(__GNUC__) && (__GNUC__ < 3) 11#if defined(__GNUC__) && (__GNUC__ < 3)
12#define FLEX_ARRAY 0 12#define FLEX_ARRAY 0
13#else 13#else
14#define FLEX_ARRAY /* empty */ 14#define FLEX_ARRAY /* empty */
15#endif 15#endif
16#endif 16#endif
17 17
18 18
19#include <unistd.h> 19#include <unistd.h>
20#include <stdio.h> 20#include <stdio.h>
21#include <sys/stat.h> 21#include <sys/stat.h>
22#include <fcntl.h> 22#include <fcntl.h>
23#include <stddef.h> 23#include <stddef.h>
24#include <stdlib.h> 24#include <stdlib.h>
25#include <stdarg.h> 25#include <stdarg.h>
26#include <string.h> 26#include <string.h>
27#include <errno.h> 27#include <errno.h>
28#include <limits.h> 28#include <limits.h>
29#include <sys/param.h> 29#include <sys/param.h>
30#include <netinet/in.h> 30#include <netinet/in.h>
31#include <sys/types.h> 31#include <sys/types.h>
32#include <dirent.h> 32#include <dirent.h>
33#include <time.h> 33#include <time.h>
34 34#include <regex.h>
35 35
36/* On most systems <limits.h> would have given us this, but 36/* On most systems <limits.h> would have given us this, but
37 * not on some systems (e.g. GNU/Hurd). 37 * not on some systems (e.g. GNU/Hurd).
38 */ 38 */
39#ifndef PATH_MAX 39#ifndef PATH_MAX
40#define PATH_MAX 4096 40#define PATH_MAX 4096
41#endif 41#endif
42 42
43#ifdef __GNUC__ 43#ifdef __GNUC__
44#define NORETURN __attribute__((__noreturn__)) 44#define NORETURN __attribute__((__noreturn__))
45#else 45#else
46#define NORETURN 46#define NORETURN
47#ifndef __attribute__ 47#ifndef __attribute__
48#define __attribute__(x) 48#define __attribute__(x)
49#endif 49#endif
50#endif 50#endif
51 51
52 52
53extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); 53extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
54 54
55 55
56static inline char* xstrdup(const char *str) 56static inline char* xstrdup(const char *str)
57{ 57{
58 char *ret = strdup(str); 58 char *ret = strdup(str);
59 if (!ret) 59 if (!ret)
60 die("Out of memory, strdup failed"); 60 die("Out of memory, strdup failed");
61 return ret; 61 return ret;
62} 62}
63 63
64static inline void *xmalloc(size_t size) 64static inline void *xmalloc(size_t size)
65{ 65{
66 void *ret = malloc(size); 66 void *ret = malloc(size);
67 if (!ret && !size) 67 if (!ret && !size)
68 ret = malloc(1); 68 ret = malloc(1);
69 if (!ret) 69 if (!ret)
70 die("Out of memory, malloc failed"); 70 die("Out of memory, malloc failed");
71#ifdef XMALLOC_POISON 71#ifdef XMALLOC_POISON
72 memset(ret, 0xA5, size); 72 memset(ret, 0xA5, size);
73#endif 73#endif
74 return ret; 74 return ret;
75} 75}
76 76
77static inline void *xrealloc(void *ptr, size_t size) 77static inline void *xrealloc(void *ptr, size_t size)
78{ 78{
79 void *ret = realloc(ptr, size); 79 void *ret = realloc(ptr, size);
80 if (!ret && !size) 80 if (!ret && !size)
81 ret = realloc(ptr, 1); 81 ret = realloc(ptr, 1);
82 if (!ret) 82 if (!ret)
83 die("Out of memory, realloc failed"); 83 die("Out of memory, realloc failed");
84 return ret; 84 return ret;
85} 85}
86 86
87static inline void *xcalloc(size_t nmemb, size_t size) 87static inline void *xcalloc(size_t nmemb, size_t size)
88{ 88{
89 void *ret = calloc(nmemb, size); 89 void *ret = calloc(nmemb, size);
90 if (!ret && (!nmemb || !size)) 90 if (!ret && (!nmemb || !size))
91 ret = calloc(1, 1); 91 ret = calloc(1, 1);
92 if (!ret) 92 if (!ret)
93 die("Out of memory, calloc failed"); 93 die("Out of memory, calloc failed");
94 return ret; 94 return ret;
95} 95}
96 96
97static inline ssize_t xread(int fd, void *buf, size_t len) 97static inline ssize_t xread(int fd, void *buf, size_t len)
98{ 98{
99 ssize_t nr; 99 ssize_t nr;
100 while (1) { 100 while (1) {
101 nr = read(fd, buf, len); 101 nr = read(fd, buf, len);
102 if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) 102 if ((nr < 0) && (errno == EAGAIN || errno == EINTR))
103 continue; 103 continue;
104 return nr; 104 return nr;
105 } 105 }
106} 106}
107 107
108static inline ssize_t xwrite(int fd, const void *buf, size_t len) 108static inline ssize_t xwrite(int fd, const void *buf, size_t len)
109{ 109{
110 ssize_t nr; 110 ssize_t nr;
111 while (1) { 111 while (1) {
112 nr = write(fd, buf, len); 112 nr = write(fd, buf, len);
113 if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) 113 if ((nr < 0) && (errno == EAGAIN || errno == EINTR))
114 continue; 114 continue;
115 return nr; 115 return nr;
116 } 116 }
117} 117}
118 118
119 119
120 120
121 121
122/* 122/*
123 * from git:cache.h 123 * from git:cache.h
124 */ 124 */
125 125
126 126
127/* Convert to/from hex/sha1 representation */ 127/* Convert to/from hex/sha1 representation */
128#define MINIMUM_ABBREV 4 128#define MINIMUM_ABBREV 4
129#define DEFAULT_ABBREV 7 129#define DEFAULT_ABBREV 7
130 130
131extern const unsigned char null_sha1[20]; 131extern const unsigned char null_sha1[20];
132 132
133extern int sha1_object_info(const unsigned char *, char *, unsigned long *); 133extern int sha1_object_info(const unsigned char *, char *, unsigned long *);
134 134
135extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size); 135extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size);
136 136
137extern int get_sha1(const char *str, unsigned char *sha1); 137extern int get_sha1(const char *str, unsigned char *sha1);
138extern int get_sha1_hex(const char *hex, unsigned char *sha1); 138extern int get_sha1_hex(const char *hex, unsigned char *sha1);
139 extern char *sha1_to_hex(const unsigned char *sha1);/* static buffer result! */ 139 extern char *sha1_to_hex(const unsigned char *sha1);/* static buffer result! */
140 140
141static inline int is_null_sha1(const unsigned char *sha1) 141static inline int is_null_sha1(const unsigned char *sha1)
142{ 142{
143 return !memcmp(sha1, null_sha1, 20); 143 return !memcmp(sha1, null_sha1, 20);
144} 144}
145static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2) 145static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
146{ 146{
147 return memcmp(sha1, sha2, 20); 147 return memcmp(sha1, sha2, 20);
148} 148}
149static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src) 149static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
150{ 150{
151 memcpy(sha_dst, sha_src, 20); 151 memcpy(sha_dst, sha_src, 20);
152} 152}
153static inline void hashclr(unsigned char *hash) 153static inline void hashclr(unsigned char *hash)
154{ 154{
155 memset(hash, 0, 20); 155 memset(hash, 0, 20);
156} 156}
157 157
158 158
159/*
160 * from git:grep.h
161 */
162
163enum grep_pat_token {
164 GREP_PATTERN,
165 GREP_PATTERN_HEAD,
166 GREP_PATTERN_BODY,
167 GREP_AND,
168 GREP_OPEN_PAREN,
169 GREP_CLOSE_PAREN,
170 GREP_NOT,
171 GREP_OR,
172};
173
174enum grep_context {
175 GREP_CONTEXT_HEAD,
176 GREP_CONTEXT_BODY,
177};
178
179struct grep_pat {
180 struct grep_pat *next;
181 const char *origin;
182 int no;
183 enum grep_pat_token token;
184 const char *pattern;
185 regex_t regexp;
186};
187
188enum grep_expr_node {
189 GREP_NODE_ATOM,
190 GREP_NODE_NOT,
191 GREP_NODE_AND,
192 GREP_NODE_OR,
193};
194
195struct grep_opt {
196 struct grep_pat *pattern_list;
197 struct grep_pat **pattern_tail;
198 struct grep_expr *pattern_expression;
199 int prefix_length;
200 regex_t regexp;
201 unsigned linenum:1;
202 unsigned invert:1;
203 unsigned status_only:1;
204 unsigned name_only:1;
205 unsigned unmatch_name_only:1;
206 unsigned count:1;
207 unsigned word_regexp:1;
208 unsigned fixed:1;
209 unsigned all_match:1;
210#define GREP_BINARY_DEFAULT 0
211#define GREP_BINARY_NOMATCH 1
212#define GREP_BINARY_TEXT 2
213 unsigned binary:2;
214 unsigned extended:1;
215 unsigned relative:1;
216 unsigned pathname:1;
217 int regflags;
218 unsigned pre_context;
219 unsigned post_context;
220};
221
222
223extern void compile_grep_patterns(struct grep_opt *opt);
224extern void free_grep_patterns(struct grep_opt *opt);
159 225
160 226
161/* 227/*
162 * from git:object.h 228 * from git:object.h
163 */ 229 */
164 230
165struct object_list { 231struct object_list {
166 struct object *item; 232 struct object *item;
167 struct object_list *next; 233 struct object_list *next;
168}; 234};
169 235
170struct object_refs { 236struct object_refs {
171 unsigned count; 237 unsigned count;
172 struct object *base; 238 struct object *base;
173 struct object *ref[FLEX_ARRAY]; /* more */ 239 struct object *ref[FLEX_ARRAY]; /* more */
174}; 240};
175 241
176struct object_array { 242struct object_array {
177 unsigned int nr; 243 unsigned int nr;
178 unsigned int alloc; 244 unsigned int alloc;
179 struct object_array_entry { 245 struct object_array_entry {
180 struct object *item; 246 struct object *item;
181 const char *name; 247 const char *name;
182 } *objects; 248 } *objects;
183}; 249};
184 250
185#define TYPE_BITS 3 251#define TYPE_BITS 3
186#define FLAG_BITS 27 252#define FLAG_BITS 27
187 253
188/* 254/*
189 * The object type is stored in 3 bits. 255 * The object type is stored in 3 bits.
190 */ 256 */
191struct object { 257struct object {
192 unsigned parsed : 1; 258 unsigned parsed : 1;
193 unsigned used : 1; 259 unsigned used : 1;
194 unsigned type : TYPE_BITS; 260 unsigned type : TYPE_BITS;
195 unsigned flags : FLAG_BITS; 261 unsigned flags : FLAG_BITS;
196 unsigned char sha1[20]; 262 unsigned char sha1[20];
197}; 263};
198 264
199 265
200/* 266/*
201 * from git:tree.h 267 * from git:tree.h
202 */ 268 */
203 269
204struct tree { 270struct tree {
205 struct object object; 271 struct object object;
206 void *buffer; 272 void *buffer;
207 unsigned long size; 273 unsigned long size;
208}; 274};
209 275
210 276
211struct tree *lookup_tree(const unsigned char *sha1); 277struct tree *lookup_tree(const unsigned char *sha1);
212int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size); 278int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
213int parse_tree(struct tree *tree); 279int parse_tree(struct tree *tree);
214struct tree *parse_tree_indirect(const unsigned char *sha1); 280struct tree *parse_tree_indirect(const unsigned char *sha1);
215 281
216typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int); 282typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int);
217 283
218extern int read_tree_recursive(struct tree *tree, 284extern int read_tree_recursive(struct tree *tree,
219 const char *base, int baselen, 285 const char *base, int baselen,
220 int stage, const char **match, 286 int stage, const char **match,
221 read_tree_fn_t fn); 287 read_tree_fn_t fn);
222 288