summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ui-log.c5
-rw-r--r--ui-repolist.c2
2 files changed, 7 insertions, 0 deletions
diff --git a/ui-log.c b/ui-log.c
index 9b2ffb6..746f40b 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -1,136 +1,141 @@
1/* ui-log.c: functions for log output 1/* ui-log.c: functions for log 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#include "html.h" 10#include "html.h"
11#include "ui-shared.h" 11#include "ui-shared.h"
12 12
13int files, add_lines, rem_lines; 13int files, add_lines, rem_lines;
14 14
15void count_lines(char *line, int size) 15void count_lines(char *line, int size)
16{ 16{
17 if (size <= 0) 17 if (size <= 0)
18 return; 18 return;
19 19
20 if (line[0] == '+') 20 if (line[0] == '+')
21 add_lines++; 21 add_lines++;
22 22
23 else if (line[0] == '-') 23 else if (line[0] == '-')
24 rem_lines++; 24 rem_lines++;
25} 25}
26 26
27void inspect_files(struct diff_filepair *pair) 27void inspect_files(struct diff_filepair *pair)
28{ 28{
29 files++; 29 files++;
30 if (ctx.repo->enable_log_linecount) 30 if (ctx.repo->enable_log_linecount)
31 cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); 31 cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines);
32} 32}
33 33
34void print_commit(struct commit *commit) 34void print_commit(struct commit *commit)
35{ 35{
36 struct commitinfo *info; 36 struct commitinfo *info;
37 char *tmp;
37 38
38 info = cgit_parse_commit(commit); 39 info = cgit_parse_commit(commit);
39 html("<tr><td>"); 40 html("<tr><td>");
41 tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1));
42 tmp = cgit_pageurl(ctx.repo->url, "commit", tmp);
43 html_link_open(tmp, NULL, NULL);
40 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); 44 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
45 html_link_close();
41 html("</td><td>"); 46 html("</td><td>");
42 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, 47 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
43 sha1_to_hex(commit->object.sha1)); 48 sha1_to_hex(commit->object.sha1));
44 html("</td><td>"); 49 html("</td><td>");
45 html_txt(info->author); 50 html_txt(info->author);
46 if (ctx.repo->enable_log_filecount) { 51 if (ctx.repo->enable_log_filecount) {
47 files = 0; 52 files = 0;
48 add_lines = 0; 53 add_lines = 0;
49 rem_lines = 0; 54 rem_lines = 0;
50 cgit_diff_commit(commit, inspect_files); 55 cgit_diff_commit(commit, inspect_files);
51 html("</td><td>"); 56 html("</td><td>");
52 htmlf("%d", files); 57 htmlf("%d", files);
53 if (ctx.repo->enable_log_linecount) { 58 if (ctx.repo->enable_log_linecount) {
54 html("</td><td>"); 59 html("</td><td>");
55 htmlf("-%d/+%d", rem_lines, add_lines); 60 htmlf("-%d/+%d", rem_lines, add_lines);
56 } 61 }
57 } 62 }
58 html("</td></tr>\n"); 63 html("</td></tr>\n");
59 cgit_free_commitinfo(info); 64 cgit_free_commitinfo(info);
60} 65}
61 66
62 67
63void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, 68void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
64 char *path, int pager) 69 char *path, int pager)
65{ 70{
66 struct rev_info rev; 71 struct rev_info rev;
67 struct commit *commit; 72 struct commit *commit;
68 const char *argv[] = {NULL, tip, NULL, NULL, NULL}; 73 const char *argv[] = {NULL, tip, NULL, NULL, NULL};
69 int argc = 2; 74 int argc = 2;
70 int i, columns = 3; 75 int i, columns = 3;
71 76
72 if (!tip) 77 if (!tip)
73 argv[1] = ctx.qry.head; 78 argv[1] = ctx.qry.head;
74 79
75 if (grep && pattern && (!strcmp(grep, "grep") || 80 if (grep && pattern && (!strcmp(grep, "grep") ||
76 !strcmp(grep, "author") || 81 !strcmp(grep, "author") ||
77 !strcmp(grep, "committer"))) 82 !strcmp(grep, "committer")))
78 argv[argc++] = fmt("--%s=%s", grep, pattern); 83 argv[argc++] = fmt("--%s=%s", grep, pattern);
79 84
80 if (path) { 85 if (path) {
81 argv[argc++] = "--"; 86 argv[argc++] = "--";
82 argv[argc++] = path; 87 argv[argc++] = path;
83 } 88 }
84 init_revisions(&rev, NULL); 89 init_revisions(&rev, NULL);
85 rev.abbrev = DEFAULT_ABBREV; 90 rev.abbrev = DEFAULT_ABBREV;
86 rev.commit_format = CMIT_FMT_DEFAULT; 91 rev.commit_format = CMIT_FMT_DEFAULT;
87 rev.verbose_header = 1; 92 rev.verbose_header = 1;
88 rev.show_root_diff = 0; 93 rev.show_root_diff = 0;
89 setup_revisions(argc, argv, &rev, NULL); 94 setup_revisions(argc, argv, &rev, NULL);
90 if (rev.grep_filter) { 95 if (rev.grep_filter) {
91 rev.grep_filter->regflags |= REG_ICASE; 96 rev.grep_filter->regflags |= REG_ICASE;
92 compile_grep_patterns(rev.grep_filter); 97 compile_grep_patterns(rev.grep_filter);
93 } 98 }
94 prepare_revision_walk(&rev); 99 prepare_revision_walk(&rev);
95 100
96 if (pager) 101 if (pager)
97 html("<table class='list nowrap'>"); 102 html("<table class='list nowrap'>");
98 103
99 html("<tr class='nohover'><th class='left'>Age</th>" 104 html("<tr class='nohover'><th class='left'>Age</th>"
100 "<th class='left'>Commit message</th>" 105 "<th class='left'>Commit message</th>"
101 "<th class='left'>Author</th>"); 106 "<th class='left'>Author</th>");
102 if (ctx.repo->enable_log_filecount) { 107 if (ctx.repo->enable_log_filecount) {
103 html("<th class='left'>Files</th>"); 108 html("<th class='left'>Files</th>");
104 columns++; 109 columns++;
105 if (ctx.repo->enable_log_linecount) { 110 if (ctx.repo->enable_log_linecount) {
106 html("<th class='left'>Lines</th>"); 111 html("<th class='left'>Lines</th>");
107 columns++; 112 columns++;
108 } 113 }
109 } 114 }
110 html("</tr>\n"); 115 html("</tr>\n");
111 116
112 if (ofs<0) 117 if (ofs<0)
113 ofs = 0; 118 ofs = 0;
114 119
115 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { 120 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
116 free(commit->buffer); 121 free(commit->buffer);
117 commit->buffer = NULL; 122 commit->buffer = NULL;
118 free_commit_list(commit->parents); 123 free_commit_list(commit->parents);
119 commit->parents = NULL; 124 commit->parents = NULL;
120 } 125 }
121 126
122 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { 127 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
123 print_commit(commit); 128 print_commit(commit);
124 free(commit->buffer); 129 free(commit->buffer);
125 commit->buffer = NULL; 130 commit->buffer = NULL;
126 free_commit_list(commit->parents); 131 free_commit_list(commit->parents);
127 commit->parents = NULL; 132 commit->parents = NULL;
128 } 133 }
129 if (pager) { 134 if (pager) {
130 htmlf("</table><div class='pager'>", 135 htmlf("</table><div class='pager'>",
131 columns); 136 columns);
132 if (ofs > 0) { 137 if (ofs > 0) {
133 cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, 138 cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
134 ctx.qry.sha1, ctx.qry.path, 139 ctx.qry.sha1, ctx.qry.path,
135 ofs - cnt, ctx.qry.grep, 140 ofs - cnt, ctx.qry.grep,
136 ctx.qry.search); 141 ctx.qry.search);
diff --git a/ui-repolist.c b/ui-repolist.c
index 7a7e95a..98009c0 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -21,119 +21,121 @@ time_t read_agefile(char *path)
21 return -1; 21 return -1;
22 fgets(buf, sizeof(buf), f); 22 fgets(buf, sizeof(buf), f);
23 fclose(f); 23 fclose(f);
24 if (parse_date(buf, buf2, sizeof(buf2))) 24 if (parse_date(buf, buf2, sizeof(buf2)))
25 return strtoul(buf2, NULL, 10); 25 return strtoul(buf2, NULL, 10);
26 else 26 else
27 return 0; 27 return 0;
28} 28}
29 29
30static void print_modtime(struct cgit_repo *repo) 30static void print_modtime(struct cgit_repo *repo)
31{ 31{
32 char *path; 32 char *path;
33 struct stat s; 33 struct stat s;
34 34
35 path = fmt("%s/%s", repo->path, ctx.cfg.agefile); 35 path = fmt("%s/%s", repo->path, ctx.cfg.agefile);
36 if (stat(path, &s) == 0) { 36 if (stat(path, &s) == 0) {
37 cgit_print_age(read_agefile(path), -1, NULL); 37 cgit_print_age(read_agefile(path), -1, NULL);
38 return; 38 return;
39 } 39 }
40 40
41 path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); 41 path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch);
42 if (stat(path, &s) != 0) 42 if (stat(path, &s) != 0)
43 return; 43 return;
44 cgit_print_age(s.st_mtime, -1, NULL); 44 cgit_print_age(s.st_mtime, -1, NULL);
45} 45}
46 46
47int is_match(struct cgit_repo *repo) 47int is_match(struct cgit_repo *repo)
48{ 48{
49 if (!ctx.qry.search) 49 if (!ctx.qry.search)
50 return 1; 50 return 1;
51 if (repo->url && strcasestr(repo->url, ctx.qry.search)) 51 if (repo->url && strcasestr(repo->url, ctx.qry.search))
52 return 1; 52 return 1;
53 if (repo->name && strcasestr(repo->name, ctx.qry.search)) 53 if (repo->name && strcasestr(repo->name, ctx.qry.search))
54 return 1; 54 return 1;
55 if (repo->desc && strcasestr(repo->desc, ctx.qry.search)) 55 if (repo->desc && strcasestr(repo->desc, ctx.qry.search))
56 return 1; 56 return 1;
57 if (repo->owner && strcasestr(repo->owner, ctx.qry.search)) 57 if (repo->owner && strcasestr(repo->owner, ctx.qry.search))
58 return 1; 58 return 1;
59 return 0; 59 return 0;
60} 60}
61 61
62void print_header(int columns) 62void print_header(int columns)
63{ 63{
64 if (ctx.cfg.index_header) { 64 if (ctx.cfg.index_header) {
65 htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>", 65 htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>",
66 columns); 66 columns);
67 html_include(ctx.cfg.index_header); 67 html_include(ctx.cfg.index_header);
68 html("</td></tr>"); 68 html("</td></tr>");
69 } 69 }
70 html("<tr class='nohover'>" 70 html("<tr class='nohover'>"
71 "<th class='left'>Name</th>" 71 "<th class='left'>Name</th>"
72 "<th class='left'>Description</th>" 72 "<th class='left'>Description</th>"
73 "<th class='left'>Owner</th>" 73 "<th class='left'>Owner</th>"
74 "<th class='left'>Idle</th>"); 74 "<th class='left'>Idle</th>");
75 if (ctx.cfg.enable_index_links) 75 if (ctx.cfg.enable_index_links)
76 html("<th class='left'>Links</th>"); 76 html("<th class='left'>Links</th>");
77 html("</tr>\n"); 77 html("</tr>\n");
78} 78}
79 79
80void cgit_print_repolist() 80void cgit_print_repolist()
81{ 81{
82 int i, columns = 4, hits = 0, header = 0; 82 int i, columns = 4, hits = 0, header = 0;
83 char *last_group = NULL; 83 char *last_group = NULL;
84 84
85 if (ctx.cfg.enable_index_links) 85 if (ctx.cfg.enable_index_links)
86 columns++; 86 columns++;
87 87
88 ctx.page.title = ctx.cfg.root_title; 88 ctx.page.title = ctx.cfg.root_title;
89 cgit_print_http_headers(&ctx); 89 cgit_print_http_headers(&ctx);
90 cgit_print_docstart(&ctx); 90 cgit_print_docstart(&ctx);
91 cgit_print_pageheader(&ctx); 91 cgit_print_pageheader(&ctx);
92 92
93 html("<table summary='repository list' class='list nowrap'>"); 93 html("<table summary='repository list' class='list nowrap'>");
94 for (i=0; i<cgit_repolist.count; i++) { 94 for (i=0; i<cgit_repolist.count; i++) {
95 ctx.repo = &cgit_repolist.repos[i]; 95 ctx.repo = &cgit_repolist.repos[i];
96 if (!is_match(ctx.repo)) 96 if (!is_match(ctx.repo))
97 continue; 97 continue;
98 if (!header++) 98 if (!header++)
99 print_header(columns); 99 print_header(columns);
100 hits++; 100 hits++;
101 if ((last_group == NULL && ctx.repo->group != NULL) || 101 if ((last_group == NULL && ctx.repo->group != NULL) ||
102 (last_group != NULL && ctx.repo->group == NULL) || 102 (last_group != NULL && ctx.repo->group == NULL) ||
103 (last_group != NULL && ctx.repo->group != NULL && 103 (last_group != NULL && ctx.repo->group != NULL &&
104 strcmp(ctx.repo->group, last_group))) { 104 strcmp(ctx.repo->group, last_group))) {
105 htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", 105 htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>",
106 columns); 106 columns);
107 html_txt(ctx.repo->group); 107 html_txt(ctx.repo->group);
108 html("</td></tr>"); 108 html("</td></tr>");
109 last_group = ctx.repo->group; 109 last_group = ctx.repo->group;
110 } 110 }
111 htmlf("<tr><td class='%s'>", 111 htmlf("<tr><td class='%s'>",
112 ctx.repo->group ? "sublevel-repo" : "toplevel-repo"); 112 ctx.repo->group ? "sublevel-repo" : "toplevel-repo");
113 html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL); 113 html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL);
114 html_txt(ctx.repo->name); 114 html_txt(ctx.repo->name);
115 html_link_close(); 115 html_link_close();
116 html("</td><td>"); 116 html("</td><td>");
117 html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL);
117 html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc); 118 html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc);
119 html_link_close();
118 html("</td><td>"); 120 html("</td><td>");
119 html_txt(ctx.repo->owner); 121 html_txt(ctx.repo->owner);
120 html("</td><td>"); 122 html("</td><td>");
121 print_modtime(ctx.repo); 123 print_modtime(ctx.repo);
122 html("</td>"); 124 html("</td>");
123 if (ctx.cfg.enable_index_links) { 125 if (ctx.cfg.enable_index_links) {
124 html("<td>"); 126 html("<td>");
125 html_link_open(cgit_repourl(ctx.repo->url), 127 html_link_open(cgit_repourl(ctx.repo->url),
126 NULL, "button"); 128 NULL, "button");
127 html("summary</a>"); 129 html("summary</a>");
128 cgit_log_link("log", NULL, "button", NULL, NULL, NULL, 130 cgit_log_link("log", NULL, "button", NULL, NULL, NULL,
129 0, NULL, NULL); 131 0, NULL, NULL);
130 cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); 132 cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL);
131 html("</td>"); 133 html("</td>");
132 } 134 }
133 html("</tr>\n"); 135 html("</tr>\n");
134 } 136 }
135 html("</table>"); 137 html("</table>");
136 if (!hits) 138 if (!hits)
137 cgit_print_error("No repositories found"); 139 cgit_print_error("No repositories found");
138 cgit_print_docend(); 140 cgit_print_docend();
139} 141}