author | Lars Hjemli <hjemli@gmail.com> | 2007-05-08 20:40:59 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-05-08 21:38:49 (UTC) |
commit | 61c3ca978c586c673aec618cb94210657278dda8 (patch) (unidiff) | |
tree | 7011987769e65ad0e7aa8b79f648357e9cd88c30 | |
parent | 66cacd053ba900c8eb3b7962027370c84a97f990 (diff) | |
download | cgit-61c3ca978c586c673aec618cb94210657278dda8.zip cgit-61c3ca978c586c673aec618cb94210657278dda8.tar.gz cgit-61c3ca978c586c673aec618cb94210657278dda8.tar.bz2 |
Update to libgit 1.5.2-rc2
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-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
@@ -1,42 +1,44 @@ | |||
1 | CGIT_VERSION = 0.2 | 1 | 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 | ||
36 | 38 | ||
37 | .PHONY: clean | 39 | .PHONY: clean |
38 | clean: | 40 | clean: |
39 | rm -f cgit *.o | 41 | rm -f cgit *.o |
40 | 42 | ||
41 | clean-cache: | 43 | clean-cache: |
42 | rm -rf $(CACHE_ROOT)/* | 44 | rm -rf $(CACHE_ROOT)/* |
@@ -1,154 +1,166 @@ | |||
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 { |
12 | char *name; | 24 | char *name; |
13 | struct stat st; | 25 | struct stat st; |
14 | int ttl; | 26 | int ttl; |
15 | int fd; | 27 | int fd; |
16 | }; | 28 | }; |
17 | 29 | ||
18 | struct repoinfo { | 30 | struct repoinfo { |
19 | char *url; | 31 | char *url; |
20 | char *name; | 32 | char *name; |
21 | char *path; | 33 | char *path; |
22 | char *desc; | 34 | char *desc; |
23 | char *owner; | 35 | char *owner; |
24 | int snapshots; | 36 | int snapshots; |
25 | }; | 37 | }; |
26 | 38 | ||
27 | struct repolist { | 39 | struct repolist { |
28 | int length; | 40 | int length; |
29 | int count; | 41 | int count; |
30 | struct repoinfo *repos; | 42 | struct repoinfo *repos; |
31 | }; | 43 | }; |
32 | 44 | ||
33 | struct commitinfo { | 45 | struct commitinfo { |
34 | struct commit *commit; | 46 | struct commit *commit; |
35 | char *author; | 47 | char *author; |
36 | char *author_email; | 48 | char *author_email; |
37 | unsigned long author_date; | 49 | unsigned long author_date; |
38 | char *committer; | 50 | char *committer; |
39 | char *committer_email; | 51 | char *committer_email; |
40 | unsigned long committer_date; | 52 | unsigned long committer_date; |
41 | char *subject; | 53 | char *subject; |
42 | char *msg; | 54 | char *msg; |
43 | }; | 55 | }; |
44 | 56 | ||
45 | struct taginfo { | 57 | struct taginfo { |
46 | char *tagger; | 58 | char *tagger; |
47 | char *tagger_email; | 59 | char *tagger_email; |
48 | int tagger_date; | 60 | int tagger_date; |
49 | char *msg; | 61 | char *msg; |
50 | }; | 62 | }; |
51 | 63 | ||
52 | extern const char cgit_version[]; | 64 | extern const char cgit_version[]; |
53 | 65 | ||
54 | extern struct repolist cgit_repolist; | 66 | extern struct repolist cgit_repolist; |
55 | extern struct repoinfo *cgit_repo; | 67 | extern struct repoinfo *cgit_repo; |
56 | 68 | ||
57 | extern char *cgit_root_title; | 69 | extern char *cgit_root_title; |
58 | extern char *cgit_css; | 70 | extern char *cgit_css; |
59 | extern char *cgit_logo; | 71 | extern char *cgit_logo; |
60 | extern char *cgit_logo_link; | 72 | extern char *cgit_logo_link; |
61 | extern char *cgit_virtual_root; | 73 | extern char *cgit_virtual_root; |
62 | extern char *cgit_cache_root; | 74 | extern char *cgit_cache_root; |
63 | 75 | ||
64 | extern int cgit_nocache; | 76 | extern int cgit_nocache; |
65 | extern int cgit_snapshots; | 77 | extern int cgit_snapshots; |
66 | extern int cgit_max_lock_attempts; | 78 | extern int cgit_max_lock_attempts; |
67 | extern int cgit_cache_root_ttl; | 79 | extern int cgit_cache_root_ttl; |
68 | extern int cgit_cache_repo_ttl; | 80 | extern int cgit_cache_repo_ttl; |
69 | extern int cgit_cache_dynamic_ttl; | 81 | extern int cgit_cache_dynamic_ttl; |
70 | extern int cgit_cache_static_ttl; | 82 | extern int cgit_cache_static_ttl; |
71 | extern int cgit_cache_max_create_time; | 83 | extern int cgit_cache_max_create_time; |
72 | 84 | ||
73 | extern int cgit_max_msg_len; | 85 | extern int cgit_max_msg_len; |
74 | 86 | ||
75 | extern char *cgit_repo_name; | 87 | extern char *cgit_repo_name; |
76 | extern char *cgit_repo_desc; | 88 | extern char *cgit_repo_desc; |
77 | extern char *cgit_repo_owner; | 89 | extern char *cgit_repo_owner; |
78 | 90 | ||
79 | extern int cgit_query_has_symref; | 91 | extern int cgit_query_has_symref; |
80 | extern int cgit_query_has_sha1; | 92 | extern int cgit_query_has_sha1; |
81 | 93 | ||
82 | extern char *cgit_querystring; | 94 | extern char *cgit_querystring; |
83 | extern char *cgit_query_repo; | 95 | extern char *cgit_query_repo; |
84 | extern char *cgit_query_page; | 96 | extern char *cgit_query_page; |
85 | extern char *cgit_query_search; | 97 | extern char *cgit_query_search; |
86 | extern char *cgit_query_head; | 98 | extern char *cgit_query_head; |
87 | extern char *cgit_query_sha1; | 99 | extern char *cgit_query_sha1; |
88 | extern char *cgit_query_sha2; | 100 | extern char *cgit_query_sha2; |
89 | extern char *cgit_query_path; | 101 | extern char *cgit_query_path; |
90 | extern char *cgit_query_name; | 102 | extern char *cgit_query_name; |
91 | extern int cgit_query_ofs; | 103 | extern int cgit_query_ofs; |
92 | 104 | ||
93 | extern int htmlfd; | 105 | extern int htmlfd; |
94 | 106 | ||
95 | extern void cgit_global_config_cb(const char *name, const char *value); | 107 | extern void cgit_global_config_cb(const char *name, const char *value); |
96 | extern void cgit_repo_config_cb(const char *name, const char *value); | 108 | extern void cgit_repo_config_cb(const char *name, const char *value); |
97 | extern void cgit_querystring_cb(const char *name, const char *value); | 109 | extern void cgit_querystring_cb(const char *name, const char *value); |
98 | 110 | ||
99 | extern int chk_zero(int result, char *msg); | 111 | extern int chk_zero(int result, char *msg); |
100 | extern int chk_positive(int result, char *msg); | 112 | extern int chk_positive(int result, char *msg); |
101 | 113 | ||
102 | extern int hextoint(char c); | 114 | extern int hextoint(char c); |
103 | 115 | ||
104 | extern void *cgit_free_commitinfo(struct commitinfo *info); | 116 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
105 | 117 | ||
106 | extern char *fmt(const char *format,...); | 118 | extern char *fmt(const char *format,...); |
107 | 119 | ||
108 | extern void html(const char *txt); | 120 | extern void html(const char *txt); |
109 | extern void htmlf(const char *format,...); | 121 | extern void htmlf(const char *format,...); |
110 | extern void html_txt(char *txt); | 122 | extern void html_txt(char *txt); |
111 | extern void html_ntxt(int len, char *txt); | 123 | extern void html_ntxt(int len, char *txt); |
112 | extern void html_attr(char *txt); | 124 | extern void html_attr(char *txt); |
113 | extern void html_hidden(char *name, char *value); | 125 | extern void html_hidden(char *name, char *value); |
114 | extern void html_link_open(char *url, char *title, char *class); | 126 | extern void html_link_open(char *url, char *title, char *class); |
115 | extern void html_link_close(void); | 127 | extern void html_link_close(void); |
116 | extern void html_filemode(unsigned short mode); | 128 | extern void html_filemode(unsigned short mode); |
117 | 129 | ||
118 | extern int cgit_read_config(const char *filename, configfn fn); | 130 | extern int cgit_read_config(const char *filename, configfn fn); |
119 | extern int cgit_parse_query(char *txt, configfn fn); | 131 | extern int cgit_parse_query(char *txt, configfn fn); |
120 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 132 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
121 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 133 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
122 | 134 | ||
123 | extern char *cache_safe_filename(const char *unsafe); | 135 | extern char *cache_safe_filename(const char *unsafe); |
124 | extern int cache_lock(struct cacheitem *item); | 136 | extern int cache_lock(struct cacheitem *item); |
125 | extern int cache_unlock(struct cacheitem *item); | 137 | extern int cache_unlock(struct cacheitem *item); |
126 | extern int cache_cancel_lock(struct cacheitem *item); | 138 | extern int cache_cancel_lock(struct cacheitem *item); |
127 | extern int cache_exist(struct cacheitem *item); | 139 | extern int cache_exist(struct cacheitem *item); |
128 | extern int cache_expired(struct cacheitem *item); | 140 | extern int cache_expired(struct cacheitem *item); |
129 | 141 | ||
130 | extern char *cgit_repourl(const char *reponame); | 142 | extern char *cgit_repourl(const char *reponame); |
131 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 143 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
132 | const char *query); | 144 | const char *query); |
133 | 145 | ||
134 | extern void cgit_print_error(char *msg); | 146 | extern void cgit_print_error(char *msg); |
135 | extern void cgit_print_date(unsigned long secs); | 147 | extern void cgit_print_date(unsigned long secs); |
136 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 148 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
137 | extern void cgit_print_docend(); | 149 | extern void cgit_print_docend(); |
138 | extern void cgit_print_pageheader(char *title, int show_search); | 150 | extern void cgit_print_pageheader(char *title, int show_search); |
139 | extern void cgit_print_snapshot_start(const char *mimetype, | 151 | extern void cgit_print_snapshot_start(const char *mimetype, |
140 | const char *filename, | 152 | const char *filename, |
141 | struct cacheitem *item); | 153 | struct cacheitem *item); |
142 | 154 | ||
143 | extern void cgit_print_repolist(struct cacheitem *item); | 155 | extern void cgit_print_repolist(struct cacheitem *item); |
144 | extern void cgit_print_summary(); | 156 | extern void cgit_print_summary(); |
145 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep); | 157 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep); |
146 | extern void cgit_print_view(const char *hex); | 158 | extern void cgit_print_view(const char *hex); |
147 | extern void cgit_print_tree(const char *hex, char *path); | 159 | extern void cgit_print_tree(const char *hex, char *path); |
148 | extern void cgit_print_commit(const char *hex); | 160 | extern void cgit_print_commit(const char *hex); |
149 | extern void cgit_print_diff(const char *old_hex, const char *new_hex); | 161 | extern void cgit_print_diff(const char *old_hex, const char *new_hex); |
150 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, | 162 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, |
151 | const char *format, const char *prefix, | 163 | const char *format, const char *prefix, |
152 | const char *filename); | 164 | const char *filename); |
153 | 165 | ||
154 | #endif /* CGIT_H */ | 166 | #endif /* CGIT_H */ |
@@ -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 */ | ||
@@ -1,245 +1,245 @@ | |||
1 | /* config.c: parsing of config files | 1 | /* config.c: parsing of config files |
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 | int next_char(FILE *f) | 11 | int next_char(FILE *f) |
12 | { | 12 | { |
13 | int c = fgetc(f); | 13 | int c = fgetc(f); |
14 | if (c=='\r') { | 14 | if (c=='\r') { |
15 | c = fgetc(f); | 15 | c = fgetc(f); |
16 | if (c!='\n') { | 16 | if (c!='\n') { |
17 | ungetc(c, f); | 17 | ungetc(c, f); |
18 | c = '\r'; | 18 | c = '\r'; |
19 | } | 19 | } |
20 | } | 20 | } |
21 | return c; | 21 | return c; |
22 | } | 22 | } |
23 | 23 | ||
24 | void skip_line(FILE *f) | 24 | void skip_line(FILE *f) |
25 | { | 25 | { |
26 | int c; | 26 | int c; |
27 | 27 | ||
28 | while((c=next_char(f)) && c!='\n' && c!=EOF) | 28 | while((c=next_char(f)) && c!='\n' && c!=EOF) |
29 | ; | 29 | ; |
30 | } | 30 | } |
31 | 31 | ||
32 | int read_config_line(FILE *f, char *line, const char **value, int bufsize) | 32 | int read_config_line(FILE *f, char *line, const char **value, int bufsize) |
33 | { | 33 | { |
34 | int i = 0, isname = 0; | 34 | int i = 0, isname = 0; |
35 | 35 | ||
36 | *value = NULL; | 36 | *value = NULL; |
37 | while(i<bufsize-1) { | 37 | while(i<bufsize-1) { |
38 | int c = next_char(f); | 38 | int c = next_char(f); |
39 | if (!isname && (c=='#' || c==';')) { | 39 | if (!isname && (c=='#' || c==';')) { |
40 | skip_line(f); | 40 | skip_line(f); |
41 | continue; | 41 | continue; |
42 | } | 42 | } |
43 | if (!isname && isspace(c)) | 43 | if (!isname && isspace(c)) |
44 | continue; | 44 | continue; |
45 | 45 | ||
46 | if (c=='=' && !*value) { | 46 | if (c=='=' && !*value) { |
47 | line[i] = 0; | 47 | line[i] = 0; |
48 | *value = &line[i+1]; | 48 | *value = &line[i+1]; |
49 | } else if (c=='\n' && !isname) { | 49 | } else if (c=='\n' && !isname) { |
50 | i = 0; | 50 | i = 0; |
51 | continue; | 51 | continue; |
52 | } else if (c=='\n' || c==EOF) { | 52 | } else if (c=='\n' || c==EOF) { |
53 | line[i] = 0; | 53 | line[i] = 0; |
54 | break; | 54 | break; |
55 | } else { | 55 | } else { |
56 | line[i]=c; | 56 | line[i]=c; |
57 | } | 57 | } |
58 | isname = 1; | 58 | isname = 1; |
59 | i++; | 59 | i++; |
60 | } | 60 | } |
61 | line[i+1] = 0; | 61 | line[i+1] = 0; |
62 | return i; | 62 | return i; |
63 | } | 63 | } |
64 | 64 | ||
65 | int cgit_read_config(const char *filename, configfn fn) | 65 | int cgit_read_config(const char *filename, configfn fn) |
66 | { | 66 | { |
67 | int ret = 0, len; | 67 | int ret = 0, len; |
68 | char line[256]; | 68 | char line[256]; |
69 | const char *value; | 69 | const char *value; |
70 | FILE *f = fopen(filename, "r"); | 70 | FILE *f = fopen(filename, "r"); |
71 | 71 | ||
72 | if (!f) | 72 | if (!f) |
73 | return -1; | 73 | return -1; |
74 | 74 | ||
75 | while((len = read_config_line(f, line, &value, sizeof(line))) > 0) | 75 | while((len = read_config_line(f, line, &value, sizeof(line))) > 0) |
76 | (*fn)(line, value); | 76 | (*fn)(line, value); |
77 | 77 | ||
78 | fclose(f); | 78 | fclose(f); |
79 | return ret; | 79 | return ret; |
80 | } | 80 | } |
81 | 81 | ||
82 | char *convert_query_hexchar(char *txt) | 82 | char *convert_query_hexchar(char *txt) |
83 | { | 83 | { |
84 | int d1, d2; | 84 | int d1, d2; |
85 | if (strlen(txt) < 3) { | 85 | if (strlen(txt) < 3) { |
86 | *txt = '\0'; | 86 | *txt = '\0'; |
87 | return txt-1; | 87 | return txt-1; |
88 | } | 88 | } |
89 | d1 = hextoint(*(txt+1)); | 89 | d1 = hextoint(*(txt+1)); |
90 | d2 = hextoint(*(txt+2)); | 90 | d2 = hextoint(*(txt+2)); |
91 | if (d1<0 || d2<0) { | 91 | if (d1<0 || d2<0) { |
92 | strcpy(txt, txt+3); | 92 | strcpy(txt, txt+3); |
93 | return txt-1; | 93 | return txt-1; |
94 | } else { | 94 | } else { |
95 | *txt = d1 * 16 + d2; | 95 | *txt = d1 * 16 + d2; |
96 | strcpy(txt+1, txt+3); | 96 | strcpy(txt+1, txt+3); |
97 | return txt; | 97 | return txt; |
98 | } | 98 | } |
99 | } | 99 | } |
100 | 100 | ||
101 | int cgit_parse_query(char *txt, configfn fn) | 101 | int cgit_parse_query(char *txt, configfn fn) |
102 | { | 102 | { |
103 | char *t, *value = NULL, c; | 103 | char *t, *value = NULL, c; |
104 | 104 | ||
105 | if (!txt) | 105 | if (!txt) |
106 | return 0; | 106 | return 0; |
107 | 107 | ||
108 | t = txt = xstrdup(txt); | 108 | t = txt = xstrdup(txt); |
109 | 109 | ||
110 | while((c=*t) != '\0') { | 110 | while((c=*t) != '\0') { |
111 | if (c=='=') { | 111 | if (c=='=') { |
112 | *t = '\0'; | 112 | *t = '\0'; |
113 | value = t+1; | 113 | value = t+1; |
114 | } else if (c=='+') { | 114 | } else if (c=='+') { |
115 | *t = ' '; | 115 | *t = ' '; |
116 | } else if (c=='%') { | 116 | } else if (c=='%') { |
117 | t = convert_query_hexchar(t); | 117 | t = convert_query_hexchar(t); |
118 | } else if (c=='&') { | 118 | } else if (c=='&') { |
119 | *t = '\0'; | 119 | *t = '\0'; |
120 | (*fn)(txt, value); | 120 | (*fn)(txt, value); |
121 | txt = t+1; | 121 | txt = t+1; |
122 | value = NULL; | 122 | value = NULL; |
123 | } | 123 | } |
124 | t++; | 124 | t++; |
125 | } | 125 | } |
126 | if (t!=txt) | 126 | if (t!=txt) |
127 | (*fn)(txt, value); | 127 | (*fn)(txt, value); |
128 | return 0; | 128 | return 0; |
129 | } | 129 | } |
130 | 130 | ||
131 | char *substr(const char *head, const char *tail) | 131 | char *substr(const char *head, const char *tail) |
132 | { | 132 | { |
133 | char *buf; | 133 | char *buf; |
134 | 134 | ||
135 | buf = xmalloc(tail - head + 1); | 135 | buf = xmalloc(tail - head + 1); |
136 | strncpy(buf, head, tail - head); | 136 | strncpy(buf, head, tail - head); |
137 | buf[tail - head] = '\0'; | 137 | buf[tail - head] = '\0'; |
138 | return buf; | 138 | return buf; |
139 | } | 139 | } |
140 | 140 | ||
141 | struct commitinfo *cgit_parse_commit(struct commit *commit) | 141 | struct commitinfo *cgit_parse_commit(struct commit *commit) |
142 | { | 142 | { |
143 | struct commitinfo *ret; | 143 | struct commitinfo *ret; |
144 | char *p = commit->buffer, *t = commit->buffer; | 144 | char *p = commit->buffer, *t = commit->buffer; |
145 | 145 | ||
146 | ret = xmalloc(sizeof(*ret)); | 146 | ret = xmalloc(sizeof(*ret)); |
147 | ret->commit = commit; | 147 | ret->commit = commit; |
148 | ret->author = NULL; | 148 | ret->author = NULL; |
149 | ret->author_email = NULL; | 149 | ret->author_email = NULL; |
150 | ret->committer = NULL; | 150 | ret->committer = NULL; |
151 | ret->committer_email = NULL; | 151 | ret->committer_email = NULL; |
152 | ret->subject = NULL; | 152 | ret->subject = NULL; |
153 | ret->msg = NULL; | 153 | ret->msg = NULL; |
154 | 154 | ||
155 | if (strncmp(p, "tree ", 5)) | 155 | if (strncmp(p, "tree ", 5)) |
156 | die("Bad commit: %s", sha1_to_hex(commit->object.sha1)); | 156 | die("Bad commit: %s", sha1_to_hex(commit->object.sha1)); |
157 | else | 157 | else |
158 | p += 46; // "tree " + hex[40] + "\n" | 158 | p += 46; // "tree " + hex[40] + "\n" |
159 | 159 | ||
160 | while (!strncmp(p, "parent ", 7)) | 160 | while (!strncmp(p, "parent ", 7)) |
161 | p += 48; // "parent " + hex[40] + "\n" | 161 | p += 48; // "parent " + hex[40] + "\n" |
162 | 162 | ||
163 | if (!strncmp(p, "author ", 7)) { | 163 | if (!strncmp(p, "author ", 7)) { |
164 | p += 7; | 164 | p += 7; |
165 | t = strchr(p, '<') - 1; | 165 | t = strchr(p, '<') - 1; |
166 | ret->author = substr(p, t); | 166 | ret->author = substr(p, t); |
167 | p = t; | 167 | p = t; |
168 | t = strchr(t, '>') + 1; | 168 | t = strchr(t, '>') + 1; |
169 | ret->author_email = substr(p, t); | 169 | ret->author_email = substr(p, t); |
170 | ret->author_date = atol(++t); | 170 | ret->author_date = atol(++t); |
171 | p = strchr(t, '\n') + 1; | 171 | p = strchr(t, '\n') + 1; |
172 | } | 172 | } |
173 | 173 | ||
174 | if (!strncmp(p, "committer ", 9)) { | 174 | if (!strncmp(p, "committer ", 9)) { |
175 | p += 9; | 175 | p += 9; |
176 | t = strchr(p, '<') - 1; | 176 | t = strchr(p, '<') - 1; |
177 | ret->committer = substr(p, t); | 177 | ret->committer = substr(p, t); |
178 | p = t; | 178 | p = t; |
179 | t = strchr(t, '>') + 1; | 179 | t = strchr(t, '>') + 1; |
180 | ret->committer_email = substr(p, t); | 180 | ret->committer_email = substr(p, t); |
181 | ret->committer_date = atol(++t); | 181 | ret->committer_date = atol(++t); |
182 | p = strchr(t, '\n') + 1; | 182 | p = strchr(t, '\n') + 1; |
183 | } | 183 | } |
184 | 184 | ||
185 | while (*p == '\n') | 185 | while (*p == '\n') |
186 | p = strchr(p, '\n') + 1; | 186 | p = strchr(p, '\n') + 1; |
187 | 187 | ||
188 | t = strchr(p, '\n'); | 188 | t = strchr(p, '\n'); |
189 | if (t && *t) { | 189 | if (t && *t) { |
190 | ret->subject = substr(p, t); | 190 | ret->subject = substr(p, t); |
191 | p = t + 1; | 191 | p = t + 1; |
192 | 192 | ||
193 | while (*p == '\n') | 193 | while (*p == '\n') |
194 | p = strchr(p, '\n') + 1; | 194 | p = strchr(p, '\n') + 1; |
195 | ret->msg = p; | 195 | ret->msg = p; |
196 | } | 196 | } |
197 | return ret; | 197 | return ret; |
198 | } | 198 | } |
199 | 199 | ||
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 | ||
215 | ret = xmalloc(sizeof(*ret)); | 215 | ret = xmalloc(sizeof(*ret)); |
216 | ret->tagger = NULL; | 216 | ret->tagger = NULL; |
217 | ret->tagger_email = NULL; | 217 | ret->tagger_email = NULL; |
218 | ret->tagger_date = 0; | 218 | ret->tagger_date = 0; |
219 | ret->msg = NULL; | 219 | ret->msg = NULL; |
220 | 220 | ||
221 | p = data; | 221 | p = data; |
222 | 222 | ||
223 | while (p && *p) { | 223 | while (p && *p) { |
224 | if (*p == '\n') | 224 | if (*p == '\n') |
225 | break; | 225 | break; |
226 | 226 | ||
227 | if (!strncmp(p, "tagger ", 7)) { | 227 | if (!strncmp(p, "tagger ", 7)) { |
228 | p += 7; | 228 | p += 7; |
229 | t = strchr(p, '<') - 1; | 229 | t = strchr(p, '<') - 1; |
230 | ret->tagger = substr(p, t); | 230 | ret->tagger = substr(p, t); |
231 | p = t; | 231 | p = t; |
232 | t = strchr(t, '>') + 1; | 232 | t = strchr(t, '>') + 1; |
233 | ret->tagger_email = substr(p, t); | 233 | ret->tagger_email = substr(p, t); |
234 | ret->tagger_date = atol(++t); | 234 | ret->tagger_date = atol(++t); |
235 | } | 235 | } |
236 | p = strchr(p, '\n') + 1; | 236 | p = strchr(p, '\n') + 1; |
237 | } | 237 | } |
238 | 238 | ||
239 | while (p && (*p == '\n')) | 239 | while (p && (*p == '\n')) |
240 | p = strchr(p, '\n') + 1; | 240 | p = strchr(p, '\n') + 1; |
241 | if (p && *p) | 241 | if (p && *p) |
242 | ret->msg = xstrdup(p); | 242 | ret->msg = xstrdup(p); |
243 | free(data); | 243 | free(data); |
244 | return ret; | 244 | return ret; |
245 | } | 245 | } |
@@ -1,130 +1,129 @@ | |||
1 | /* ui-diff.c: show diff between two blobs | 1 | /* ui-diff.c: show diff between two blobs |
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 | #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 | ||
15 | 14 | ||
16 | /* | 15 | /* |
17 | * print a single line returned from xdiff | 16 | * print a single line returned from xdiff |
18 | */ | 17 | */ |
19 | static void print_line(char *line, int len) | 18 | static void print_line(char *line, int len) |
20 | { | 19 | { |
21 | char *class = "ctx"; | 20 | char *class = "ctx"; |
22 | char c = line[len-1]; | 21 | char c = line[len-1]; |
23 | 22 | ||
24 | if (line[0] == '+') | 23 | if (line[0] == '+') |
25 | class = "add"; | 24 | class = "add"; |
26 | else if (line[0] == '-') | 25 | else if (line[0] == '-') |
27 | class = "del"; | 26 | class = "del"; |
28 | else if (line[0] == '@') | 27 | else if (line[0] == '@') |
29 | class = "hunk"; | 28 | class = "hunk"; |
30 | 29 | ||
31 | htmlf("<div class='%s'>", class); | 30 | htmlf("<div class='%s'>", class); |
32 | line[len-1] = '\0'; | 31 | line[len-1] = '\0'; |
33 | html_txt(line); | 32 | html_txt(line); |
34 | html("</div>"); | 33 | html("</div>"); |
35 | line[len-1] = c; | 34 | line[len-1] = c; |
36 | } | 35 | } |
37 | 36 | ||
38 | /* | 37 | /* |
39 | * Receive diff-buffers from xdiff and concatenate them as | 38 | * Receive diff-buffers from xdiff and concatenate them as |
40 | * needed across multiple callbacks. | 39 | * needed across multiple callbacks. |
41 | * | 40 | * |
42 | * This is basically a copy of xdiff-interface.c/xdiff_outf(), | 41 | * This is basically a copy of xdiff-interface.c/xdiff_outf(), |
43 | * ripped from git and modified to use globals instead of | 42 | * ripped from git and modified to use globals instead of |
44 | * a special callback-struct. | 43 | * a special callback-struct. |
45 | */ | 44 | */ |
46 | int diff_cb(void *priv_, mmbuffer_t *mb, int nbuf) | 45 | int diff_cb(void *priv_, mmbuffer_t *mb, int nbuf) |
47 | { | 46 | { |
48 | int i; | 47 | int i; |
49 | 48 | ||
50 | for (i = 0; i < nbuf; i++) { | 49 | for (i = 0; i < nbuf; i++) { |
51 | if (mb[i].ptr[mb[i].size-1] != '\n') { | 50 | if (mb[i].ptr[mb[i].size-1] != '\n') { |
52 | /* Incomplete line */ | 51 | /* Incomplete line */ |
53 | diff_buffer = xrealloc(diff_buffer, | 52 | diff_buffer = xrealloc(diff_buffer, |
54 | diff_buffer_size + mb[i].size); | 53 | diff_buffer_size + mb[i].size); |
55 | memcpy(diff_buffer + diff_buffer_size, | 54 | memcpy(diff_buffer + diff_buffer_size, |
56 | mb[i].ptr, mb[i].size); | 55 | mb[i].ptr, mb[i].size); |
57 | diff_buffer_size += mb[i].size; | 56 | diff_buffer_size += mb[i].size; |
58 | continue; | 57 | continue; |
59 | } | 58 | } |
60 | 59 | ||
61 | /* we have a complete line */ | 60 | /* we have a complete line */ |
62 | if (!diff_buffer) { | 61 | if (!diff_buffer) { |
63 | print_line(mb[i].ptr, mb[i].size); | 62 | print_line(mb[i].ptr, mb[i].size); |
64 | continue; | 63 | continue; |
65 | } | 64 | } |
66 | diff_buffer = xrealloc(diff_buffer, | 65 | diff_buffer = xrealloc(diff_buffer, |
67 | diff_buffer_size + mb[i].size); | 66 | diff_buffer_size + mb[i].size); |
68 | memcpy(diff_buffer + diff_buffer_size, mb[i].ptr, mb[i].size); | 67 | memcpy(diff_buffer + diff_buffer_size, mb[i].ptr, mb[i].size); |
69 | print_line(diff_buffer, diff_buffer_size + mb[i].size); | 68 | print_line(diff_buffer, diff_buffer_size + mb[i].size); |
70 | free(diff_buffer); | 69 | free(diff_buffer); |
71 | diff_buffer = NULL; | 70 | diff_buffer = NULL; |
72 | diff_buffer_size = 0; | 71 | diff_buffer_size = 0; |
73 | } | 72 | } |
74 | if (diff_buffer) { | 73 | if (diff_buffer) { |
75 | print_line(diff_buffer, diff_buffer_size); | 74 | print_line(diff_buffer, diff_buffer_size); |
76 | free(diff_buffer); | 75 | free(diff_buffer); |
77 | diff_buffer = NULL; | 76 | diff_buffer = NULL; |
78 | diff_buffer_size = 0; | 77 | diff_buffer_size = 0; |
79 | } | 78 | } |
80 | return 0; | 79 | return 0; |
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 | ||
96 | static void run_diff(const unsigned char *sha1, const unsigned char *sha2) | 95 | static void run_diff(const unsigned char *sha1, const unsigned char *sha2) |
97 | { | 96 | { |
98 | mmfile_t file1, file2; | 97 | mmfile_t file1, file2; |
99 | xpparam_t diff_params; | 98 | xpparam_t diff_params; |
100 | xdemitconf_t emit_params; | 99 | xdemitconf_t emit_params; |
101 | xdemitcb_t emit_cb; | 100 | xdemitcb_t emit_cb; |
102 | 101 | ||
103 | if (!load_mmfile(&file1, sha1) || !load_mmfile(&file2, sha2)) { | 102 | if (!load_mmfile(&file1, sha1) || !load_mmfile(&file2, sha2)) { |
104 | cgit_print_error("Unable to load files for diff"); | 103 | cgit_print_error("Unable to load files for diff"); |
105 | return; | 104 | return; |
106 | } | 105 | } |
107 | 106 | ||
108 | diff_params.flags = XDF_NEED_MINIMAL; | 107 | diff_params.flags = XDF_NEED_MINIMAL; |
109 | 108 | ||
110 | emit_params.ctxlen = 3; | 109 | emit_params.ctxlen = 3; |
111 | emit_params.flags = XDL_EMIT_FUNCNAMES; | 110 | emit_params.flags = XDL_EMIT_FUNCNAMES; |
112 | 111 | ||
113 | emit_cb.outf = diff_cb; | 112 | emit_cb.outf = diff_cb; |
114 | 113 | ||
115 | xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); | 114 | xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); |
116 | } | 115 | } |
117 | 116 | ||
118 | 117 | ||
119 | 118 | ||
120 | void cgit_print_diff(const char *old_hex, const char *new_hex) | 119 | void cgit_print_diff(const char *old_hex, const char *new_hex) |
121 | { | 120 | { |
122 | unsigned char sha1[20], sha2[20]; | 121 | unsigned char sha1[20], sha2[20]; |
123 | 122 | ||
124 | get_sha1(old_hex, sha1); | 123 | get_sha1(old_hex, sha1); |
125 | get_sha1(new_hex, sha2); | 124 | get_sha1(new_hex, sha2); |
126 | 125 | ||
127 | html("<table class='diff'><tr><td>"); | 126 | html("<table class='diff'><tr><td>"); |
128 | run_diff(sha1, sha2); | 127 | run_diff(sha1, sha2); |
129 | html("</td></tr></table>"); | 128 | html("</td></tr></table>"); |
130 | } | 129 | } |
diff --git a/ui-summary.c b/ui-summary.c index 42f4300..0a7869b 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -1,141 +1,141 @@ | |||
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 | 50 | ||
51 | static void cgit_print_object_ref(struct object *obj) | 51 | static void cgit_print_object_ref(struct object *obj) |
52 | { | 52 | { |
53 | char *page, *url; | 53 | char *page, *url; |
54 | 54 | ||
55 | if (obj->type == OBJ_COMMIT) | 55 | if (obj->type == OBJ_COMMIT) |
56 | page = "commit"; | 56 | page = "commit"; |
57 | else if (obj->type == OBJ_TREE) | 57 | else if (obj->type == OBJ_TREE) |
58 | page = "tree"; | 58 | page = "tree"; |
59 | else | 59 | else |
60 | page = "view"; | 60 | page = "view"; |
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 | ||
70 | 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, |
71 | int flags, void *cb_data) | 71 | int flags, void *cb_data) |
72 | { | 72 | { |
73 | struct tag *tag; | 73 | struct tag *tag; |
74 | struct taginfo *info; | 74 | struct taginfo *info; |
75 | struct object *obj; | 75 | struct object *obj; |
76 | char buf[256], *url; | 76 | char buf[256], *url; |
77 | 77 | ||
78 | strncpy(buf, refname, sizeof(buf)); | 78 | strncpy(buf, refname, sizeof(buf)); |
79 | obj = parse_object(sha1); | 79 | obj = parse_object(sha1); |
80 | if (!obj) | 80 | if (!obj) |
81 | return 1; | 81 | return 1; |
82 | if (obj->type == OBJ_TAG) { | 82 | if (obj->type == OBJ_TAG) { |
83 | tag = lookup_tag(sha1); | 83 | tag = lookup_tag(sha1); |
84 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 84 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
85 | return 2; | 85 | return 2; |
86 | html("<tr><td>"); | 86 | html("<tr><td>"); |
87 | url = cgit_pageurl(cgit_query_repo, "view", | 87 | url = cgit_pageurl(cgit_query_repo, "view", |
88 | fmt("id=%s", sha1_to_hex(sha1))); | 88 | fmt("id=%s", sha1_to_hex(sha1))); |
89 | html_link_open(url, NULL, NULL); | 89 | html_link_open(url, NULL, NULL); |
90 | html_txt(buf); | 90 | html_txt(buf); |
91 | html_link_close(); | 91 | html_link_close(); |
92 | html("</td><td>"); | 92 | html("</td><td>"); |
93 | if (info->tagger_date > 0) | 93 | if (info->tagger_date > 0) |
94 | cgit_print_date(info->tagger_date); | 94 | cgit_print_date(info->tagger_date); |
95 | html("</td><td>"); | 95 | html("</td><td>"); |
96 | if (info->tagger) | 96 | if (info->tagger) |
97 | html(info->tagger); | 97 | html(info->tagger); |
98 | html("</td><td>"); | 98 | html("</td><td>"); |
99 | cgit_print_object_ref(tag->tagged); | 99 | cgit_print_object_ref(tag->tagged); |
100 | html("</td></tr>\n"); | 100 | html("</td></tr>\n"); |
101 | } else { | 101 | } else { |
102 | html("<tr><td>"); | 102 | html("<tr><td>"); |
103 | html_txt(buf); | 103 | html_txt(buf); |
104 | html("</td><td colspan='2'/><td>"); | 104 | html("</td><td colspan='2'/><td>"); |
105 | cgit_print_object_ref(obj); | 105 | cgit_print_object_ref(obj); |
106 | html("</td></tr>\n"); | 106 | html("</td></tr>\n"); |
107 | } | 107 | } |
108 | return 0; | 108 | return 0; |
109 | } | 109 | } |
110 | 110 | ||
111 | static void cgit_print_branches() | 111 | static void cgit_print_branches() |
112 | { | 112 | { |
113 | html("<tr class='nohover'><th class='left'>Branch</th>" | 113 | html("<tr class='nohover'><th class='left'>Branch</th>" |
114 | "<th class='left'>Updated</th>" | 114 | "<th class='left'>Updated</th>" |
115 | "<th class='left'>Author</th>" | 115 | "<th class='left'>Author</th>" |
116 | "<th class='left'>Head commit</th></tr>\n"); | 116 | "<th class='left'>Head commit</th></tr>\n"); |
117 | for_each_branch_ref(cgit_print_branch_cb, NULL); | 117 | for_each_branch_ref(cgit_print_branch_cb, NULL); |
118 | } | 118 | } |
119 | 119 | ||
120 | static void cgit_print_tags() | 120 | static void cgit_print_tags() |
121 | { | 121 | { |
122 | html("<tr class='nohover'><th class='left'>Tag</th>" | 122 | html("<tr class='nohover'><th class='left'>Tag</th>" |
123 | "<th class='left'>Created</th>" | 123 | "<th class='left'>Created</th>" |
124 | "<th class='left'>Author</th>" | 124 | "<th class='left'>Author</th>" |
125 | "<th class='left'>Reference</th></tr>\n"); | 125 | "<th class='left'>Reference</th></tr>\n"); |
126 | for_each_tag_ref(cgit_print_tag_cb, NULL); | 126 | for_each_tag_ref(cgit_print_tag_cb, NULL); |
127 | } | 127 | } |
128 | 128 | ||
129 | void cgit_print_summary() | 129 | void cgit_print_summary() |
130 | { | 130 | { |
131 | html("<h2>"); | 131 | html("<h2>"); |
132 | html(cgit_repo->name); | 132 | html(cgit_repo->name); |
133 | html("</h2><h3>"); | 133 | html("</h2><h3>"); |
134 | html(cgit_repo->desc); | 134 | html(cgit_repo->desc); |
135 | html("</h3>"); | 135 | html("</h3>"); |
136 | html("<table class='list nowrap'>"); | 136 | html("<table class='list nowrap'>"); |
137 | cgit_print_branches(); | 137 | cgit_print_branches(); |
138 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 138 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
139 | cgit_print_tags(); | 139 | cgit_print_tags(); |
140 | html("</table>"); | 140 | html("</table>"); |
141 | } | 141 | } |
@@ -1,78 +1,80 @@ | |||
1 | /* ui-tree.c: functions for tree output | 1 | /* ui-tree.c: functions for tree output |
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 | 11 | ||
12 | static int print_entry(const unsigned char *sha1, const char *base, | 12 | 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; |
52 | } | 54 | } |
53 | 55 | ||
54 | void cgit_print_tree(const char *hex, char *path) | 56 | void cgit_print_tree(const char *hex, char *path) |
55 | { | 57 | { |
56 | struct tree *tree; | 58 | struct tree *tree; |
57 | unsigned char sha1[20]; | 59 | unsigned char sha1[20]; |
58 | 60 | ||
59 | if (get_sha1_hex(hex, sha1)) { | 61 | if (get_sha1_hex(hex, sha1)) { |
60 | cgit_print_error(fmt("Invalid object id: %s", hex)); | 62 | cgit_print_error(fmt("Invalid object id: %s", hex)); |
61 | return; | 63 | return; |
62 | } | 64 | } |
63 | tree = parse_tree_indirect(sha1); | 65 | tree = parse_tree_indirect(sha1); |
64 | if (!tree) { | 66 | if (!tree) { |
65 | cgit_print_error(fmt("Not a tree object: %s", hex)); | 67 | cgit_print_error(fmt("Not a tree object: %s", hex)); |
66 | return; | 68 | return; |
67 | } | 69 | } |
68 | 70 | ||
69 | html_txt(path); | 71 | html_txt(path); |
70 | html("<table class='list'>\n"); | 72 | html("<table class='list'>\n"); |
71 | html("<tr class='nohover'>"); | 73 | html("<tr class='nohover'>"); |
72 | html("<th class='left'>Mode</th>"); | 74 | html("<th class='left'>Mode</th>"); |
73 | html("<th class='left'>Name</th>"); | 75 | html("<th class='left'>Name</th>"); |
74 | html("<th class='right'>Size</th>"); | 76 | html("<th class='right'>Size</th>"); |
75 | html("</tr>\n"); | 77 | html("</tr>\n"); |
76 | read_tree_recursive(tree, "", 0, 1, NULL, print_entry); | 78 | read_tree_recursive(tree, "", 0, 1, NULL, print_entry); |
77 | html("</table>\n"); | 79 | html("</table>\n"); |
78 | } | 80 | } |
@@ -1,41 +1,43 @@ | |||
1 | /* ui-view.c: functions to output _any_ object, given it's sha1 | 1 | /* ui-view.c: functions to output _any_ object, given it's sha1 |
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 | 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"); |
41 | } | 43 | } |
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 | |||