-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | cgit.h | 20 | ||||
-rw-r--r-- | git.h | 699 | ||||
-rw-r--r-- | parsing.c | 6 | ||||
-rw-r--r-- | ui-diff.c | 5 | ||||
-rw-r--r-- | ui-summary.c | 2 | ||||
-rw-r--r-- | ui-tree.c | 24 | ||||
-rw-r--r-- | ui-view.c | 14 | ||||
-rw-r--r-- | xdiff.h | 105 |
9 files changed, 50 insertions, 837 deletions
@@ -2,34 +2,36 @@ CGIT_VERSION = 0.2 | |||
2 | 2 | ||
3 | prefix = /var/www/htdocs/cgit | 3 | prefix = /var/www/htdocs/cgit |
4 | gitsrc = ../git | 4 | gitsrc = ../git |
5 | 5 | ||
6 | SHA1_HEADER = <openssl/sha.h> | ||
7 | |||
6 | CACHE_ROOT = /var/cache/cgit | 8 | CACHE_ROOT = /var/cache/cgit |
7 | EXTLIBS = $(gitsrc)/libgit.a $(gitsrc)/xdiff/lib.a -lz -lcrypto | 9 | EXTLIBS = $(gitsrc)/libgit.a $(gitsrc)/xdiff/lib.a -lz -lcrypto |
8 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ | 10 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ |
9 | ui-summary.o ui-log.o ui-view.c ui-tree.c ui-commit.c ui-diff.o \ | 11 | ui-summary.o ui-log.o ui-view.o ui-tree.o ui-commit.o ui-diff.o \ |
10 | ui-snapshot.o | 12 | ui-snapshot.o |
11 | 13 | ||
12 | CFLAGS += -Wall | 14 | CFLAGS += -Wall |
13 | 15 | ||
14 | ifdef DEBUG | 16 | ifdef DEBUG |
15 | CFLAGS += -g | 17 | CFLAGS += -g |
16 | endif | 18 | endif |
17 | 19 | ||
20 | CFLAGS += -I$(gitsrc) -DSHA1_HEADER='$(SHA1_HEADER)' | ||
21 | |||
18 | all: cgit | 22 | all: cgit |
19 | 23 | ||
20 | install: all clean-cache | 24 | install: all clean-cache |
21 | mkdir -p $(prefix) | 25 | mkdir -p $(prefix) |
22 | install cgit $(prefix)/cgit.cgi | 26 | install cgit $(prefix)/cgit.cgi |
23 | install cgit.css $(prefix)/cgit.css | 27 | install cgit.css $(prefix)/cgit.css |
24 | 28 | ||
25 | cgit: cgit.c cgit.h git.h $(OBJECTS) $(gitsrc)/libgit.a | 29 | cgit: cgit.c cgit.h $(OBJECTS) $(gitsrc)/libgit.a |
26 | $(CC) $(CFLAGS) -DCGIT_VERSION='"$(CGIT_VERSION)"' cgit.c -o cgit \ | 30 | $(CC) $(CFLAGS) -DCGIT_VERSION='"$(CGIT_VERSION)"' cgit.c -o cgit \ |
27 | $(OBJECTS) $(EXTLIBS) | 31 | $(OBJECTS) $(EXTLIBS) |
28 | 32 | ||
29 | $(OBJECTS): cgit.h git.h | 33 | $(OBJECTS): cgit.h |
30 | |||
31 | ui-diff.o: xdiff.h | ||
32 | 34 | ||
33 | $(gitsrc)/libgit.a: | 35 | $(gitsrc)/libgit.a: |
34 | $(MAKE) -C $(gitsrc) | 36 | $(MAKE) -C $(gitsrc) |
35 | 37 | ||
@@ -1,11 +1,23 @@ | |||
1 | #ifndef CGIT_H | 1 | #ifndef CGIT_H |
2 | #define CGIT_H | 2 | #define CGIT_H |
3 | 3 | ||
4 | #include "git.h" | 4 | |
5 | #include <openssl/sha.h> | 5 | #include <git-compat-util.h> |
6 | #include <ctype.h> | 6 | #include <cache.h> |
7 | #include <sched.h> | 7 | #include <grep.h> |
8 | #include <object.h> | ||
9 | #include <tree.h> | ||
10 | #include <commit.h> | ||
11 | #include <tag.h> | ||
12 | #include <diff.h> | ||
13 | #include <diffcore.h> | ||
14 | #include <refs.h> | ||
15 | #include <revision.h> | ||
16 | #include <log-tree.h> | ||
17 | #include <archive.h> | ||
18 | #include <xdiff/xdiff.h> | ||
19 | |||
8 | 20 | ||
9 | typedef void (*configfn)(const char *name, const char *value); | 21 | typedef void (*configfn)(const char *name, const char *value); |
10 | 22 | ||
11 | struct cacheitem { | 23 | struct cacheitem { |
@@ -1,699 +0,0 @@ | |||
1 | #ifndef GIT_H | ||
2 | #define GIT_H | ||
3 | |||
4 | |||
5 | /* | ||
6 | * from git:git-compat-util.h | ||
7 | */ | ||
8 | |||
9 | |||
10 | #ifndef FLEX_ARRAY | ||
11 | #if defined(__GNUC__) && (__GNUC__ < 3) | ||
12 | #define FLEX_ARRAY 0 | ||
13 | #else | ||
14 | #define FLEX_ARRAY /* empty */ | ||
15 | #endif | ||
16 | #endif | ||
17 | |||
18 | |||
19 | #include <unistd.h> | ||
20 | #include <stdio.h> | ||
21 | #include <sys/stat.h> | ||
22 | #include <fcntl.h> | ||
23 | #include <stddef.h> | ||
24 | #include <stdlib.h> | ||
25 | #include <stdarg.h> | ||
26 | #include <string.h> | ||
27 | #include <errno.h> | ||
28 | #include <limits.h> | ||
29 | #include <sys/param.h> | ||
30 | #include <netinet/in.h> | ||
31 | #include <sys/types.h> | ||
32 | #include <dirent.h> | ||
33 | #include <time.h> | ||
34 | #include <regex.h> | ||
35 | |||
36 | /* On most systems <limits.h> would have given us this, but | ||
37 | * not on some systems (e.g. GNU/Hurd). | ||
38 | */ | ||
39 | #ifndef PATH_MAX | ||
40 | #define PATH_MAX 4096 | ||
41 | #endif | ||
42 | |||
43 | #ifdef __GNUC__ | ||
44 | #define NORETURN __attribute__((__noreturn__)) | ||
45 | #else | ||
46 | #define NORETURN | ||
47 | #ifndef __attribute__ | ||
48 | #define __attribute__(x) | ||
49 | #endif | ||
50 | #endif | ||
51 | |||
52 | |||
53 | extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); | ||
54 | |||
55 | |||
56 | static inline char* xstrdup(const char *str) | ||
57 | { | ||
58 | char *ret = strdup(str); | ||
59 | if (!ret) | ||
60 | die("Out of memory, strdup failed"); | ||
61 | return ret; | ||
62 | } | ||
63 | |||
64 | static inline void *xmalloc(size_t size) | ||
65 | { | ||
66 | void *ret = malloc(size); | ||
67 | if (!ret && !size) | ||
68 | ret = malloc(1); | ||
69 | if (!ret) | ||
70 | die("Out of memory, malloc failed"); | ||
71 | #ifdef XMALLOC_POISON | ||
72 | memset(ret, 0xA5, size); | ||
73 | #endif | ||
74 | return ret; | ||
75 | } | ||
76 | |||
77 | static inline void *xrealloc(void *ptr, size_t size) | ||
78 | { | ||
79 | void *ret = realloc(ptr, size); | ||
80 | if (!ret && !size) | ||
81 | ret = realloc(ptr, 1); | ||
82 | if (!ret) | ||
83 | die("Out of memory, realloc failed"); | ||
84 | return ret; | ||
85 | } | ||
86 | |||
87 | static inline void *xcalloc(size_t nmemb, size_t size) | ||
88 | { | ||
89 | void *ret = calloc(nmemb, size); | ||
90 | if (!ret && (!nmemb || !size)) | ||
91 | ret = calloc(1, 1); | ||
92 | if (!ret) | ||
93 | die("Out of memory, calloc failed"); | ||
94 | return ret; | ||
95 | } | ||
96 | |||
97 | static inline ssize_t xread(int fd, void *buf, size_t len) | ||
98 | { | ||
99 | ssize_t nr; | ||
100 | while (1) { | ||
101 | nr = read(fd, buf, len); | ||
102 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | ||
103 | continue; | ||
104 | return nr; | ||
105 | } | ||
106 | } | ||
107 | |||
108 | static inline ssize_t xwrite(int fd, const void *buf, size_t len) | ||
109 | { | ||
110 | ssize_t nr; | ||
111 | while (1) { | ||
112 | nr = write(fd, buf, len); | ||
113 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | ||
114 | continue; | ||
115 | return nr; | ||
116 | } | ||
117 | } | ||
118 | |||
119 | |||
120 | |||
121 | |||
122 | /* | ||
123 | * from git:cache.h | ||
124 | */ | ||
125 | |||
126 | |||
127 | enum 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 | |||
140 | /* Convert to/from hex/sha1 representation */ | ||
141 | #define MINIMUM_ABBREV 4 | ||
142 | #define DEFAULT_ABBREV 7 | ||
143 | |||
144 | extern const unsigned char null_sha1[20]; | ||
145 | |||
146 | extern int sha1_object_info(const unsigned char *, char *, unsigned long *); | ||
147 | |||
148 | extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size); | ||
149 | |||
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! */ | ||
153 | |||
154 | static inline int is_null_sha1(const unsigned char *sha1) | ||
155 | { | ||
156 | return !memcmp(sha1, null_sha1, 20); | ||
157 | } | ||
158 | static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2) | ||
159 | { | ||
160 | return memcmp(sha1, sha2, 20); | ||
161 | } | ||
162 | static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src) | ||
163 | { | ||
164 | memcpy(sha_dst, sha_src, 20); | ||
165 | } | ||
166 | static inline void hashclr(unsigned char *hash) | ||
167 | { | ||
168 | memset(hash, 0, 20); | ||
169 | } | ||
170 | |||
171 | |||
172 | /* | ||
173 | * from git:grep.h | ||
174 | */ | ||
175 | |||
176 | enum grep_pat_token { | ||
177 | GREP_PATTERN, | ||
178 | GREP_PATTERN_HEAD, | ||
179 | GREP_PATTERN_BODY, | ||
180 | GREP_AND, | ||
181 | GREP_OPEN_PAREN, | ||
182 | GREP_CLOSE_PAREN, | ||
183 | GREP_NOT, | ||
184 | GREP_OR, | ||
185 | }; | ||
186 | |||
187 | enum grep_context { | ||
188 | GREP_CONTEXT_HEAD, | ||
189 | GREP_CONTEXT_BODY, | ||
190 | }; | ||
191 | |||
192 | struct grep_pat { | ||
193 | struct grep_pat *next; | ||
194 | const char *origin; | ||
195 | int no; | ||
196 | enum grep_pat_token token; | ||
197 | const char *pattern; | ||
198 | regex_t regexp; | ||
199 | }; | ||
200 | |||
201 | enum grep_expr_node { | ||
202 | GREP_NODE_ATOM, | ||
203 | GREP_NODE_NOT, | ||
204 | GREP_NODE_AND, | ||
205 | GREP_NODE_OR, | ||
206 | }; | ||
207 | |||
208 | struct grep_opt { | ||
209 | struct grep_pat *pattern_list; | ||
210 | struct grep_pat **pattern_tail; | ||
211 | struct grep_expr *pattern_expression; | ||
212 | int prefix_length; | ||
213 | regex_t regexp; | ||
214 | unsigned linenum:1; | ||
215 | unsigned invert:1; | ||
216 | unsigned status_only:1; | ||
217 | unsigned name_only:1; | ||
218 | unsigned unmatch_name_only:1; | ||
219 | unsigned count:1; | ||
220 | unsigned word_regexp:1; | ||
221 | unsigned fixed:1; | ||
222 | unsigned all_match:1; | ||
223 | #define GREP_BINARY_DEFAULT 0 | ||
224 | #define GREP_BINARY_NOMATCH 1 | ||
225 | #define GREP_BINARY_TEXT 2 | ||
226 | unsigned binary:2; | ||
227 | unsigned extended:1; | ||
228 | unsigned relative:1; | ||
229 | unsigned pathname:1; | ||
230 | int regflags; | ||
231 | unsigned pre_context; | ||
232 | unsigned post_context; | ||
233 | }; | ||
234 | |||
235 | |||
236 | extern void compile_grep_patterns(struct grep_opt *opt); | ||
237 | extern void free_grep_patterns(struct grep_opt *opt); | ||
238 | |||
239 | |||
240 | /* | ||
241 | * from git:object.h | ||
242 | */ | ||
243 | |||
244 | extern const char *type_names[9]; | ||
245 | |||
246 | struct object_list { | ||
247 | struct object *item; | ||
248 | struct object_list *next; | ||
249 | }; | ||
250 | |||
251 | struct object_refs { | ||
252 | unsigned count; | ||
253 | struct object *base; | ||
254 | struct object *ref[FLEX_ARRAY]; /* more */ | ||
255 | }; | ||
256 | |||
257 | struct object_array { | ||
258 | unsigned int nr; | ||
259 | unsigned int alloc; | ||
260 | struct object_array_entry { | ||
261 | struct object *item; | ||
262 | const char *name; | ||
263 | } *objects; | ||
264 | }; | ||
265 | |||
266 | #define TYPE_BITS 3 | ||
267 | #define FLAG_BITS 27 | ||
268 | |||
269 | /* | ||
270 | * The object type is stored in 3 bits. | ||
271 | */ | ||
272 | struct object { | ||
273 | unsigned parsed : 1; | ||
274 | unsigned used : 1; | ||
275 | unsigned type : TYPE_BITS; | ||
276 | unsigned flags : FLAG_BITS; | ||
277 | unsigned char sha1[20]; | ||
278 | }; | ||
279 | |||
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 | |||
285 | /* | ||
286 | * from git:tree.h | ||
287 | */ | ||
288 | |||
289 | struct tree { | ||
290 | struct object object; | ||
291 | void *buffer; | ||
292 | unsigned long size; | ||
293 | }; | ||
294 | |||
295 | |||
296 | struct tree *lookup_tree(const unsigned char *sha1); | ||
297 | int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size); | ||
298 | int parse_tree(struct tree *tree); | ||
299 | struct tree *parse_tree_indirect(const unsigned char *sha1); | ||
300 | |||
301 | typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int); | ||
302 | |||
303 | extern int read_tree_recursive(struct tree *tree, | ||
304 | const char *base, int baselen, | ||
305 | int stage, const char **match, | ||
306 | read_tree_fn_t fn); | ||
307 | |||
308 | extern int read_tree(struct tree *tree, int stage, const char **paths); | ||
309 | |||
310 | |||
311 | /* from git:commit.h */ | ||
312 | |||
313 | struct commit_list { | ||
314 | struct commit *item; | ||
315 | struct commit_list *next; | ||
316 | }; | ||
317 | |||
318 | struct commit { | ||
319 | struct object object; | ||
320 | void *util; | ||
321 | unsigned long date; | ||
322 | struct commit_list *parents; | ||
323 | struct tree *tree; | ||
324 | char *buffer; | ||
325 | }; | ||
326 | |||
327 | |||
328 | struct commit *lookup_commit(const unsigned char *sha1); | ||
329 | struct commit *lookup_commit_reference(const unsigned char *sha1); | ||
330 | struct commit *lookup_commit_reference_gently(const unsigned char *sha1, | ||
331 | int quiet); | ||
332 | |||
333 | int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size); | ||
334 | int parse_commit(struct commit *item); | ||
335 | |||
336 | struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p); | ||
337 | struct commit_list * insert_by_date(struct commit *item, struct commit_list **list); | ||
338 | |||
339 | void free_commit_list(struct commit_list *list); | ||
340 | |||
341 | void sort_by_date(struct commit_list **list); | ||
342 | |||
343 | /* Commit formats */ | ||
344 | enum cmit_fmt { | ||
345 | CMIT_FMT_RAW, | ||
346 | CMIT_FMT_MEDIUM, | ||
347 | CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM, | ||
348 | CMIT_FMT_SHORT, | ||
349 | CMIT_FMT_FULL, | ||
350 | CMIT_FMT_FULLER, | ||
351 | CMIT_FMT_ONELINE, | ||
352 | CMIT_FMT_EMAIL, | ||
353 | |||
354 | CMIT_FMT_UNSPECIFIED, | ||
355 | }; | ||
356 | |||
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); | ||
358 | |||
359 | |||
360 | typedef void (*topo_sort_set_fn_t)(struct commit*, void *data); | ||
361 | typedef void* (*topo_sort_get_fn_t)(struct commit*); | ||
362 | |||
363 | |||
364 | |||
365 | /* | ||
366 | * from git:tag.h | ||
367 | */ | ||
368 | |||
369 | extern const char *tag_type; | ||
370 | |||
371 | struct tag { | ||
372 | struct object object; | ||
373 | struct object *tagged; | ||
374 | char *tag; | ||
375 | char *signature; /* not actually implemented */ | ||
376 | }; | ||
377 | |||
378 | extern struct tag *lookup_tag(const unsigned char *sha1); | ||
379 | extern int parse_tag_buffer(struct tag *item, void *data, unsigned long size); | ||
380 | extern int parse_tag(struct tag *item); | ||
381 | extern struct object *deref_tag(struct object *, const char *, int); | ||
382 | |||
383 | |||
384 | /* | ||
385 | * from git:diffcore.h | ||
386 | */ | ||
387 | |||
388 | struct diff_filespec { | ||
389 | unsigned char sha1[20]; | ||
390 | char *path; | ||
391 | void *data; | ||
392 | void *cnt_data; | ||
393 | unsigned long size; | ||
394 | int xfrm_flags; /* for use by the xfrm */ | ||
395 | unsigned short mode; /* file mode */ | ||
396 | unsigned sha1_valid : 1; /* if true, use sha1 and trust mode; | ||
397 | * if false, use the name and read from | ||
398 | * the filesystem. | ||
399 | */ | ||
400 | #define DIFF_FILE_VALID(spec) (((spec)->mode) != 0) | ||
401 | unsigned should_free : 1; /* data should be free()'ed */ | ||
402 | unsigned should_munmap : 1; /* data should be munmap()'ed */ | ||
403 | }; | ||
404 | |||
405 | struct diff_filepair { | ||
406 | struct diff_filespec *one; | ||
407 | struct diff_filespec *two; | ||
408 | unsigned short int score; | ||
409 | char status; /* M C R N D U (see Documentation/diff-format.txt) */ | ||
410 | unsigned source_stays : 1; /* all of R/C are copies */ | ||
411 | unsigned broken_pair : 1; | ||
412 | unsigned renamed_pair : 1; | ||
413 | }; | ||
414 | |||
415 | #define DIFF_PAIR_UNMERGED(p) \ | ||
416 | (!DIFF_FILE_VALID((p)->one) && !DIFF_FILE_VALID((p)->two)) | ||
417 | |||
418 | #define DIFF_PAIR_RENAME(p) ((p)->renamed_pair) | ||
419 | |||
420 | #define DIFF_PAIR_BROKEN(p) \ | ||
421 | ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \ | ||
422 | ((p)->broken_pair != 0) ) | ||
423 | |||
424 | #define DIFF_PAIR_TYPE_CHANGED(p) \ | ||
425 | ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode)) | ||
426 | |||
427 | #define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode) | ||
428 | |||
429 | extern void diff_free_filepair(struct diff_filepair *); | ||
430 | |||
431 | extern int diff_unmodified_pair(struct diff_filepair *); | ||
432 | |||
433 | struct diff_queue_struct { | ||
434 | struct diff_filepair **queue; | ||
435 | int alloc; | ||
436 | int nr; | ||
437 | }; | ||
438 | |||
439 | |||
440 | /* | ||
441 | * from git:diff.h | ||
442 | */ | ||
443 | |||
444 | |||
445 | struct rev_info; | ||
446 | struct diff_options; | ||
447 | struct diff_queue_struct; | ||
448 | |||
449 | typedef void (*change_fn_t)(struct diff_options *options, | ||
450 | unsigned old_mode, unsigned new_mode, | ||
451 | const unsigned char *old_sha1, | ||
452 | const unsigned char *new_sha1, | ||
453 | const char *base, const char *path); | ||
454 | |||
455 | typedef void (*add_remove_fn_t)(struct diff_options *options, | ||
456 | int addremove, unsigned mode, | ||
457 | const unsigned char *sha1, | ||
458 | const char *base, const char *path); | ||
459 | |||
460 | typedef void (*diff_format_fn_t)(struct diff_queue_struct *q, | ||
461 | struct diff_options *options, void *data); | ||
462 | |||
463 | #define DIFF_FORMAT_RAW 0x0001 | ||
464 | #define DIFF_FORMAT_DIFFSTAT0x0002 | ||
465 | #define DIFF_FORMAT_NUMSTAT0x0004 | ||
466 | #define DIFF_FORMAT_SUMMARY0x0008 | ||
467 | #define DIFF_FORMAT_PATCH0x0010 | ||
468 | |||
469 | /* These override all above */ | ||
470 | #define DIFF_FORMAT_NAME0x0100 | ||
471 | #define DIFF_FORMAT_NAME_STATUS0x0200 | ||
472 | #define DIFF_FORMAT_CHECKDIFF0x0400 | ||
473 | |||
474 | /* Same as output_format = 0 but we know that -s flag was given | ||
475 | * and we should not give default value to output_format. | ||
476 | */ | ||
477 | #define DIFF_FORMAT_NO_OUTPUT0x0800 | ||
478 | |||
479 | #define DIFF_FORMAT_CALLBACK0x1000 | ||
480 | |||
481 | struct diff_options { | ||
482 | const char *filter; | ||
483 | const char *orderfile; | ||
484 | const char *pickaxe; | ||
485 | const char *single_follow; | ||
486 | unsigned recursive:1, | ||
487 | tree_in_recursive:1, | ||
488 | binary:1, | ||
489 | text:1, | ||
490 | full_index:1, | ||
491 | silent_on_remove:1, | ||
492 | find_copies_harder:1, | ||
493 | color_diff:1, | ||
494 | color_diff_words:1; | ||
495 | int context; | ||
496 | int break_opt; | ||
497 | int detect_rename; | ||
498 | int line_termination; | ||
499 | int output_format; | ||
500 | int pickaxe_opts; | ||
501 | int rename_score; | ||
502 | int reverse_diff; | ||
503 | int rename_limit; | ||
504 | int setup; | ||
505 | int abbrev; | ||
506 | const char *msg_sep; | ||
507 | const char *stat_sep; | ||
508 | long xdl_opts; | ||
509 | |||
510 | int stat_width; | ||
511 | int stat_name_width; | ||
512 | |||
513 | int nr_paths; | ||
514 | const char **paths; | ||
515 | int *pathlens; | ||
516 | change_fn_t change; | ||
517 | add_remove_fn_t add_remove; | ||
518 | diff_format_fn_t format_callback; | ||
519 | void *format_callback_data; | ||
520 | }; | ||
521 | |||
522 | enum color_diff { | ||
523 | DIFF_RESET = 0, | ||
524 | DIFF_PLAIN = 1, | ||
525 | DIFF_METAINFO = 2, | ||
526 | DIFF_FRAGINFO = 3, | ||
527 | DIFF_FILE_OLD = 4, | ||
528 | DIFF_FILE_NEW = 5, | ||
529 | DIFF_COMMIT = 6, | ||
530 | DIFF_WHITESPACE = 7, | ||
531 | }; | ||
532 | |||
533 | |||
534 | extern int diff_tree_sha1(const unsigned char *old, const unsigned char *new, | ||
535 | const char *base, struct diff_options *opt); | ||
536 | |||
537 | extern int diff_root_tree_sha1(const unsigned char *new, const char *base, | ||
538 | struct diff_options *opt); | ||
539 | |||
540 | extern int git_diff_ui_config(const char *var, const char *value); | ||
541 | extern void diff_setup(struct diff_options *); | ||
542 | extern int diff_opt_parse(struct diff_options *, const char **, int); | ||
543 | extern int diff_setup_done(struct diff_options *); | ||
544 | |||
545 | |||
546 | extern void diffcore_std(struct diff_options *); | ||
547 | extern void diff_flush(struct diff_options*); | ||
548 | |||
549 | |||
550 | /* diff-raw status letters */ | ||
551 | #define DIFF_STATUS_ADDED 'A' | ||
552 | #define DIFF_STATUS_COPIED 'C' | ||
553 | #define DIFF_STATUS_DELETED 'D' | ||
554 | #define DIFF_STATUS_MODIFIED 'M' | ||
555 | #define DIFF_STATUS_RENAMED 'R' | ||
556 | #define DIFF_STATUS_TYPE_CHANGED'T' | ||
557 | #define DIFF_STATUS_UNKNOWN 'X' | ||
558 | #define DIFF_STATUS_UNMERGED 'U' | ||
559 | |||
560 | |||
561 | |||
562 | /* | ||
563 | * from git:refs.g | ||
564 | */ | ||
565 | |||
566 | typedef int each_ref_fn(const char *refname, const unsigned char *sha1, int flags, void *cb_data); | ||
567 | extern int head_ref(each_ref_fn, void *); | ||
568 | extern int for_each_ref(each_ref_fn, void *); | ||
569 | extern int for_each_tag_ref(each_ref_fn, void *); | ||
570 | extern int for_each_branch_ref(each_ref_fn, void *); | ||
571 | extern int for_each_remote_ref(each_ref_fn, void *); | ||
572 | |||
573 | |||
574 | |||
575 | /* | ||
576 | * from git:revision.h | ||
577 | */ | ||
578 | |||
579 | struct rev_info; | ||
580 | struct log_info; | ||
581 | |||
582 | typedef void (prune_fn_t)(struct rev_info *revs, struct commit *commit); | ||
583 | |||
584 | struct rev_info { | ||
585 | /* Starting list */ | ||
586 | struct commit_list *commits; | ||
587 | struct object_array pending; | ||
588 | |||
589 | /* Basic information */ | ||
590 | const char *prefix; | ||
591 | void *prune_data; | ||
592 | prune_fn_t *prune_fn; | ||
593 | |||
594 | /* Traversal flags */ | ||
595 | unsigned intdense:1, | ||
596 | no_merges:1, | ||
597 | no_walk:1, | ||
598 | remove_empty_trees:1, | ||
599 | simplify_history:1, | ||
600 | lifo:1, | ||
601 | topo_order:1, | ||
602 | tag_objects:1, | ||
603 | tree_objects:1, | ||
604 | blob_objects:1, | ||
605 | edge_hint:1, | ||
606 | limited:1, | ||
607 | unpacked:1, /* see also ignore_packed below */ | ||
608 | boundary:1, | ||
609 | parents:1; | ||
610 | |||
611 | /* Diff flags */ | ||
612 | unsigned intdiff:1, | ||
613 | full_diff:1, | ||
614 | show_root_diff:1, | ||
615 | no_commit_id:1, | ||
616 | verbose_header:1, | ||
617 | ignore_merges:1, | ||
618 | combine_merges:1, | ||
619 | dense_combined_merges:1, | ||
620 | always_show_header:1; | ||
621 | |||
622 | /* Format info */ | ||
623 | unsigned intshown_one:1, | ||
624 | abbrev_commit:1, | ||
625 | relative_date:1; | ||
626 | |||
627 | const char **ignore_packed; /* pretend objects in these are unpacked */ | ||
628 | int num_ignore_packed; | ||
629 | |||
630 | unsigned intabbrev; | ||
631 | enum cmit_fmtcommit_format; | ||
632 | struct log_info *loginfo; | ||
633 | int nr, total; | ||
634 | const char*mime_boundary; | ||
635 | const char*message_id; | ||
636 | const char*ref_message_id; | ||
637 | const char*add_signoff; | ||
638 | const char*extra_headers; | ||
639 | |||
640 | /* Filter by commit log message */ | ||
641 | struct grep_opt*grep_filter; | ||
642 | |||
643 | /* special limits */ | ||
644 | int max_count; | ||
645 | unsigned long max_age; | ||
646 | unsigned long min_age; | ||
647 | |||
648 | /* diff info for patches and for paths limiting */ | ||
649 | struct diff_options diffopt; | ||
650 | struct diff_options pruning; | ||
651 | |||
652 | topo_sort_set_fn_t topo_setter; | ||
653 | topo_sort_get_fn_t topo_getter; | ||
654 | }; | ||
655 | |||
656 | |||
657 | extern void init_revisions(struct rev_info *revs, const char *prefix); | ||
658 | extern int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def); | ||
659 | extern int handle_revision_arg(const char *arg, struct rev_info *revs,int flags,int cant_be_filename); | ||
660 | |||
661 | extern void prepare_revision_walk(struct rev_info *revs); | ||
662 | extern struct commit *get_revision(struct rev_info *revs); | ||
663 | |||
664 | |||
665 | |||
666 | /* from git:log-tree.h */ | ||
667 | |||
668 | int log_tree_commit(struct rev_info *, struct commit *); | ||
669 | |||
670 | |||
671 | |||
672 | /* from git:archive.h */ | ||
673 | |||
674 | struct archiver_args { | ||
675 | const char *base; | ||
676 | struct tree *tree; | ||
677 | const unsigned char *commit_sha1; | ||
678 | time_t time; | ||
679 | const char **pathspec; | ||
680 | unsigned int verbose : 1; | ||
681 | void *extra; | ||
682 | }; | ||
683 | |||
684 | typedef int (*write_archive_fn_t)(struct archiver_args *); | ||
685 | |||
686 | typedef void *(*parse_extra_args_fn_t)(int argc, const char **argv); | ||
687 | |||
688 | struct archiver { | ||
689 | const char *name; | ||
690 | struct archiver_args args; | ||
691 | write_archive_fn_t write_archive; | ||
692 | parse_extra_args_fn_t parse_extra; | ||
693 | }; | ||
694 | |||
695 | extern int write_tar_archive(struct archiver_args *); | ||
696 | extern int write_zip_archive(struct archiver_args *); | ||
697 | extern void *parse_extra_zip_args(int argc, const char **argv); | ||
698 | |||
699 | #endif /* GIT_H */ | ||
@@ -200,15 +200,15 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) | |||
200 | 200 | ||
201 | struct taginfo *cgit_parse_tag(struct tag *tag) | 201 | struct taginfo *cgit_parse_tag(struct tag *tag) |
202 | { | 202 | { |
203 | void *data; | 203 | void *data; |
204 | char type[20]; | 204 | enum object_type type; |
205 | unsigned long size; | 205 | unsigned long size; |
206 | char *p, *t; | 206 | char *p, *t; |
207 | struct taginfo *ret; | 207 | struct taginfo *ret; |
208 | 208 | ||
209 | data = read_sha1_file(tag->object.sha1, type, &size); | 209 | data = read_sha1_file(tag->object.sha1, &type, &size); |
210 | if (!data || strcmp(type, tag_type)) { | 210 | if (!data || type != OBJ_TAG) { |
211 | free(data); | 211 | free(data); |
212 | return 0; | 212 | return 0; |
213 | } | 213 | } |
214 | 214 | ||
@@ -6,9 +6,8 @@ | |||
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 | #include "xdiff.h" | ||
11 | 10 | ||
12 | char *diff_buffer; | 11 | char *diff_buffer; |
13 | int diff_buffer_size; | 12 | int diff_buffer_size; |
14 | 13 | ||
@@ -81,15 +80,15 @@ int diff_cb(void *priv_, mmbuffer_t *mb, int nbuf) | |||
81 | } | 80 | } |
82 | 81 | ||
83 | static int load_mmfile(mmfile_t *file, const unsigned char *sha1) | 82 | static int load_mmfile(mmfile_t *file, const unsigned char *sha1) |
84 | { | 83 | { |
85 | char type[20]; | 84 | enum object_type type; |
86 | 85 | ||
87 | if (is_null_sha1(sha1)) { | 86 | if (is_null_sha1(sha1)) { |
88 | file->ptr = (char *)""; | 87 | file->ptr = (char *)""; |
89 | file->size = 0; | 88 | file->size = 0; |
90 | } else { | 89 | } else { |
91 | file->ptr = read_sha1_file(sha1, type, &file->size); | 90 | file->ptr = read_sha1_file(sha1, &type, &file->size); |
92 | } | 91 | } |
93 | return 1; | 92 | return 1; |
94 | } | 93 | } |
95 | 94 | ||
diff --git a/ui-summary.c b/ui-summary.c index 42f4300..0a7869b 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -61,9 +61,9 @@ static void cgit_print_object_ref(struct object *obj) | |||
61 | 61 | ||
62 | url = cgit_pageurl(cgit_query_repo, page, | 62 | url = cgit_pageurl(cgit_query_repo, page, |
63 | fmt("id=%s", sha1_to_hex(obj->sha1))); | 63 | fmt("id=%s", sha1_to_hex(obj->sha1))); |
64 | html_link_open(url, NULL, NULL); | 64 | html_link_open(url, NULL, NULL); |
65 | htmlf("%s %s", type_names[obj->type], | 65 | htmlf("%s %s", typename(obj->type), |
66 | sha1_to_hex(obj->sha1)); | 66 | sha1_to_hex(obj->sha1)); |
67 | html_link_close(); | 67 | html_link_close(); |
68 | } | 68 | } |
69 | 69 | ||
@@ -13,39 +13,41 @@ static int print_entry(const unsigned char *sha1, const char *base, | |||
13 | int baselen, const char *pathname, unsigned int mode, | 13 | int baselen, const char *pathname, unsigned int mode, |
14 | int stage) | 14 | int stage) |
15 | { | 15 | { |
16 | char *name; | 16 | char *name; |
17 | char type[20]; | 17 | enum object_type type; |
18 | unsigned long size; | 18 | unsigned long size; |
19 | 19 | ||
20 | if (sha1_object_info(sha1, type, &size)) { | 20 | name = xstrdup(pathname); |
21 | cgit_print_error(fmt("Bad object name: %s", | 21 | type = sha1_object_info(sha1, &size); |
22 | sha1_to_hex(sha1))); | 22 | if (type == OBJ_BAD) { |
23 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", | ||
24 | name, | ||
25 | sha1_to_hex(sha1)); | ||
23 | return 0; | 26 | return 0; |
24 | } | 27 | } |
25 | name = xstrdup(pathname); | ||
26 | html("<tr><td class='filemode'>"); | 28 | html("<tr><td class='filemode'>"); |
27 | html_filemode(mode); | 29 | html_filemode(mode); |
28 | html("</td><td>"); | 30 | html("</td><td>"); |
29 | if (S_ISDIR(mode)) { | 31 | if (S_ISDIRLNK(mode)) { |
32 | htmlf("<div class='ls-dirlnk'>%s => submodule</div>", name); | ||
33 | } else if (S_ISDIR(mode)) { | ||
30 | html("<div class='ls-dir'><a href='"); | 34 | html("<div class='ls-dir'><a href='"); |
31 | html_attr(cgit_pageurl(cgit_query_repo, "tree", | 35 | html_attr(cgit_pageurl(cgit_query_repo, "tree", |
32 | fmt("id=%s&path=%s%s/", | 36 | fmt("id=%s&path=%s%s/", |
33 | sha1_to_hex(sha1), | 37 | sha1_to_hex(sha1), |
34 | cgit_query_path ? cgit_query_path : "", | 38 | cgit_query_path ? cgit_query_path : "", |
35 | pathname))); | 39 | pathname))); |
40 | htmlf("'>%s</a></div>", name); | ||
36 | } else { | 41 | } else { |
37 | html("<div class='ls-blob'><a href='"); | 42 | html("<div class='ls-blob'><a href='"); |
38 | html_attr(cgit_pageurl(cgit_query_repo, "view", | 43 | html_attr(cgit_pageurl(cgit_query_repo, "view", |
39 | fmt("id=%s&path=%s%s", sha1_to_hex(sha1), | 44 | fmt("id=%s&path=%s%s", sha1_to_hex(sha1), |
40 | cgit_query_path ? cgit_query_path : "", | 45 | cgit_query_path ? cgit_query_path : "", |
41 | pathname))); | 46 | pathname))); |
47 | htmlf("'>%s</a></div>", name); | ||
42 | } | 48 | } |
43 | html("'>"); | 49 | html("</div></td>"); |
44 | html_txt(name); | ||
45 | if (S_ISDIR(mode)) | ||
46 | html("/"); | ||
47 | html("</a></div></td>"); | ||
48 | htmlf("<td class='filesize'>%li</td>", size); | 50 | htmlf("<td class='filesize'>%li</td>", size); |
49 | html("</tr>\n"); | 51 | html("</tr>\n"); |
50 | free(name); | 52 | free(name); |
51 | return 0; | 53 | return 0; |
@@ -10,31 +10,33 @@ | |||
10 | 10 | ||
11 | void cgit_print_view(const char *hex) | 11 | void cgit_print_view(const char *hex) |
12 | { | 12 | { |
13 | unsigned char sha1[20]; | 13 | unsigned char sha1[20]; |
14 | char type[20]; | 14 | enum object_type type; |
15 | unsigned char *buf; | 15 | unsigned char *buf; |
16 | unsigned long size; | 16 | unsigned long size; |
17 | 17 | ||
18 | if (get_sha1_hex(hex, sha1)){ | 18 | if (get_sha1_hex(hex, sha1)){ |
19 | cgit_print_error(fmt("Bad hex value: %s", hex)); | 19 | cgit_print_error(fmt("Bad hex value: %s", hex)); |
20 | return; | 20 | return; |
21 | } | 21 | } |
22 | 22 | ||
23 | if (sha1_object_info(sha1, type, &size)){ | 23 | type = sha1_object_info(sha1, &size); |
24 | cgit_print_error("Bad object name"); | 24 | if (type == OBJ_BAD) { |
25 | cgit_print_error(fmt("Bad object name: %s", hex)); | ||
25 | return; | 26 | return; |
26 | } | 27 | } |
27 | 28 | ||
28 | buf = read_sha1_file(sha1, type, &size); | 29 | buf = read_sha1_file(sha1, &type, &size); |
29 | if (!buf) { | 30 | if (!buf) { |
30 | cgit_print_error("Error reading object"); | 31 | cgit_print_error(fmt("Error reading object %s", hex)); |
31 | return; | 32 | return; |
32 | } | 33 | } |
33 | 34 | ||
34 | buf[size] = '\0'; | 35 | buf[size] = '\0'; |
35 | html("<table class='list'>\n"); | 36 | html("<table class='list'>\n"); |
36 | htmlf("<tr class='nohover'><th class='left'>%s %s, %li bytes</th></tr>\n", type, hex, size); | 37 | htmlf("<tr class='nohover'><th class='left'>%s %s, %li bytes</th></tr>\n", |
38 | typename(type), hex, size); | ||
37 | html("<tr><td class='blob'>\n"); | 39 | html("<tr><td class='blob'>\n"); |
38 | html_txt(buf); | 40 | html_txt(buf); |
39 | html("\n</td></tr>\n"); | 41 | html("\n</td></tr>\n"); |
40 | html("</table>\n"); | 42 | html("</table>\n"); |
diff --git a/xdiff.h b/xdiff.h deleted file mode 100644 index fa409d5..0000000 --- a/xdiff.h +++ b/dev/null | |||
@@ -1,105 +0,0 @@ | |||
1 | /* | ||
2 | * LibXDiff by Davide Libenzi ( File Differential Library ) | ||
3 | * Copyright (C) 2003 Davide Libenzi | ||
4 | * | ||
5 | * This library is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU Lesser General Public | ||
7 | * License as published by the Free Software Foundation; either | ||
8 | * version 2.1 of the License, or (at your option) any later version. | ||
9 | * | ||
10 | * This library is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * Lesser General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Lesser General Public | ||
16 | * License along with this library; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | * | ||
19 | * Davide Libenzi <davidel@xmailserver.org> | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #if !defined(XDIFF_H) | ||
24 | #define XDIFF_H | ||
25 | |||
26 | #ifdef __cplusplus | ||
27 | extern "C" { | ||
28 | #endif /* #ifdef __cplusplus */ | ||
29 | |||
30 | |||
31 | #define XDF_NEED_MINIMAL (1 << 1) | ||
32 | #define XDF_IGNORE_WHITESPACE (1 << 2) | ||
33 | #define XDF_IGNORE_WHITESPACE_CHANGE (1 << 3) | ||
34 | #define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE) | ||
35 | |||
36 | #define XDL_PATCH_NORMAL '-' | ||
37 | #define XDL_PATCH_REVERSE '+' | ||
38 | #define XDL_PATCH_MODEMASK ((1 << 8) - 1) | ||
39 | #define XDL_PATCH_IGNOREBSPACE (1 << 8) | ||
40 | |||
41 | #define XDL_EMIT_FUNCNAMES (1 << 0) | ||
42 | #define XDL_EMIT_COMMON (1 << 1) | ||
43 | |||
44 | #define XDL_MMB_READONLY (1 << 0) | ||
45 | |||
46 | #define XDL_MMF_ATOMIC (1 << 0) | ||
47 | |||
48 | #define XDL_BDOP_INS 1 | ||
49 | #define XDL_BDOP_CPY 2 | ||
50 | #define XDL_BDOP_INSB 3 | ||
51 | |||
52 | #define XDL_MERGE_MINIMAL 0 | ||
53 | #define XDL_MERGE_EAGER 1 | ||
54 | #define XDL_MERGE_ZEALOUS 2 | ||
55 | |||
56 | typedef struct s_mmfile { | ||
57 | char *ptr; | ||
58 | long size; | ||
59 | } mmfile_t; | ||
60 | |||
61 | typedef struct s_mmbuffer { | ||
62 | char *ptr; | ||
63 | long size; | ||
64 | } mmbuffer_t; | ||
65 | |||
66 | typedef struct s_xpparam { | ||
67 | unsigned long flags; | ||
68 | } xpparam_t; | ||
69 | |||
70 | typedef struct s_xdemitcb { | ||
71 | void *priv; | ||
72 | int (*outf)(void *, mmbuffer_t *, int); | ||
73 | } xdemitcb_t; | ||
74 | |||
75 | typedef struct s_xdemitconf { | ||
76 | long ctxlen; | ||
77 | unsigned long flags; | ||
78 | } xdemitconf_t; | ||
79 | |||
80 | typedef struct s_bdiffparam { | ||
81 | long bsize; | ||
82 | } bdiffparam_t; | ||
83 | |||
84 | |||
85 | #define xdl_malloc(x) malloc(x) | ||
86 | #define xdl_free(ptr) free(ptr) | ||
87 | #define xdl_realloc(ptr,x) realloc(ptr,x) | ||
88 | |||
89 | void *xdl_mmfile_first(mmfile_t *mmf, long *size); | ||
90 | void *xdl_mmfile_next(mmfile_t *mmf, long *size); | ||
91 | long xdl_mmfile_size(mmfile_t *mmf); | ||
92 | |||
93 | int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, | ||
94 | xdemitconf_t const *xecfg, xdemitcb_t *ecb); | ||
95 | |||
96 | int xdl_merge(mmfile_t *orig, mmfile_t *mf1, const char *name1, | ||
97 | mmfile_t *mf2, const char *name2, | ||
98 | xpparam_t const *xpp, int level, mmbuffer_t *result); | ||
99 | |||
100 | #ifdef __cplusplus | ||
101 | } | ||
102 | #endif /* #ifdef __cplusplus */ | ||
103 | |||
104 | #endif /* #if !defined(XDIFF_H) */ | ||
105 | |||