author | Lars Hjemli <hjemli@gmail.com> | 2008-04-08 19:29:21 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-04-08 19:29:21 (UTC) |
commit | 23296ad648c0e2a9e3cf40a3de322b10ad25cce3 (patch) (unidiff) | |
tree | 136493d8228b0ff4971feb06b0e8aee296367b00 /ui-log.c | |
parent | e2a44cf0923398396b7a321d5ce894ad3bf6f580 (diff) | |
parent | c6f747649ace1a92ed5dfaae9cc1ea3affe0bf51 (diff) | |
download | cgit-23296ad648c0e2a9e3cf40a3de322b10ad25cce3.zip cgit-23296ad648c0e2a9e3cf40a3de322b10ad25cce3.tar.gz cgit-23296ad648c0e2a9e3cf40a3de322b10ad25cce3.tar.bz2 |
Merge branch 'lh/cleanup'
* lh/cleanup: (21 commits)
Reset ctx.repo to NULL when the config parser is finished
Move cgit_parse_query() from parsing.c to html.c as http_parse_querystring()
Move function for configfile parsing into configfile.[ch]
Add cache.h
Remove global and obsolete cgit_cmd
Makefile: copy the QUIET constructs from the Makefile in git.git
Move cgit_version from shared.c to cgit.c
Makefile: autobuild dependency rules
Initial Makefile cleanup
Move non-generic functions from shared.c to cgit.c
Add ui-shared.h
Add separate header-files for each page/view
Refactor snapshot support
Add command dispatcher
Remove obsolete cacheitem parameter to ui-functions
Add struct cgit_page to cgit_context
Introduce html.h
Improve initialization of git directory
Move cgit_repo into cgit_context
Add all config variables into struct cgit_context
...
-rw-r--r-- | ui-log.c | 32 |
1 files changed, 17 insertions, 15 deletions
@@ -1,140 +1,142 @@ | |||
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" | ||
11 | #include "ui-shared.h" | ||
10 | 12 | ||
11 | int files, add_lines, rem_lines; | 13 | int files, add_lines, rem_lines; |
12 | 14 | ||
13 | void count_lines(char *line, int size) | 15 | void count_lines(char *line, int size) |
14 | { | 16 | { |
15 | if (size <= 0) | 17 | if (size <= 0) |
16 | return; | 18 | return; |
17 | 19 | ||
18 | if (line[0] == '+') | 20 | if (line[0] == '+') |
19 | add_lines++; | 21 | add_lines++; |
20 | 22 | ||
21 | else if (line[0] == '-') | 23 | else if (line[0] == '-') |
22 | rem_lines++; | 24 | rem_lines++; |
23 | } | 25 | } |
24 | 26 | ||
25 | void inspect_files(struct diff_filepair *pair) | 27 | void inspect_files(struct diff_filepair *pair) |
26 | { | 28 | { |
27 | files++; | 29 | files++; |
28 | if (cgit_repo->enable_log_linecount) | 30 | if (ctx.repo->enable_log_linecount) |
29 | cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); | 31 | cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); |
30 | } | 32 | } |
31 | 33 | ||
32 | void print_commit(struct commit *commit) | 34 | void print_commit(struct commit *commit) |
33 | { | 35 | { |
34 | struct commitinfo *info; | 36 | struct commitinfo *info; |
35 | 37 | ||
36 | info = cgit_parse_commit(commit); | 38 | info = cgit_parse_commit(commit); |
37 | html("<tr><td>"); | 39 | html("<tr><td>"); |
38 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); | 40 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); |
39 | html("</td><td>"); | 41 | html("</td><td>"); |
40 | cgit_commit_link(info->subject, NULL, NULL, cgit_query_head, | 42 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, |
41 | sha1_to_hex(commit->object.sha1)); | 43 | sha1_to_hex(commit->object.sha1)); |
42 | if (cgit_repo->enable_log_filecount) { | 44 | if (ctx.repo->enable_log_filecount) { |
43 | files = 0; | 45 | files = 0; |
44 | add_lines = 0; | 46 | add_lines = 0; |
45 | rem_lines = 0; | 47 | rem_lines = 0; |
46 | cgit_diff_commit(commit, inspect_files); | 48 | cgit_diff_commit(commit, inspect_files); |
47 | html("</td><td class='right'>"); | 49 | html("</td><td class='right'>"); |
48 | htmlf("%d", files); | 50 | htmlf("%d", files); |
49 | if (cgit_repo->enable_log_linecount) { | 51 | if (ctx.repo->enable_log_linecount) { |
50 | html("</td><td class='right'>"); | 52 | html("</td><td class='right'>"); |
51 | htmlf("-%d/+%d", rem_lines, add_lines); | 53 | htmlf("-%d/+%d", rem_lines, add_lines); |
52 | } | 54 | } |
53 | } | 55 | } |
54 | html("</td><td>"); | 56 | html("</td><td>"); |
55 | html_txt(info->author); | 57 | html_txt(info->author); |
56 | html("</td></tr>\n"); | 58 | html("</td></tr>\n"); |
57 | cgit_free_commitinfo(info); | 59 | cgit_free_commitinfo(info); |
58 | } | 60 | } |
59 | 61 | ||
60 | 62 | ||
61 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, char *path, int pager) | 63 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, char *path, int pager) |
62 | { | 64 | { |
63 | struct rev_info rev; | 65 | struct rev_info rev; |
64 | struct commit *commit; | 66 | struct commit *commit; |
65 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; | 67 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; |
66 | int argc = 2; | 68 | int argc = 2; |
67 | int i; | 69 | int i; |
68 | 70 | ||
69 | if (!tip) | 71 | if (!tip) |
70 | argv[1] = cgit_query_head; | 72 | argv[1] = ctx.qry.head; |
71 | 73 | ||
72 | if (grep && pattern && (!strcmp(grep, "grep") || | 74 | if (grep && pattern && (!strcmp(grep, "grep") || |
73 | !strcmp(grep, "author") || | 75 | !strcmp(grep, "author") || |
74 | !strcmp(grep, "committer"))) | 76 | !strcmp(grep, "committer"))) |
75 | argv[argc++] = fmt("--%s=%s", grep, pattern); | 77 | argv[argc++] = fmt("--%s=%s", grep, pattern); |
76 | 78 | ||
77 | if (path) { | 79 | if (path) { |
78 | argv[argc++] = "--"; | 80 | argv[argc++] = "--"; |
79 | argv[argc++] = path; | 81 | argv[argc++] = path; |
80 | } | 82 | } |
81 | init_revisions(&rev, NULL); | 83 | init_revisions(&rev, NULL); |
82 | rev.abbrev = DEFAULT_ABBREV; | 84 | rev.abbrev = DEFAULT_ABBREV; |
83 | rev.commit_format = CMIT_FMT_DEFAULT; | 85 | rev.commit_format = CMIT_FMT_DEFAULT; |
84 | rev.verbose_header = 1; | 86 | rev.verbose_header = 1; |
85 | rev.show_root_diff = 0; | 87 | rev.show_root_diff = 0; |
86 | setup_revisions(argc, argv, &rev, NULL); | 88 | setup_revisions(argc, argv, &rev, NULL); |
87 | if (rev.grep_filter) { | 89 | if (rev.grep_filter) { |
88 | rev.grep_filter->regflags |= REG_ICASE; | 90 | rev.grep_filter->regflags |= REG_ICASE; |
89 | compile_grep_patterns(rev.grep_filter); | 91 | compile_grep_patterns(rev.grep_filter); |
90 | } | 92 | } |
91 | prepare_revision_walk(&rev); | 93 | prepare_revision_walk(&rev); |
92 | 94 | ||
93 | html("<table summary='log' class='list nowrap'>"); | 95 | html("<table summary='log' class='list nowrap'>"); |
94 | html("<tr class='nohover'><th class='left'>Age</th>" | 96 | html("<tr class='nohover'><th class='left'>Age</th>" |
95 | "<th class='left'>Message</th>"); | 97 | "<th class='left'>Message</th>"); |
96 | 98 | ||
97 | if (cgit_repo->enable_log_filecount) { | 99 | if (ctx.repo->enable_log_filecount) { |
98 | html("<th class='right'>Files</th>"); | 100 | html("<th class='right'>Files</th>"); |
99 | if (cgit_repo->enable_log_linecount) | 101 | if (ctx.repo->enable_log_linecount) |
100 | html("<th class='right'>Lines</th>"); | 102 | html("<th class='right'>Lines</th>"); |
101 | } | 103 | } |
102 | html("<th class='left'>Author</th></tr>\n"); | 104 | html("<th class='left'>Author</th></tr>\n"); |
103 | 105 | ||
104 | if (ofs<0) | 106 | if (ofs<0) |
105 | ofs = 0; | 107 | ofs = 0; |
106 | 108 | ||
107 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { | 109 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { |
108 | free(commit->buffer); | 110 | free(commit->buffer); |
109 | commit->buffer = NULL; | 111 | commit->buffer = NULL; |
110 | free_commit_list(commit->parents); | 112 | free_commit_list(commit->parents); |
111 | commit->parents = NULL; | 113 | commit->parents = NULL; |
112 | } | 114 | } |
113 | 115 | ||
114 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { | 116 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { |
115 | print_commit(commit); | 117 | print_commit(commit); |
116 | free(commit->buffer); | 118 | free(commit->buffer); |
117 | commit->buffer = NULL; | 119 | commit->buffer = NULL; |
118 | free_commit_list(commit->parents); | 120 | free_commit_list(commit->parents); |
119 | commit->parents = NULL; | 121 | commit->parents = NULL; |
120 | } | 122 | } |
121 | html("</table>\n"); | 123 | html("</table>\n"); |
122 | 124 | ||
123 | if (pager) { | 125 | if (pager) { |
124 | html("<div class='pager'>"); | 126 | html("<div class='pager'>"); |
125 | if (ofs > 0) { | 127 | if (ofs > 0) { |
126 | cgit_log_link("[prev]", NULL, NULL, cgit_query_head, | 128 | cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, |
127 | cgit_query_sha1, cgit_query_path, | 129 | ctx.qry.sha1, ctx.qry.path, |
128 | ofs - cnt, cgit_query_grep, | 130 | ofs - cnt, ctx.qry.grep, |
129 | cgit_query_search); | 131 | ctx.qry.search); |
130 | html(" "); | 132 | html(" "); |
131 | } | 133 | } |
132 | if ((commit = get_revision(&rev)) != NULL) { | 134 | if ((commit = get_revision(&rev)) != NULL) { |
133 | cgit_log_link("[next]", NULL, NULL, cgit_query_head, | 135 | cgit_log_link("[next]", NULL, NULL, ctx.qry.head, |
134 | cgit_query_sha1, cgit_query_path, | 136 | ctx.qry.sha1, ctx.qry.path, |
135 | ofs + cnt, cgit_query_grep, | 137 | ofs + cnt, ctx.qry.grep, |
136 | cgit_query_search); | 138 | ctx.qry.search); |
137 | } | 139 | } |
138 | html("</div>"); | 140 | html("</div>"); |
139 | } | 141 | } |
140 | } | 142 | } |