-rw-r--r-- | git.h | 4 | ||||
-rw-r--r-- | ui-summary.c | 52 |
2 files changed, 37 insertions, 19 deletions
@@ -89,384 +89,388 @@ static inline void *xcalloc(size_t nmemb, size_t size) | |||
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 | ||
97 | static inline ssize_t xread(int fd, void *buf, size_t len) | 97 | static 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 | ||
108 | static inline ssize_t xwrite(int fd, const void *buf, size_t len) | 108 | static 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 | enum object_type { | 127 | enum object_type { |
128 | OBJ_NONE = 0, | 128 | OBJ_NONE = 0, |
129 | OBJ_COMMIT = 1, | 129 | OBJ_COMMIT = 1, |
130 | OBJ_TREE = 2, | 130 | OBJ_TREE = 2, |
131 | OBJ_BLOB = 3, | 131 | OBJ_BLOB = 3, |
132 | OBJ_TAG = 4, | 132 | OBJ_TAG = 4, |
133 | /* 5 for future expansion */ | 133 | /* 5 for future expansion */ |
134 | OBJ_OFS_DELTA = 6, | 134 | OBJ_OFS_DELTA = 6, |
135 | OBJ_REF_DELTA = 7, | 135 | OBJ_REF_DELTA = 7, |
136 | OBJ_BAD, | 136 | OBJ_BAD, |
137 | }; | 137 | }; |
138 | 138 | ||
139 | 139 | ||
140 | /* Convert to/from hex/sha1 representation */ | 140 | /* Convert to/from hex/sha1 representation */ |
141 | #define MINIMUM_ABBREV 4 | 141 | #define MINIMUM_ABBREV 4 |
142 | #define DEFAULT_ABBREV 7 | 142 | #define DEFAULT_ABBREV 7 |
143 | 143 | ||
144 | extern const unsigned char null_sha1[20]; | 144 | extern const unsigned char null_sha1[20]; |
145 | 145 | ||
146 | extern int sha1_object_info(const unsigned char *, char *, unsigned long *); | 146 | extern int sha1_object_info(const unsigned char *, char *, unsigned long *); |
147 | 147 | ||
148 | extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size); | 148 | extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size); |
149 | 149 | ||
150 | extern int get_sha1(const char *str, unsigned char *sha1); | 150 | extern int get_sha1(const char *str, unsigned char *sha1); |
151 | extern int get_sha1_hex(const char *hex, 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! */ | 152 | extern char *sha1_to_hex(const unsigned char *sha1);/* static buffer result! */ |
153 | 153 | ||
154 | static inline int is_null_sha1(const unsigned char *sha1) | 154 | static inline int is_null_sha1(const unsigned char *sha1) |
155 | { | 155 | { |
156 | return !memcmp(sha1, null_sha1, 20); | 156 | return !memcmp(sha1, null_sha1, 20); |
157 | } | 157 | } |
158 | static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2) | 158 | static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2) |
159 | { | 159 | { |
160 | return memcmp(sha1, sha2, 20); | 160 | return memcmp(sha1, sha2, 20); |
161 | } | 161 | } |
162 | static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src) | 162 | static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src) |
163 | { | 163 | { |
164 | memcpy(sha_dst, sha_src, 20); | 164 | memcpy(sha_dst, sha_src, 20); |
165 | } | 165 | } |
166 | static inline void hashclr(unsigned char *hash) | 166 | static inline void hashclr(unsigned char *hash) |
167 | { | 167 | { |
168 | memset(hash, 0, 20); | 168 | memset(hash, 0, 20); |
169 | } | 169 | } |
170 | 170 | ||
171 | 171 | ||
172 | /* | 172 | /* |
173 | * from git:grep.h | 173 | * from git:grep.h |
174 | */ | 174 | */ |
175 | 175 | ||
176 | enum grep_pat_token { | 176 | enum grep_pat_token { |
177 | GREP_PATTERN, | 177 | GREP_PATTERN, |
178 | GREP_PATTERN_HEAD, | 178 | GREP_PATTERN_HEAD, |
179 | GREP_PATTERN_BODY, | 179 | GREP_PATTERN_BODY, |
180 | GREP_AND, | 180 | GREP_AND, |
181 | GREP_OPEN_PAREN, | 181 | GREP_OPEN_PAREN, |
182 | GREP_CLOSE_PAREN, | 182 | GREP_CLOSE_PAREN, |
183 | GREP_NOT, | 183 | GREP_NOT, |
184 | GREP_OR, | 184 | GREP_OR, |
185 | }; | 185 | }; |
186 | 186 | ||
187 | enum grep_context { | 187 | enum grep_context { |
188 | GREP_CONTEXT_HEAD, | 188 | GREP_CONTEXT_HEAD, |
189 | GREP_CONTEXT_BODY, | 189 | GREP_CONTEXT_BODY, |
190 | }; | 190 | }; |
191 | 191 | ||
192 | struct grep_pat { | 192 | struct grep_pat { |
193 | struct grep_pat *next; | 193 | struct grep_pat *next; |
194 | const char *origin; | 194 | const char *origin; |
195 | int no; | 195 | int no; |
196 | enum grep_pat_token token; | 196 | enum grep_pat_token token; |
197 | const char *pattern; | 197 | const char *pattern; |
198 | regex_t regexp; | 198 | regex_t regexp; |
199 | }; | 199 | }; |
200 | 200 | ||
201 | enum grep_expr_node { | 201 | enum grep_expr_node { |
202 | GREP_NODE_ATOM, | 202 | GREP_NODE_ATOM, |
203 | GREP_NODE_NOT, | 203 | GREP_NODE_NOT, |
204 | GREP_NODE_AND, | 204 | GREP_NODE_AND, |
205 | GREP_NODE_OR, | 205 | GREP_NODE_OR, |
206 | }; | 206 | }; |
207 | 207 | ||
208 | struct grep_opt { | 208 | struct grep_opt { |
209 | struct grep_pat *pattern_list; | 209 | struct grep_pat *pattern_list; |
210 | struct grep_pat **pattern_tail; | 210 | struct grep_pat **pattern_tail; |
211 | struct grep_expr *pattern_expression; | 211 | struct grep_expr *pattern_expression; |
212 | int prefix_length; | 212 | int prefix_length; |
213 | regex_t regexp; | 213 | regex_t regexp; |
214 | unsigned linenum:1; | 214 | unsigned linenum:1; |
215 | unsigned invert:1; | 215 | unsigned invert:1; |
216 | unsigned status_only:1; | 216 | unsigned status_only:1; |
217 | unsigned name_only:1; | 217 | unsigned name_only:1; |
218 | unsigned unmatch_name_only:1; | 218 | unsigned unmatch_name_only:1; |
219 | unsigned count:1; | 219 | unsigned count:1; |
220 | unsigned word_regexp:1; | 220 | unsigned word_regexp:1; |
221 | unsigned fixed:1; | 221 | unsigned fixed:1; |
222 | unsigned all_match:1; | 222 | unsigned all_match:1; |
223 | #define GREP_BINARY_DEFAULT 0 | 223 | #define GREP_BINARY_DEFAULT 0 |
224 | #define GREP_BINARY_NOMATCH 1 | 224 | #define GREP_BINARY_NOMATCH 1 |
225 | #define GREP_BINARY_TEXT 2 | 225 | #define GREP_BINARY_TEXT 2 |
226 | unsigned binary:2; | 226 | unsigned binary:2; |
227 | unsigned extended:1; | 227 | unsigned extended:1; |
228 | unsigned relative:1; | 228 | unsigned relative:1; |
229 | unsigned pathname:1; | 229 | unsigned pathname:1; |
230 | int regflags; | 230 | int regflags; |
231 | unsigned pre_context; | 231 | unsigned pre_context; |
232 | unsigned post_context; | 232 | unsigned post_context; |
233 | }; | 233 | }; |
234 | 234 | ||
235 | 235 | ||
236 | extern void compile_grep_patterns(struct grep_opt *opt); | 236 | extern void compile_grep_patterns(struct grep_opt *opt); |
237 | extern void free_grep_patterns(struct grep_opt *opt); | 237 | extern void free_grep_patterns(struct grep_opt *opt); |
238 | 238 | ||
239 | 239 | ||
240 | /* | 240 | /* |
241 | * from git:object.h | 241 | * from git:object.h |
242 | */ | 242 | */ |
243 | 243 | ||
244 | extern const char *type_names[9]; | 244 | extern const char *type_names[9]; |
245 | 245 | ||
246 | struct object_list { | 246 | struct object_list { |
247 | struct object *item; | 247 | struct object *item; |
248 | struct object_list *next; | 248 | struct object_list *next; |
249 | }; | 249 | }; |
250 | 250 | ||
251 | struct object_refs { | 251 | struct object_refs { |
252 | unsigned count; | 252 | unsigned count; |
253 | struct object *base; | 253 | struct object *base; |
254 | struct object *ref[FLEX_ARRAY]; /* more */ | 254 | struct object *ref[FLEX_ARRAY]; /* more */ |
255 | }; | 255 | }; |
256 | 256 | ||
257 | struct object_array { | 257 | struct object_array { |
258 | unsigned int nr; | 258 | unsigned int nr; |
259 | unsigned int alloc; | 259 | unsigned int alloc; |
260 | struct object_array_entry { | 260 | struct object_array_entry { |
261 | struct object *item; | 261 | struct object *item; |
262 | const char *name; | 262 | const char *name; |
263 | } *objects; | 263 | } *objects; |
264 | }; | 264 | }; |
265 | 265 | ||
266 | #define TYPE_BITS 3 | 266 | #define TYPE_BITS 3 |
267 | #define FLAG_BITS 27 | 267 | #define FLAG_BITS 27 |
268 | 268 | ||
269 | /* | 269 | /* |
270 | * The object type is stored in 3 bits. | 270 | * The object type is stored in 3 bits. |
271 | */ | 271 | */ |
272 | struct object { | 272 | struct object { |
273 | unsigned parsed : 1; | 273 | unsigned parsed : 1; |
274 | unsigned used : 1; | 274 | unsigned used : 1; |
275 | unsigned type : TYPE_BITS; | 275 | unsigned type : TYPE_BITS; |
276 | unsigned flags : FLAG_BITS; | 276 | unsigned flags : FLAG_BITS; |
277 | unsigned char sha1[20]; | 277 | unsigned char sha1[20]; |
278 | }; | 278 | }; |
279 | 279 | ||
280 | 280 | ||
281 | /** Returns the object, having parsed it to find out what it is. **/ | ||
282 | struct object *parse_object(const unsigned char *sha1); | ||
283 | |||
284 | |||
281 | /* | 285 | /* |
282 | * from git:tree.h | 286 | * from git:tree.h |
283 | */ | 287 | */ |
284 | 288 | ||
285 | struct tree { | 289 | struct tree { |
286 | struct object object; | 290 | struct object object; |
287 | void *buffer; | 291 | void *buffer; |
288 | unsigned long size; | 292 | unsigned long size; |
289 | }; | 293 | }; |
290 | 294 | ||
291 | 295 | ||
292 | struct tree *lookup_tree(const unsigned char *sha1); | 296 | struct tree *lookup_tree(const unsigned char *sha1); |
293 | int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size); | 297 | int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size); |
294 | int parse_tree(struct tree *tree); | 298 | int parse_tree(struct tree *tree); |
295 | struct tree *parse_tree_indirect(const unsigned char *sha1); | 299 | struct tree *parse_tree_indirect(const unsigned char *sha1); |
296 | 300 | ||
297 | typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int); | 301 | typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int); |
298 | 302 | ||
299 | extern int read_tree_recursive(struct tree *tree, | 303 | extern int read_tree_recursive(struct tree *tree, |
300 | const char *base, int baselen, | 304 | const char *base, int baselen, |
301 | int stage, const char **match, | 305 | int stage, const char **match, |
302 | read_tree_fn_t fn); | 306 | read_tree_fn_t fn); |
303 | 307 | ||
304 | extern int read_tree(struct tree *tree, int stage, const char **paths); | 308 | extern int read_tree(struct tree *tree, int stage, const char **paths); |
305 | 309 | ||
306 | 310 | ||
307 | /* from git:commit.h */ | 311 | /* from git:commit.h */ |
308 | 312 | ||
309 | struct commit_list { | 313 | struct commit_list { |
310 | struct commit *item; | 314 | struct commit *item; |
311 | struct commit_list *next; | 315 | struct commit_list *next; |
312 | }; | 316 | }; |
313 | 317 | ||
314 | struct commit { | 318 | struct commit { |
315 | struct object object; | 319 | struct object object; |
316 | void *util; | 320 | void *util; |
317 | unsigned long date; | 321 | unsigned long date; |
318 | struct commit_list *parents; | 322 | struct commit_list *parents; |
319 | struct tree *tree; | 323 | struct tree *tree; |
320 | char *buffer; | 324 | char *buffer; |
321 | }; | 325 | }; |
322 | 326 | ||
323 | 327 | ||
324 | struct commit *lookup_commit(const unsigned char *sha1); | 328 | struct commit *lookup_commit(const unsigned char *sha1); |
325 | struct commit *lookup_commit_reference(const unsigned char *sha1); | 329 | struct commit *lookup_commit_reference(const unsigned char *sha1); |
326 | struct commit *lookup_commit_reference_gently(const unsigned char *sha1, | 330 | struct commit *lookup_commit_reference_gently(const unsigned char *sha1, |
327 | int quiet); | 331 | int quiet); |
328 | 332 | ||
329 | int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size); | 333 | int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size); |
330 | int parse_commit(struct commit *item); | 334 | int parse_commit(struct commit *item); |
331 | 335 | ||
332 | struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p); | 336 | 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); | 337 | struct commit_list * insert_by_date(struct commit *item, struct commit_list **list); |
334 | 338 | ||
335 | void free_commit_list(struct commit_list *list); | 339 | void free_commit_list(struct commit_list *list); |
336 | 340 | ||
337 | void sort_by_date(struct commit_list **list); | 341 | void sort_by_date(struct commit_list **list); |
338 | 342 | ||
339 | /* Commit formats */ | 343 | /* Commit formats */ |
340 | enum cmit_fmt { | 344 | enum cmit_fmt { |
341 | CMIT_FMT_RAW, | 345 | CMIT_FMT_RAW, |
342 | CMIT_FMT_MEDIUM, | 346 | CMIT_FMT_MEDIUM, |
343 | CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM, | 347 | CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM, |
344 | CMIT_FMT_SHORT, | 348 | CMIT_FMT_SHORT, |
345 | CMIT_FMT_FULL, | 349 | CMIT_FMT_FULL, |
346 | CMIT_FMT_FULLER, | 350 | CMIT_FMT_FULLER, |
347 | CMIT_FMT_ONELINE, | 351 | CMIT_FMT_ONELINE, |
348 | CMIT_FMT_EMAIL, | 352 | CMIT_FMT_EMAIL, |
349 | 353 | ||
350 | CMIT_FMT_UNSPECIFIED, | 354 | CMIT_FMT_UNSPECIFIED, |
351 | }; | 355 | }; |
352 | 356 | ||
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); | 357 | 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); |
354 | 358 | ||
355 | 359 | ||
356 | typedef void (*topo_sort_set_fn_t)(struct commit*, void *data); | 360 | typedef void (*topo_sort_set_fn_t)(struct commit*, void *data); |
357 | typedef void* (*topo_sort_get_fn_t)(struct commit*); | 361 | typedef void* (*topo_sort_get_fn_t)(struct commit*); |
358 | 362 | ||
359 | 363 | ||
360 | 364 | ||
361 | /* | 365 | /* |
362 | * from git:tag.h | 366 | * from git:tag.h |
363 | */ | 367 | */ |
364 | 368 | ||
365 | extern const char *tag_type; | 369 | extern const char *tag_type; |
366 | 370 | ||
367 | struct tag { | 371 | struct tag { |
368 | struct object object; | 372 | struct object object; |
369 | struct object *tagged; | 373 | struct object *tagged; |
370 | char *tag; | 374 | char *tag; |
371 | char *signature; /* not actually implemented */ | 375 | char *signature; /* not actually implemented */ |
372 | }; | 376 | }; |
373 | 377 | ||
374 | extern struct tag *lookup_tag(const unsigned char *sha1); | 378 | extern struct tag *lookup_tag(const unsigned char *sha1); |
375 | extern int parse_tag_buffer(struct tag *item, void *data, unsigned long size); | 379 | extern int parse_tag_buffer(struct tag *item, void *data, unsigned long size); |
376 | extern int parse_tag(struct tag *item); | 380 | extern int parse_tag(struct tag *item); |
377 | extern struct object *deref_tag(struct object *, const char *, int); | 381 | extern struct object *deref_tag(struct object *, const char *, int); |
378 | 382 | ||
379 | 383 | ||
380 | /* | 384 | /* |
381 | * from git:diffcore.h | 385 | * from git:diffcore.h |
382 | */ | 386 | */ |
383 | 387 | ||
384 | struct diff_filespec { | 388 | struct diff_filespec { |
385 | unsigned char sha1[20]; | 389 | unsigned char sha1[20]; |
386 | char *path; | 390 | char *path; |
387 | void *data; | 391 | void *data; |
388 | void *cnt_data; | 392 | void *cnt_data; |
389 | unsigned long size; | 393 | unsigned long size; |
390 | int xfrm_flags; /* for use by the xfrm */ | 394 | int xfrm_flags; /* for use by the xfrm */ |
391 | unsigned short mode; /* file mode */ | 395 | unsigned short mode; /* file mode */ |
392 | unsigned sha1_valid : 1; /* if true, use sha1 and trust mode; | 396 | unsigned sha1_valid : 1; /* if true, use sha1 and trust mode; |
393 | * if false, use the name and read from | 397 | * if false, use the name and read from |
394 | * the filesystem. | 398 | * the filesystem. |
395 | */ | 399 | */ |
396 | #define DIFF_FILE_VALID(spec) (((spec)->mode) != 0) | 400 | #define DIFF_FILE_VALID(spec) (((spec)->mode) != 0) |
397 | unsigned should_free : 1; /* data should be free()'ed */ | 401 | unsigned should_free : 1; /* data should be free()'ed */ |
398 | unsigned should_munmap : 1; /* data should be munmap()'ed */ | 402 | unsigned should_munmap : 1; /* data should be munmap()'ed */ |
399 | }; | 403 | }; |
400 | 404 | ||
401 | struct diff_filepair { | 405 | struct diff_filepair { |
402 | struct diff_filespec *one; | 406 | struct diff_filespec *one; |
403 | struct diff_filespec *two; | 407 | struct diff_filespec *two; |
404 | unsigned short int score; | 408 | unsigned short int score; |
405 | char status; /* M C R N D U (see Documentation/diff-format.txt) */ | 409 | char status; /* M C R N D U (see Documentation/diff-format.txt) */ |
406 | unsigned source_stays : 1; /* all of R/C are copies */ | 410 | unsigned source_stays : 1; /* all of R/C are copies */ |
407 | unsigned broken_pair : 1; | 411 | unsigned broken_pair : 1; |
408 | unsigned renamed_pair : 1; | 412 | unsigned renamed_pair : 1; |
409 | }; | 413 | }; |
410 | 414 | ||
411 | #define DIFF_PAIR_UNMERGED(p) \ | 415 | #define DIFF_PAIR_UNMERGED(p) \ |
412 | (!DIFF_FILE_VALID((p)->one) && !DIFF_FILE_VALID((p)->two)) | 416 | (!DIFF_FILE_VALID((p)->one) && !DIFF_FILE_VALID((p)->two)) |
413 | 417 | ||
414 | #define DIFF_PAIR_RENAME(p) ((p)->renamed_pair) | 418 | #define DIFF_PAIR_RENAME(p) ((p)->renamed_pair) |
415 | 419 | ||
416 | #define DIFF_PAIR_BROKEN(p) \ | 420 | #define DIFF_PAIR_BROKEN(p) \ |
417 | ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \ | 421 | ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \ |
418 | ((p)->broken_pair != 0) ) | 422 | ((p)->broken_pair != 0) ) |
419 | 423 | ||
420 | #define DIFF_PAIR_TYPE_CHANGED(p) \ | 424 | #define DIFF_PAIR_TYPE_CHANGED(p) \ |
421 | ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode)) | 425 | ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode)) |
422 | 426 | ||
423 | #define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode) | 427 | #define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode) |
424 | 428 | ||
425 | extern void diff_free_filepair(struct diff_filepair *); | 429 | extern void diff_free_filepair(struct diff_filepair *); |
426 | 430 | ||
427 | extern int diff_unmodified_pair(struct diff_filepair *); | 431 | extern int diff_unmodified_pair(struct diff_filepair *); |
428 | 432 | ||
429 | struct diff_queue_struct { | 433 | struct diff_queue_struct { |
430 | struct diff_filepair **queue; | 434 | struct diff_filepair **queue; |
431 | int alloc; | 435 | int alloc; |
432 | int nr; | 436 | int nr; |
433 | }; | 437 | }; |
434 | 438 | ||
435 | 439 | ||
436 | /* | 440 | /* |
437 | * from git:diff.h | 441 | * from git:diff.h |
438 | */ | 442 | */ |
439 | 443 | ||
440 | 444 | ||
441 | struct rev_info; | 445 | struct rev_info; |
442 | struct diff_options; | 446 | struct diff_options; |
443 | struct diff_queue_struct; | 447 | struct diff_queue_struct; |
444 | 448 | ||
445 | typedef void (*change_fn_t)(struct diff_options *options, | 449 | typedef void (*change_fn_t)(struct diff_options *options, |
446 | unsigned old_mode, unsigned new_mode, | 450 | unsigned old_mode, unsigned new_mode, |
447 | const unsigned char *old_sha1, | 451 | const unsigned char *old_sha1, |
448 | const unsigned char *new_sha1, | 452 | const unsigned char *new_sha1, |
449 | const char *base, const char *path); | 453 | const char *base, const char *path); |
450 | 454 | ||
451 | typedef void (*add_remove_fn_t)(struct diff_options *options, | 455 | typedef void (*add_remove_fn_t)(struct diff_options *options, |
452 | int addremove, unsigned mode, | 456 | int addremove, unsigned mode, |
453 | const unsigned char *sha1, | 457 | const unsigned char *sha1, |
454 | const char *base, const char *path); | 458 | const char *base, const char *path); |
455 | 459 | ||
456 | typedef void (*diff_format_fn_t)(struct diff_queue_struct *q, | 460 | typedef void (*diff_format_fn_t)(struct diff_queue_struct *q, |
457 | struct diff_options *options, void *data); | 461 | struct diff_options *options, void *data); |
458 | 462 | ||
459 | #define DIFF_FORMAT_RAW 0x0001 | 463 | #define DIFF_FORMAT_RAW 0x0001 |
460 | #define DIFF_FORMAT_DIFFSTAT0x0002 | 464 | #define DIFF_FORMAT_DIFFSTAT0x0002 |
461 | #define DIFF_FORMAT_NUMSTAT0x0004 | 465 | #define DIFF_FORMAT_NUMSTAT0x0004 |
462 | #define DIFF_FORMAT_SUMMARY0x0008 | 466 | #define DIFF_FORMAT_SUMMARY0x0008 |
463 | #define DIFF_FORMAT_PATCH0x0010 | 467 | #define DIFF_FORMAT_PATCH0x0010 |
464 | 468 | ||
465 | /* These override all above */ | 469 | /* These override all above */ |
466 | #define DIFF_FORMAT_NAME0x0100 | 470 | #define DIFF_FORMAT_NAME0x0100 |
467 | #define DIFF_FORMAT_NAME_STATUS0x0200 | 471 | #define DIFF_FORMAT_NAME_STATUS0x0200 |
468 | #define DIFF_FORMAT_CHECKDIFF0x0400 | 472 | #define DIFF_FORMAT_CHECKDIFF0x0400 |
469 | 473 | ||
470 | /* Same as output_format = 0 but we know that -s flag was given | 474 | /* Same as output_format = 0 but we know that -s flag was given |
471 | * and we should not give default value to output_format. | 475 | * and we should not give default value to output_format. |
472 | */ | 476 | */ |
diff --git a/ui-summary.c b/ui-summary.c index 5518d01..ff3ed4d 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -1,125 +1,139 @@ | |||
1 | /* ui-summary.c: functions for generating repo summary page | 1 | /* ui-summary.c: functions for generating repo summary page |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, | 11 | static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, |
12 | int flags, void *cb_data) | 12 | int flags, void *cb_data) |
13 | { | 13 | { |
14 | struct commit *commit; | 14 | struct commit *commit; |
15 | struct commitinfo *info; | 15 | struct commitinfo *info; |
16 | char buf[256], *url; | 16 | char buf[256], *url; |
17 | 17 | ||
18 | strncpy(buf, refname, sizeof(buf)); | 18 | strncpy(buf, refname, sizeof(buf)); |
19 | commit = lookup_commit(sha1); | 19 | commit = lookup_commit(sha1); |
20 | if (commit && !parse_commit(commit)){ | 20 | if (commit && !parse_commit(commit)){ |
21 | info = cgit_parse_commit(commit); | 21 | info = cgit_parse_commit(commit); |
22 | html("<tr><td>"); | 22 | html("<tr><td>"); |
23 | url = cgit_pageurl(cgit_query_repo, "log", | 23 | url = cgit_pageurl(cgit_query_repo, "log", |
24 | fmt("h=%s", refname)); | 24 | fmt("h=%s", refname)); |
25 | html_link_open(url, NULL, NULL); | 25 | html_link_open(url, NULL, NULL); |
26 | html_txt(buf); | 26 | html_txt(buf); |
27 | html_link_close(); | 27 | html_link_close(); |
28 | html("</td><td>"); | 28 | html("</td><td>"); |
29 | cgit_print_date(commit->date); | 29 | cgit_print_date(commit->date); |
30 | html("</td><td>"); | 30 | html("</td><td>"); |
31 | html_txt(info->author); | 31 | html_txt(info->author); |
32 | html("</td><td>"); | 32 | html("</td><td>"); |
33 | url = cgit_pageurl(cgit_query_repo, "commit", | 33 | url = cgit_pageurl(cgit_query_repo, "commit", |
34 | fmt("id=%s", sha1_to_hex(sha1))); | 34 | fmt("id=%s", sha1_to_hex(sha1))); |
35 | html_link_open(url, NULL, NULL); | 35 | html_link_open(url, NULL, NULL); |
36 | html_ntxt(cgit_max_msg_len, info->subject); | 36 | html_ntxt(cgit_max_msg_len, info->subject); |
37 | html_link_close(); | 37 | html_link_close(); |
38 | html("</td></tr>\n"); | 38 | html("</td></tr>\n"); |
39 | cgit_free_commitinfo(info); | 39 | cgit_free_commitinfo(info); |
40 | } else { | 40 | } else { |
41 | html("<tr><td>"); | 41 | html("<tr><td>"); |
42 | html_txt(buf); | 42 | html_txt(buf); |
43 | html("</td><td colspan='3'>"); | 43 | html("</td><td colspan='3'>"); |
44 | htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); | 44 | htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); |
45 | html("</td></tr>\n"); | 45 | html("</td></tr>\n"); |
46 | } | 46 | } |
47 | return 0; | 47 | return 0; |
48 | } | 48 | } |
49 | 49 | ||
50 | |||
51 | static void cgit_print_object_ref(struct object *obj) | ||
52 | { | ||
53 | char *page, *url; | ||
54 | |||
55 | if (obj->type == OBJ_COMMIT) | ||
56 | page = "commit"; | ||
57 | else if (obj->type == OBJ_TREE) | ||
58 | page = "tree"; | ||
59 | else | ||
60 | page = "view"; | ||
61 | |||
62 | url = cgit_pageurl(cgit_query_repo, page, | ||
63 | fmt("id=%s", sha1_to_hex(obj->sha1))); | ||
64 | html_link_open(url, NULL, NULL); | ||
65 | htmlf("%s %s", type_names[obj->type], | ||
66 | sha1_to_hex(obj->sha1)); | ||
67 | html_link_close(); | ||
68 | } | ||
69 | |||
50 | static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, | 70 | static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, |
51 | int flags, void *cb_data) | 71 | int flags, void *cb_data) |
52 | { | 72 | { |
53 | struct tag *tag; | 73 | struct tag *tag; |
54 | struct taginfo *info; | 74 | struct taginfo *info; |
55 | char buf[256], *page, *url; | 75 | struct object *obj; |
56 | 76 | char buf[256], *url; | |
77 | |||
57 | strncpy(buf, refname, sizeof(buf)); | 78 | strncpy(buf, refname, sizeof(buf)); |
58 | tag = lookup_tag(sha1); | 79 | obj = parse_object(sha1); |
59 | if (tag && !parse_tag(tag) && (info = cgit_parse_tag(tag))){ | 80 | if (!obj) |
81 | return 1; | ||
82 | if (obj->type == OBJ_TAG) { | ||
83 | tag = lookup_tag(sha1); | ||
84 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | ||
85 | return 2; | ||
60 | html("<tr><td>"); | 86 | html("<tr><td>"); |
61 | url = cgit_pageurl(cgit_query_repo, "view", | 87 | url = cgit_pageurl(cgit_query_repo, "view", |
62 | fmt("id=%s", sha1_to_hex(sha1))); | 88 | fmt("id=%s", sha1_to_hex(sha1))); |
63 | html_link_open(url, NULL, NULL); | 89 | html_link_open(url, NULL, NULL); |
64 | html_txt(buf); | 90 | html_txt(buf); |
65 | html_link_close(); | 91 | html_link_close(); |
66 | html("</td><td>"); | 92 | html("</td><td>"); |
67 | if (info->tagger_date > 0) | 93 | if (info->tagger_date > 0) |
68 | cgit_print_date(info->tagger_date); | 94 | cgit_print_date(info->tagger_date); |
69 | html("</td><td>"); | 95 | html("</td><td>"); |
70 | if (info->tagger) | 96 | if (info->tagger) |
71 | html(info->tagger); | 97 | html(info->tagger); |
72 | html("</td><td>"); | 98 | html("</td><td>"); |
73 | if (tag->tagged->type == OBJ_COMMIT) | 99 | cgit_print_object_ref(tag->tagged); |
74 | page = "commit"; | ||
75 | else if (tag->tagged->type == OBJ_TREE) | ||
76 | page = "tree"; | ||
77 | else | ||
78 | page = "view"; | ||
79 | |||
80 | url = cgit_pageurl(cgit_query_repo, page, | ||
81 | fmt("id=%s", sha1_to_hex(tag->tagged->sha1))); | ||
82 | html_link_open(url, NULL, NULL); | ||
83 | htmlf("%s %s", type_names[tag->tagged->type], | ||
84 | sha1_to_hex(tag->tagged->sha1)); | ||
85 | html_link_close(); | ||
86 | html("</td></tr>\n"); | 100 | html("</td></tr>\n"); |
87 | } else { | 101 | } else { |
88 | html("<tr><td>"); | 102 | html("<tr><td>"); |
89 | html_txt(buf); | 103 | html_txt(buf); |
90 | html("</td><td colspan='3'>"); | 104 | html("</td><td colspan='2'/><td>"); |
91 | htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); | 105 | cgit_print_object_ref(obj); |
92 | html("</td></tr>\n"); | 106 | html("</td></tr>\n"); |
93 | } | 107 | } |
94 | return 0; | 108 | return 0; |
95 | } | 109 | } |
96 | 110 | ||
97 | static void cgit_print_branches() | 111 | static void cgit_print_branches() |
98 | { | 112 | { |
99 | html("<tr class='nohover'><th class='left'>Branch</th>" | 113 | html("<tr class='nohover'><th class='left'>Branch</th>" |
100 | "<th class='left'>Updated</th>" | 114 | "<th class='left'>Updated</th>" |
101 | "<th class='left'>Author</th>" | 115 | "<th class='left'>Author</th>" |
102 | "<th class='left'>Head commit</th></tr>\n"); | 116 | "<th class='left'>Head commit</th></tr>\n"); |
103 | for_each_branch_ref(cgit_print_branch_cb, NULL); | 117 | for_each_branch_ref(cgit_print_branch_cb, NULL); |
104 | } | 118 | } |
105 | 119 | ||
106 | static void cgit_print_tags() | 120 | static void cgit_print_tags() |
107 | { | 121 | { |
108 | html("<tr class='nohover'><th class='left'>Tag</th>" | 122 | html("<tr class='nohover'><th class='left'>Tag</th>" |
109 | "<th class='left'>Created</th>" | 123 | "<th class='left'>Created</th>" |
110 | "<th class='left'>Author</th>" | 124 | "<th class='left'>Author</th>" |
111 | "<th class='left'>Reference</th></tr>\n"); | 125 | "<th class='left'>Reference</th></tr>\n"); |
112 | for_each_tag_ref(cgit_print_tag_cb, NULL); | 126 | for_each_tag_ref(cgit_print_tag_cb, NULL); |
113 | } | 127 | } |
114 | 128 | ||
115 | void cgit_print_summary() | 129 | void cgit_print_summary() |
116 | { | 130 | { |
117 | html("<h2>"); | 131 | html("<h2>"); |
118 | html_txt("Repo summary page"); | 132 | html_txt("Repo summary page"); |
119 | html("</h2>"); | 133 | html("</h2>"); |
120 | html("<table class='list nowrap'>"); | 134 | html("<table class='list nowrap'>"); |
121 | cgit_print_branches(); | 135 | cgit_print_branches(); |
122 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 136 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
123 | cgit_print_tags(); | 137 | cgit_print_tags(); |
124 | html("</table>"); | 138 | html("</table>"); |
125 | } | 139 | } |