summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c7
-rw-r--r--cgit.h2
-rw-r--r--git.h68
-rw-r--r--ui-log.c13
4 files changed, 83 insertions, 7 deletions
diff --git a/cgit.c b/cgit.c
index 277b849..fba97d7 100644
--- a/cgit.c
+++ b/cgit.c
@@ -3,54 +3,57 @@
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
11const char cgit_version[] = CGIT_VERSION; 11const char cgit_version[] = CGIT_VERSION;
12 12
13static void cgit_print_repo_page(struct cacheitem *item) 13static void cgit_print_repo_page(struct cacheitem *item)
14{ 14{
15 if (chdir(fmt("%s/%s", cgit_root, cgit_query_repo)) || 15 if (chdir(fmt("%s/%s", cgit_root, cgit_query_repo)) ||
16 cgit_read_config("info/cgit", cgit_repo_config_cb)) { 16 cgit_read_config("info/cgit", cgit_repo_config_cb)) {
17 char *title = fmt("%s - %s", cgit_root_title, "Bad request"); 17 char *title = fmt("%s - %s", cgit_root_title, "Bad request");
18 cgit_print_docstart(title, item); 18 cgit_print_docstart(title, item);
19 cgit_print_pageheader(title, 0); 19 cgit_print_pageheader(title, 0);
20 cgit_print_error(fmt("Unable to scan repository: %s", 20 cgit_print_error(fmt("Unable to scan repository: %s",
21 strerror(errno))); 21 strerror(errno)));
22 cgit_print_docend(); 22 cgit_print_docend();
23 return; 23 return;
24 } 24 }
25 setenv("GIT_DIR", fmt("%s/%s", cgit_root, cgit_query_repo), 1); 25 setenv("GIT_DIR", fmt("%s/%s", cgit_root, cgit_query_repo), 1);
26 char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc); 26 char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc);
27 int show_search = 0;
28 if (cgit_query_page && !strcmp(cgit_query_page, "log"))
29 show_search = 1;
27 cgit_print_docstart(title, item); 30 cgit_print_docstart(title, item);
28 cgit_print_pageheader(title, 0); 31 cgit_print_pageheader(title, show_search);
29 if (!cgit_query_page) { 32 if (!cgit_query_page) {
30 cgit_print_summary(); 33 cgit_print_summary();
31 } else if (!strcmp(cgit_query_page, "log")) { 34 } else if (!strcmp(cgit_query_page, "log")) {
32 cgit_print_log(cgit_query_head, cgit_query_ofs, 100); 35 cgit_print_log(cgit_query_head, cgit_query_ofs, 100, cgit_query_search);
33 } else if (!strcmp(cgit_query_page, "tree")) { 36 } else if (!strcmp(cgit_query_page, "tree")) {
34 cgit_print_tree(cgit_query_sha1); 37 cgit_print_tree(cgit_query_sha1);
35 } else if (!strcmp(cgit_query_page, "commit")) { 38 } else if (!strcmp(cgit_query_page, "commit")) {
36 cgit_print_commit(cgit_query_sha1); 39 cgit_print_commit(cgit_query_sha1);
37 } else if (!strcmp(cgit_query_page, "view")) { 40 } else if (!strcmp(cgit_query_page, "view")) {
38 cgit_print_view(cgit_query_sha1); 41 cgit_print_view(cgit_query_sha1);
39 } else if (!strcmp(cgit_query_page, "diff")) { 42 } else if (!strcmp(cgit_query_page, "diff")) {
40 cgit_print_diff(cgit_query_sha1, cgit_query_sha2); 43 cgit_print_diff(cgit_query_sha1, cgit_query_sha2);
41 } 44 }
42 cgit_print_docend(); 45 cgit_print_docend();
43} 46}
44 47
45static void cgit_fill_cache(struct cacheitem *item) 48static void cgit_fill_cache(struct cacheitem *item)
46{ 49{
47 static char buf[PATH_MAX]; 50 static char buf[PATH_MAX];
48 51
49 getcwd(buf, sizeof(buf)); 52 getcwd(buf, sizeof(buf));
50 htmlfd = item->fd; 53 htmlfd = item->fd;
51 item->st.st_mtime = time(NULL); 54 item->st.st_mtime = time(NULL);
52 if (cgit_query_repo) 55 if (cgit_query_repo)
53 cgit_print_repo_page(item); 56 cgit_print_repo_page(item);
54 else 57 else
55 cgit_print_repolist(item); 58 cgit_print_repolist(item);
56 chdir(buf); 59 chdir(buf);
diff --git a/cgit.h b/cgit.h
index e114a50..249650e 100644
--- a/cgit.h
+++ b/cgit.h
@@ -83,31 +83,31 @@ extern void html_filemode(unsigned short mode);
83 83
84extern int cgit_read_config(const char *filename, configfn fn); 84extern int cgit_read_config(const char *filename, configfn fn);
85extern int cgit_parse_query(char *txt, configfn fn); 85extern int cgit_parse_query(char *txt, configfn fn);
86extern struct commitinfo *cgit_parse_commit(struct commit *commit); 86extern struct commitinfo *cgit_parse_commit(struct commit *commit);
87 87
88extern void cache_prepare(struct cacheitem *item); 88extern void cache_prepare(struct cacheitem *item);
89extern int cache_lock(struct cacheitem *item); 89extern int cache_lock(struct cacheitem *item);
90extern int cache_unlock(struct cacheitem *item); 90extern int cache_unlock(struct cacheitem *item);
91extern int cache_cancel_lock(struct cacheitem *item); 91extern int cache_cancel_lock(struct cacheitem *item);
92extern int cache_exist(struct cacheitem *item); 92extern int cache_exist(struct cacheitem *item);
93extern int cache_expired(struct cacheitem *item); 93extern int cache_expired(struct cacheitem *item);
94 94
95extern char *cgit_repourl(const char *reponame); 95extern char *cgit_repourl(const char *reponame);
96extern char *cgit_pageurl(const char *reponame, const char *pagename, 96extern char *cgit_pageurl(const char *reponame, const char *pagename,
97 const char *query); 97 const char *query);
98 98
99extern void cgit_print_error(char *msg); 99extern void cgit_print_error(char *msg);
100extern void cgit_print_date(unsigned long secs); 100extern void cgit_print_date(unsigned long secs);
101extern void cgit_print_docstart(char *title, struct cacheitem *item); 101extern void cgit_print_docstart(char *title, struct cacheitem *item);
102extern void cgit_print_docend(); 102extern void cgit_print_docend();
103extern void cgit_print_pageheader(char *title, int show_search); 103extern void cgit_print_pageheader(char *title, int show_search);
104 104
105extern void cgit_print_repolist(struct cacheitem *item); 105extern void cgit_print_repolist(struct cacheitem *item);
106extern void cgit_print_summary(); 106extern void cgit_print_summary();
107extern void cgit_print_log(const char *tip, int ofs, int cnt); 107extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep);
108extern void cgit_print_view(const char *hex); 108extern void cgit_print_view(const char *hex);
109extern void cgit_print_tree(const char *hex); 109extern void cgit_print_tree(const char *hex);
110extern void cgit_print_commit(const char *hex); 110extern void cgit_print_commit(const char *hex);
111extern void cgit_print_diff(const char *old_hex, const char *new_hex); 111extern void cgit_print_diff(const char *old_hex, const char *new_hex);
112 112
113#endif /* CGIT_H */ 113#endif /* CGIT_H */
diff --git a/git.h b/git.h
index 922a167..b1e4828 100644
--- a/git.h
+++ b/git.h
@@ -10,49 +10,49 @@
10#ifndef FLEX_ARRAY 10#ifndef FLEX_ARRAY
11#if defined(__GNUC__) && (__GNUC__ < 3) 11#if defined(__GNUC__) && (__GNUC__ < 3)
12#define FLEX_ARRAY 0 12#define FLEX_ARRAY 0
13#else 13#else
14#define FLEX_ARRAY /* empty */ 14#define FLEX_ARRAY /* empty */
15#endif 15#endif
16#endif 16#endif
17 17
18 18
19#include <unistd.h> 19#include <unistd.h>
20#include <stdio.h> 20#include <stdio.h>
21#include <sys/stat.h> 21#include <sys/stat.h>
22#include <fcntl.h> 22#include <fcntl.h>
23#include <stddef.h> 23#include <stddef.h>
24#include <stdlib.h> 24#include <stdlib.h>
25#include <stdarg.h> 25#include <stdarg.h>
26#include <string.h> 26#include <string.h>
27#include <errno.h> 27#include <errno.h>
28#include <limits.h> 28#include <limits.h>
29#include <sys/param.h> 29#include <sys/param.h>
30#include <netinet/in.h> 30#include <netinet/in.h>
31#include <sys/types.h> 31#include <sys/types.h>
32#include <dirent.h> 32#include <dirent.h>
33#include <time.h> 33#include <time.h>
34 34#include <regex.h>
35 35
36/* On most systems <limits.h> would have given us this, but 36/* On most systems <limits.h> would have given us this, but
37 * not on some systems (e.g. GNU/Hurd). 37 * not on some systems (e.g. GNU/Hurd).
38 */ 38 */
39#ifndef PATH_MAX 39#ifndef PATH_MAX
40#define PATH_MAX 4096 40#define PATH_MAX 4096
41#endif 41#endif
42 42
43#ifdef __GNUC__ 43#ifdef __GNUC__
44#define NORETURN __attribute__((__noreturn__)) 44#define NORETURN __attribute__((__noreturn__))
45#else 45#else
46#define NORETURN 46#define NORETURN
47#ifndef __attribute__ 47#ifndef __attribute__
48#define __attribute__(x) 48#define __attribute__(x)
49#endif 49#endif
50#endif 50#endif
51 51
52 52
53extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); 53extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
54 54
55 55
56static inline char* xstrdup(const char *str) 56static inline char* xstrdup(const char *str)
57{ 57{
58 char *ret = strdup(str); 58 char *ret = strdup(str);
@@ -135,48 +135,114 @@ extern int sha1_object_info(const unsigned char *, char *, unsigned long *);
135extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size); 135extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size);
136 136
137extern int get_sha1(const char *str, unsigned char *sha1); 137extern int get_sha1(const char *str, unsigned char *sha1);
138extern int get_sha1_hex(const char *hex, unsigned char *sha1); 138extern int get_sha1_hex(const char *hex, unsigned char *sha1);
139 extern char *sha1_to_hex(const unsigned char *sha1);/* static buffer result! */ 139 extern char *sha1_to_hex(const unsigned char *sha1);/* static buffer result! */
140 140
141static inline int is_null_sha1(const unsigned char *sha1) 141static inline int is_null_sha1(const unsigned char *sha1)
142{ 142{
143 return !memcmp(sha1, null_sha1, 20); 143 return !memcmp(sha1, null_sha1, 20);
144} 144}
145static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2) 145static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
146{ 146{
147 return memcmp(sha1, sha2, 20); 147 return memcmp(sha1, sha2, 20);
148} 148}
149static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src) 149static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
150{ 150{
151 memcpy(sha_dst, sha_src, 20); 151 memcpy(sha_dst, sha_src, 20);
152} 152}
153static inline void hashclr(unsigned char *hash) 153static inline void hashclr(unsigned char *hash)
154{ 154{
155 memset(hash, 0, 20); 155 memset(hash, 0, 20);
156} 156}
157 157
158 158
159/*
160 * from git:grep.h
161 */
162
163enum grep_pat_token {
164 GREP_PATTERN,
165 GREP_PATTERN_HEAD,
166 GREP_PATTERN_BODY,
167 GREP_AND,
168 GREP_OPEN_PAREN,
169 GREP_CLOSE_PAREN,
170 GREP_NOT,
171 GREP_OR,
172};
173
174enum grep_context {
175 GREP_CONTEXT_HEAD,
176 GREP_CONTEXT_BODY,
177};
178
179struct grep_pat {
180 struct grep_pat *next;
181 const char *origin;
182 int no;
183 enum grep_pat_token token;
184 const char *pattern;
185 regex_t regexp;
186};
187
188enum grep_expr_node {
189 GREP_NODE_ATOM,
190 GREP_NODE_NOT,
191 GREP_NODE_AND,
192 GREP_NODE_OR,
193};
194
195struct grep_opt {
196 struct grep_pat *pattern_list;
197 struct grep_pat **pattern_tail;
198 struct grep_expr *pattern_expression;
199 int prefix_length;
200 regex_t regexp;
201 unsigned linenum:1;
202 unsigned invert:1;
203 unsigned status_only:1;
204 unsigned name_only:1;
205 unsigned unmatch_name_only:1;
206 unsigned count:1;
207 unsigned word_regexp:1;
208 unsigned fixed:1;
209 unsigned all_match:1;
210#define GREP_BINARY_DEFAULT 0
211#define GREP_BINARY_NOMATCH 1
212#define GREP_BINARY_TEXT 2
213 unsigned binary:2;
214 unsigned extended:1;
215 unsigned relative:1;
216 unsigned pathname:1;
217 int regflags;
218 unsigned pre_context;
219 unsigned post_context;
220};
221
222
223extern void compile_grep_patterns(struct grep_opt *opt);
224extern void free_grep_patterns(struct grep_opt *opt);
159 225
160 226
161/* 227/*
162 * from git:object.h 228 * from git:object.h
163 */ 229 */
164 230
165struct object_list { 231struct object_list {
166 struct object *item; 232 struct object *item;
167 struct object_list *next; 233 struct object_list *next;
168}; 234};
169 235
170struct object_refs { 236struct object_refs {
171 unsigned count; 237 unsigned count;
172 struct object *base; 238 struct object *base;
173 struct object *ref[FLEX_ARRAY]; /* more */ 239 struct object *ref[FLEX_ARRAY]; /* more */
174}; 240};
175 241
176struct object_array { 242struct object_array {
177 unsigned int nr; 243 unsigned int nr;
178 unsigned int alloc; 244 unsigned int alloc;
179 struct object_array_entry { 245 struct object_array_entry {
180 struct object *item; 246 struct object *item;
181 const char *name; 247 const char *name;
182 } *objects; 248 } *objects;
diff --git a/ui-log.c b/ui-log.c
index f3b16e7..c353b2a 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -11,61 +11,68 @@
11void print_commit(struct commit *commit) 11void print_commit(struct commit *commit)
12{ 12{
13 char buf[32]; 13 char buf[32];
14 struct commitinfo *info; 14 struct commitinfo *info;
15 struct tm *time; 15 struct tm *time;
16 16
17 info = cgit_parse_commit(commit); 17 info = cgit_parse_commit(commit);
18 time = gmtime(&commit->date); 18 time = gmtime(&commit->date);
19 html("<tr><td>"); 19 html("<tr><td>");
20 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time); 20 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time);
21 html_txt(buf); 21 html_txt(buf);
22 html("</td><td>"); 22 html("</td><td>");
23 char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1)); 23 char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1));
24 char *url = cgit_pageurl(cgit_query_repo, "commit", qry); 24 char *url = cgit_pageurl(cgit_query_repo, "commit", qry);
25 html_link_open(url, NULL, NULL); 25 html_link_open(url, NULL, NULL);
26 html_ntxt(80, info->subject); 26 html_ntxt(80, info->subject);
27 html_link_close(); 27 html_link_close();
28 html("</td><td>"); 28 html("</td><td>");
29 html_txt(info->author); 29 html_txt(info->author);
30 html("</td></tr>\n"); 30 html("</td></tr>\n");
31 cgit_free_commitinfo(info); 31 cgit_free_commitinfo(info);
32} 32}
33 33
34 34
35void cgit_print_log(const char *tip, int ofs, int cnt) 35void cgit_print_log(const char *tip, int ofs, int cnt, char *grep)
36{ 36{
37 struct rev_info rev; 37 struct rev_info rev;
38 struct commit *commit; 38 struct commit *commit;
39 const char *argv[2] = {NULL, tip}; 39 const char *argv[3] = {NULL, tip, NULL};
40 int argc = 2;
40 int i; 41 int i;
41 42
43 if (grep)
44 argv[argc++] = fmt("--grep=%s", grep);
42 init_revisions(&rev, NULL); 45 init_revisions(&rev, NULL);
43 rev.abbrev = DEFAULT_ABBREV; 46 rev.abbrev = DEFAULT_ABBREV;
44 rev.commit_format = CMIT_FMT_DEFAULT; 47 rev.commit_format = CMIT_FMT_DEFAULT;
45 rev.verbose_header = 1; 48 rev.verbose_header = 1;
46 rev.show_root_diff = 0; 49 rev.show_root_diff = 0;
47 setup_revisions(2, argv, &rev, NULL); 50 setup_revisions(argc, argv, &rev, NULL);
51 if (rev.grep_filter) {
52 rev.grep_filter->regflags |= REG_ICASE;
53 compile_grep_patterns(rev.grep_filter);
54 }
48 prepare_revision_walk(&rev); 55 prepare_revision_walk(&rev);
49 56
50 html("<h2>Log</h2>"); 57 html("<h2>Log</h2>");
51 html("<table class='list nowrap'>"); 58 html("<table class='list nowrap'>");
52 html("<tr><th class='left'>Date</th>" 59 html("<tr><th class='left'>Date</th>"
53 "<th class='left'>Message</th>" 60 "<th class='left'>Message</th>"
54 "<th class='left'>Author</th></tr>\n"); 61 "<th class='left'>Author</th></tr>\n");
55 62
56 if (ofs<0) 63 if (ofs<0)
57 ofs = 0; 64 ofs = 0;
58 65
59 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { 66 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
60 free(commit->buffer); 67 free(commit->buffer);
61 commit->buffer = NULL; 68 commit->buffer = NULL;
62 free_commit_list(commit->parents); 69 free_commit_list(commit->parents);
63 commit->parents = NULL; 70 commit->parents = NULL;
64 } 71 }
65 72
66 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { 73 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
67 print_commit(commit); 74 print_commit(commit);
68 free(commit->buffer); 75 free(commit->buffer);
69 commit->buffer = NULL; 76 commit->buffer = NULL;
70 free_commit_list(commit->parents); 77 free_commit_list(commit->parents);
71 commit->parents = NULL; 78 commit->parents = NULL;