summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--git.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/git.h b/git.h
index b1e4828..991eaa5 100644
--- a/git.h
+++ b/git.h
@@ -79,96 +79,109 @@ static inline void *xrealloc(void *ptr, size_t size)
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
127enum object_type {
128 OBJ_NONE = 0,
129 OBJ_COMMIT = 1,
130 OBJ_TREE = 2,
131 OBJ_BLOB = 3,
132 OBJ_TAG = 4,
133 /* 5 for future expansion */
134 OBJ_OFS_DELTA = 6,
135 OBJ_REF_DELTA = 7,
136 OBJ_BAD,
137};
138
139
127/* Convert to/from hex/sha1 representation */ 140/* Convert to/from hex/sha1 representation */
128#define MINIMUM_ABBREV 4 141#define MINIMUM_ABBREV 4
129#define DEFAULT_ABBREV 7 142#define DEFAULT_ABBREV 7
130 143
131extern const unsigned char null_sha1[20]; 144extern const unsigned char null_sha1[20];
132 145
133extern int sha1_object_info(const unsigned char *, char *, unsigned long *); 146extern int sha1_object_info(const unsigned char *, char *, unsigned long *);
134 147
135extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size); 148extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size);
136 149
137extern int get_sha1(const char *str, unsigned char *sha1); 150extern int get_sha1(const char *str, unsigned char *sha1);
138extern int get_sha1_hex(const char *hex, unsigned char *sha1); 151extern int get_sha1_hex(const char *hex, unsigned char *sha1);
139 extern char *sha1_to_hex(const unsigned char *sha1);/* static buffer result! */ 152 extern char *sha1_to_hex(const unsigned char *sha1);/* static buffer result! */
140 153
141static inline int is_null_sha1(const unsigned char *sha1) 154static inline int is_null_sha1(const unsigned char *sha1)
142{ 155{
143 return !memcmp(sha1, null_sha1, 20); 156 return !memcmp(sha1, null_sha1, 20);
144} 157}
145static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2) 158static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
146{ 159{
147 return memcmp(sha1, sha2, 20); 160 return memcmp(sha1, sha2, 20);
148} 161}
149static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src) 162static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
150{ 163{
151 memcpy(sha_dst, sha_src, 20); 164 memcpy(sha_dst, sha_src, 20);
152} 165}
153static inline void hashclr(unsigned char *hash) 166static inline void hashclr(unsigned char *hash)
154{ 167{
155 memset(hash, 0, 20); 168 memset(hash, 0, 20);
156} 169}
157 170
158 171
159/* 172/*
160 * from git:grep.h 173 * from git:grep.h
161 */ 174 */
162 175
163enum grep_pat_token { 176enum grep_pat_token {
164 GREP_PATTERN, 177 GREP_PATTERN,
165 GREP_PATTERN_HEAD, 178 GREP_PATTERN_HEAD,
166 GREP_PATTERN_BODY, 179 GREP_PATTERN_BODY,
167 GREP_AND, 180 GREP_AND,
168 GREP_OPEN_PAREN, 181 GREP_OPEN_PAREN,
169 GREP_CLOSE_PAREN, 182 GREP_CLOSE_PAREN,
170 GREP_NOT, 183 GREP_NOT,
171 GREP_OR, 184 GREP_OR,
172}; 185};
173 186
174enum grep_context { 187enum grep_context {
@@ -183,96 +196,98 @@ struct grep_pat {
183 enum grep_pat_token token; 196 enum grep_pat_token token;
184 const char *pattern; 197 const char *pattern;
185 regex_t regexp; 198 regex_t regexp;
186}; 199};
187 200
188enum grep_expr_node { 201enum grep_expr_node {
189 GREP_NODE_ATOM, 202 GREP_NODE_ATOM,
190 GREP_NODE_NOT, 203 GREP_NODE_NOT,
191 GREP_NODE_AND, 204 GREP_NODE_AND,
192 GREP_NODE_OR, 205 GREP_NODE_OR,
193}; 206};
194 207
195struct grep_opt { 208struct grep_opt {
196 struct grep_pat *pattern_list; 209 struct grep_pat *pattern_list;
197 struct grep_pat **pattern_tail; 210 struct grep_pat **pattern_tail;
198 struct grep_expr *pattern_expression; 211 struct grep_expr *pattern_expression;
199 int prefix_length; 212 int prefix_length;
200 regex_t regexp; 213 regex_t regexp;
201 unsigned linenum:1; 214 unsigned linenum:1;
202 unsigned invert:1; 215 unsigned invert:1;
203 unsigned status_only:1; 216 unsigned status_only:1;
204 unsigned name_only:1; 217 unsigned name_only:1;
205 unsigned unmatch_name_only:1; 218 unsigned unmatch_name_only:1;
206 unsigned count:1; 219 unsigned count:1;
207 unsigned word_regexp:1; 220 unsigned word_regexp:1;
208 unsigned fixed:1; 221 unsigned fixed:1;
209 unsigned all_match:1; 222 unsigned all_match:1;
210#define GREP_BINARY_DEFAULT 0 223#define GREP_BINARY_DEFAULT 0
211#define GREP_BINARY_NOMATCH 1 224#define GREP_BINARY_NOMATCH 1
212#define GREP_BINARY_TEXT 2 225#define GREP_BINARY_TEXT 2
213 unsigned binary:2; 226 unsigned binary:2;
214 unsigned extended:1; 227 unsigned extended:1;
215 unsigned relative:1; 228 unsigned relative:1;
216 unsigned pathname:1; 229 unsigned pathname:1;
217 int regflags; 230 int regflags;
218 unsigned pre_context; 231 unsigned pre_context;
219 unsigned post_context; 232 unsigned post_context;
220}; 233};
221 234
222 235
223extern void compile_grep_patterns(struct grep_opt *opt); 236extern void compile_grep_patterns(struct grep_opt *opt);
224extern void free_grep_patterns(struct grep_opt *opt); 237extern void free_grep_patterns(struct grep_opt *opt);
225 238
226 239
227/* 240/*
228 * from git:object.h 241 * from git:object.h
229 */ 242 */
230 243
244extern const char *type_names[9];
245
231struct object_list { 246struct object_list {
232 struct object *item; 247 struct object *item;
233 struct object_list *next; 248 struct object_list *next;
234}; 249};
235 250
236struct object_refs { 251struct object_refs {
237 unsigned count; 252 unsigned count;
238 struct object *base; 253 struct object *base;
239 struct object *ref[FLEX_ARRAY]; /* more */ 254 struct object *ref[FLEX_ARRAY]; /* more */
240}; 255};
241 256
242struct object_array { 257struct object_array {
243 unsigned int nr; 258 unsigned int nr;
244 unsigned int alloc; 259 unsigned int alloc;
245 struct object_array_entry { 260 struct object_array_entry {
246 struct object *item; 261 struct object *item;
247 const char *name; 262 const char *name;
248 } *objects; 263 } *objects;
249}; 264};
250 265
251#define TYPE_BITS 3 266#define TYPE_BITS 3
252#define FLAG_BITS 27 267#define FLAG_BITS 27
253 268
254/* 269/*
255 * The object type is stored in 3 bits. 270 * The object type is stored in 3 bits.
256 */ 271 */
257struct object { 272struct object {
258 unsigned parsed : 1; 273 unsigned parsed : 1;
259 unsigned used : 1; 274 unsigned used : 1;
260 unsigned type : TYPE_BITS; 275 unsigned type : TYPE_BITS;
261 unsigned flags : FLAG_BITS; 276 unsigned flags : FLAG_BITS;
262 unsigned char sha1[20]; 277 unsigned char sha1[20];
263}; 278};
264 279
265 280
266/* 281/*
267 * from git:tree.h 282 * from git:tree.h
268 */ 283 */
269 284
270struct tree { 285struct tree {
271 struct object object; 286 struct object object;
272 void *buffer; 287 void *buffer;
273 unsigned long size; 288 unsigned long size;
274}; 289};
275 290
276 291
277struct tree *lookup_tree(const unsigned char *sha1); 292struct tree *lookup_tree(const unsigned char *sha1);
278int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size); 293int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
@@ -299,96 +314,115 @@ struct commit_list {
299struct commit { 314struct commit {
300 struct object object; 315 struct object object;
301 void *util; 316 void *util;
302 unsigned long date; 317 unsigned long date;
303 struct commit_list *parents; 318 struct commit_list *parents;
304 struct tree *tree; 319 struct tree *tree;
305 char *buffer; 320 char *buffer;
306}; 321};
307 322
308 323
309struct commit *lookup_commit(const unsigned char *sha1); 324struct commit *lookup_commit(const unsigned char *sha1);
310struct commit *lookup_commit_reference(const unsigned char *sha1); 325struct commit *lookup_commit_reference(const unsigned char *sha1);
311struct commit *lookup_commit_reference_gently(const unsigned char *sha1, 326struct commit *lookup_commit_reference_gently(const unsigned char *sha1,
312 int quiet); 327 int quiet);
313 328
314int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size); 329int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size);
315int parse_commit(struct commit *item); 330int parse_commit(struct commit *item);
316 331
317struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p); 332struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p);
318struct commit_list * insert_by_date(struct commit *item, struct commit_list **list); 333struct commit_list * insert_by_date(struct commit *item, struct commit_list **list);
319 334
320void free_commit_list(struct commit_list *list); 335void free_commit_list(struct commit_list *list);
321 336
322void sort_by_date(struct commit_list **list); 337void sort_by_date(struct commit_list **list);
323 338
324/* Commit formats */ 339/* Commit formats */
325enum cmit_fmt { 340enum cmit_fmt {
326 CMIT_FMT_RAW, 341 CMIT_FMT_RAW,
327 CMIT_FMT_MEDIUM, 342 CMIT_FMT_MEDIUM,
328 CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM, 343 CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM,
329 CMIT_FMT_SHORT, 344 CMIT_FMT_SHORT,
330 CMIT_FMT_FULL, 345 CMIT_FMT_FULL,
331 CMIT_FMT_FULLER, 346 CMIT_FMT_FULLER,
332 CMIT_FMT_ONELINE, 347 CMIT_FMT_ONELINE,
333 CMIT_FMT_EMAIL, 348 CMIT_FMT_EMAIL,
334 349
335 CMIT_FMT_UNSPECIFIED, 350 CMIT_FMT_UNSPECIFIED,
336}; 351};
337 352
338extern 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); 353extern 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);
339 354
340 355
341typedef void (*topo_sort_set_fn_t)(struct commit*, void *data); 356typedef void (*topo_sort_set_fn_t)(struct commit*, void *data);
342typedef void* (*topo_sort_get_fn_t)(struct commit*); 357typedef void* (*topo_sort_get_fn_t)(struct commit*);
343 358
344 359
345 360
346/* 361/*
362 * from git:tag.h
363 */
364
365extern const char *tag_type;
366
367struct tag {
368 struct object object;
369 struct object *tagged;
370 char *tag;
371 char *signature; /* not actually implemented */
372};
373
374extern struct tag *lookup_tag(const unsigned char *sha1);
375extern int parse_tag_buffer(struct tag *item, void *data, unsigned long size);
376extern int parse_tag(struct tag *item);
377extern struct object *deref_tag(struct object *, const char *, int);
378
379
380/*
347 * from git:diffcore.h 381 * from git:diffcore.h
348 */ 382 */
349 383
350struct diff_filespec { 384struct diff_filespec {
351 unsigned char sha1[20]; 385 unsigned char sha1[20];
352 char *path; 386 char *path;
353 void *data; 387 void *data;
354 void *cnt_data; 388 void *cnt_data;
355 unsigned long size; 389 unsigned long size;
356 int xfrm_flags; /* for use by the xfrm */ 390 int xfrm_flags; /* for use by the xfrm */
357 unsigned short mode; /* file mode */ 391 unsigned short mode; /* file mode */
358 unsigned sha1_valid : 1; /* if true, use sha1 and trust mode; 392 unsigned sha1_valid : 1; /* if true, use sha1 and trust mode;
359 * if false, use the name and read from 393 * if false, use the name and read from
360 * the filesystem. 394 * the filesystem.
361 */ 395 */
362#define DIFF_FILE_VALID(spec) (((spec)->mode) != 0) 396#define DIFF_FILE_VALID(spec) (((spec)->mode) != 0)
363 unsigned should_free : 1; /* data should be free()'ed */ 397 unsigned should_free : 1; /* data should be free()'ed */
364 unsigned should_munmap : 1; /* data should be munmap()'ed */ 398 unsigned should_munmap : 1; /* data should be munmap()'ed */
365}; 399};
366 400
367struct diff_filepair { 401struct diff_filepair {
368 struct diff_filespec *one; 402 struct diff_filespec *one;
369 struct diff_filespec *two; 403 struct diff_filespec *two;
370 unsigned short int score; 404 unsigned short int score;
371 char status; /* M C R N D U (see Documentation/diff-format.txt) */ 405 char status; /* M C R N D U (see Documentation/diff-format.txt) */
372 unsigned source_stays : 1; /* all of R/C are copies */ 406 unsigned source_stays : 1; /* all of R/C are copies */
373 unsigned broken_pair : 1; 407 unsigned broken_pair : 1;
374 unsigned renamed_pair : 1; 408 unsigned renamed_pair : 1;
375}; 409};
376 410
377#define DIFF_PAIR_UNMERGED(p) \ 411#define DIFF_PAIR_UNMERGED(p) \
378 (!DIFF_FILE_VALID((p)->one) && !DIFF_FILE_VALID((p)->two)) 412 (!DIFF_FILE_VALID((p)->one) && !DIFF_FILE_VALID((p)->two))
379 413
380#define DIFF_PAIR_RENAME(p) ((p)->renamed_pair) 414#define DIFF_PAIR_RENAME(p) ((p)->renamed_pair)
381 415
382#define DIFF_PAIR_BROKEN(p) \ 416#define DIFF_PAIR_BROKEN(p) \
383 ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \ 417 ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \
384 ((p)->broken_pair != 0) ) 418 ((p)->broken_pair != 0) )
385 419
386#define DIFF_PAIR_TYPE_CHANGED(p) \ 420#define DIFF_PAIR_TYPE_CHANGED(p) \
387 ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode)) 421 ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode))
388 422
389#define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode) 423#define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode)
390 424
391extern void diff_free_filepair(struct diff_filepair *); 425extern void diff_free_filepair(struct diff_filepair *);
392 426
393extern int diff_unmodified_pair(struct diff_filepair *); 427extern int diff_unmodified_pair(struct diff_filepair *);
394 428