author | Lars Hjemli <hjemli@gmail.com> | 2007-05-14 09:10:59 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-05-14 09:13:18 (UTC) |
commit | 9fb53af215639fcd3bfb876fa9c8bac221244bdf (patch) (unidiff) | |
tree | 3ebbebebed59b53066e16720a32e1b34c54dc609 | |
parent | 4fdf571c888fd38ae362684c429a3bdf24240ef7 (diff) | |
download | cgit-9fb53af215639fcd3bfb876fa9c8bac221244bdf.zip cgit-9fb53af215639fcd3bfb876fa9c8bac221244bdf.tar.gz cgit-9fb53af215639fcd3bfb876fa9c8bac221244bdf.tar.bz2 |
Add log filtering by path and link to it from tree view
This enables path-filtering in log-view, and adds a link per entry in
tree-view to show the log for each file/directory.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 5 | ||||
-rw-r--r-- | cgit.css | 5 | ||||
-rw-r--r-- | cgit.h | 4 | ||||
-rw-r--r-- | ui-commit.c | 3 | ||||
-rw-r--r-- | ui-log.c | 8 | ||||
-rw-r--r-- | ui-tree.c | 25 |
6 files changed, 37 insertions, 13 deletions
@@ -79,67 +79,68 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
79 | show_search = 0; | 79 | show_search = 0; |
80 | setenv("GIT_DIR", cgit_repo->path, 1); | 80 | setenv("GIT_DIR", cgit_repo->path, 1); |
81 | 81 | ||
82 | if (cgit_query_page) { | 82 | if (cgit_query_page) { |
83 | if (cgit_repo->snapshots && !strcmp(cgit_query_page, "snapshot")) { | 83 | if (cgit_repo->snapshots && !strcmp(cgit_query_page, "snapshot")) { |
84 | cgit_print_snapshot(item, cgit_query_sha1, "zip", | 84 | cgit_print_snapshot(item, cgit_query_sha1, "zip", |
85 | cgit_repo->url, cgit_query_name); | 85 | cgit_repo->url, cgit_query_name); |
86 | return; | 86 | return; |
87 | } | 87 | } |
88 | if (!strcmp(cgit_query_page, "blob")) { | 88 | if (!strcmp(cgit_query_page, "blob")) { |
89 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); | 89 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); |
90 | return; | 90 | return; |
91 | } | 91 | } |
92 | } | 92 | } |
93 | 93 | ||
94 | if (cgit_query_page && !strcmp(cgit_query_page, "log")) | 94 | if (cgit_query_page && !strcmp(cgit_query_page, "log")) |
95 | show_search = 1; | 95 | show_search = 1; |
96 | 96 | ||
97 | cgit_print_docstart(title, item); | 97 | cgit_print_docstart(title, item); |
98 | 98 | ||
99 | 99 | ||
100 | if (!cgit_query_page) { | 100 | if (!cgit_query_page) { |
101 | cgit_print_pageheader("summary", show_search); | 101 | cgit_print_pageheader("summary", show_search); |
102 | cgit_print_summary(); | 102 | cgit_print_summary(); |
103 | cgit_print_docend(); | 103 | cgit_print_docend(); |
104 | return; | 104 | return; |
105 | } | 105 | } |
106 | 106 | ||
107 | cgit_print_pageheader(cgit_query_page, show_search); | 107 | cgit_print_pageheader(cgit_query_page, show_search); |
108 | 108 | ||
109 | if (!strcmp(cgit_query_page, "log")) { | 109 | if (!strcmp(cgit_query_page, "log")) { |
110 | cgit_print_log(cgit_query_head, cgit_query_ofs, | 110 | cgit_print_log(cgit_query_head, cgit_query_ofs, |
111 | cgit_max_commit_count, cgit_query_search); | 111 | cgit_max_commit_count, cgit_query_search, |
112 | cgit_query_path); | ||
112 | } else if (!strcmp(cgit_query_page, "tree")) { | 113 | } else if (!strcmp(cgit_query_page, "tree")) { |
113 | cgit_print_tree(cgit_query_sha1, cgit_query_path); | 114 | cgit_print_tree(cgit_query_head, cgit_query_sha1, cgit_query_path); |
114 | } else if (!strcmp(cgit_query_page, "commit")) { | 115 | } else if (!strcmp(cgit_query_page, "commit")) { |
115 | cgit_print_commit(cgit_query_sha1); | 116 | cgit_print_commit(cgit_query_sha1); |
116 | } else if (!strcmp(cgit_query_page, "view")) { | 117 | } else if (!strcmp(cgit_query_page, "view")) { |
117 | cgit_print_view(cgit_query_sha1, cgit_query_path); | 118 | cgit_print_view(cgit_query_sha1, cgit_query_path); |
118 | } else if (!strcmp(cgit_query_page, "diff")) { | 119 | } else if (!strcmp(cgit_query_page, "diff")) { |
119 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path); | 120 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path); |
120 | } else { | 121 | } else { |
121 | cgit_print_error("Invalid request"); | 122 | cgit_print_error("Invalid request"); |
122 | } | 123 | } |
123 | cgit_print_docend(); | 124 | cgit_print_docend(); |
124 | } | 125 | } |
125 | 126 | ||
126 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 127 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
127 | { | 128 | { |
128 | static char buf[PATH_MAX]; | 129 | static char buf[PATH_MAX]; |
129 | int stdout2; | 130 | int stdout2; |
130 | 131 | ||
131 | getcwd(buf, sizeof(buf)); | 132 | getcwd(buf, sizeof(buf)); |
132 | item->st.st_mtime = time(NULL); | 133 | item->st.st_mtime = time(NULL); |
133 | 134 | ||
134 | if (use_cache) { | 135 | if (use_cache) { |
135 | stdout2 = chk_positive(dup(STDOUT_FILENO), | 136 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
136 | "Preserving STDOUT"); | 137 | "Preserving STDOUT"); |
137 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); | 138 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
138 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); | 139 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
139 | } | 140 | } |
140 | 141 | ||
141 | if (cgit_query_repo) | 142 | if (cgit_query_repo) |
142 | cgit_print_repo_page(item); | 143 | cgit_print_repo_page(item); |
143 | else | 144 | else |
144 | cgit_print_repolist(item); | 145 | cgit_print_repolist(item); |
145 | 146 | ||
@@ -160,64 +160,69 @@ td#archivelist table th { | |||
160 | } | 160 | } |
161 | 161 | ||
162 | td#content { | 162 | td#content { |
163 | padding: 1em 0.5em; | 163 | padding: 1em 0.5em; |
164 | } | 164 | } |
165 | 165 | ||
166 | div#blob { | 166 | div#blob { |
167 | border: solid 1px black; | 167 | border: solid 1px black; |
168 | } | 168 | } |
169 | 169 | ||
170 | div.error { | 170 | div.error { |
171 | color: red; | 171 | color: red; |
172 | font-weight: bold; | 172 | font-weight: bold; |
173 | margin: 1em 2em; | 173 | margin: 1em 2em; |
174 | } | 174 | } |
175 | 175 | ||
176 | td.ls-blob, td.ls-dir, td.ls-mod { | 176 | td.ls-blob, td.ls-dir, td.ls-mod { |
177 | font-family: monospace; | 177 | font-family: monospace; |
178 | } | 178 | } |
179 | 179 | ||
180 | div.ls-dir a { | 180 | div.ls-dir a { |
181 | font-weight: bold; | 181 | font-weight: bold; |
182 | } | 182 | } |
183 | 183 | ||
184 | th.filesize, td.filesize { | 184 | th.filesize, td.filesize { |
185 | text-align: right; | 185 | text-align: right; |
186 | } | 186 | } |
187 | 187 | ||
188 | td.filesize { | 188 | td.filesize { |
189 | font-family: monospace; | 189 | font-family: monospace; |
190 | } | 190 | } |
191 | 191 | ||
192 | td.links { | ||
193 | font-size: 80%; | ||
194 | padding-left: 2em; | ||
195 | } | ||
196 | |||
192 | td.filemode { | 197 | td.filemode { |
193 | font-family: monospace; | 198 | font-family: monospace; |
194 | } | 199 | } |
195 | 200 | ||
196 | td.blob { | 201 | td.blob { |
197 | white-space: pre; | 202 | white-space: pre; |
198 | font-family: monospace; | 203 | font-family: monospace; |
199 | background-color: white; | 204 | background-color: white; |
200 | } | 205 | } |
201 | 206 | ||
202 | table.nowrap td { | 207 | table.nowrap td { |
203 | white-space: nowrap; | 208 | white-space: nowrap; |
204 | } | 209 | } |
205 | 210 | ||
206 | table.commit-info { | 211 | table.commit-info { |
207 | border-collapse: collapse; | 212 | border-collapse: collapse; |
208 | margin-top: 1.5em; | 213 | margin-top: 1.5em; |
209 | } | 214 | } |
210 | 215 | ||
211 | table.commit-info th { | 216 | table.commit-info th { |
212 | text-align: left; | 217 | text-align: left; |
213 | font-weight: normal; | 218 | font-weight: normal; |
214 | padding: 0.1em 1em 0.1em 0.1em; | 219 | padding: 0.1em 1em 0.1em 0.1em; |
215 | } | 220 | } |
216 | 221 | ||
217 | table.commit-info td { | 222 | table.commit-info td { |
218 | font-weight: normal; | 223 | font-weight: normal; |
219 | padding: 0.1em 1em 0.1em 0.1em; | 224 | padding: 0.1em 1em 0.1em 0.1em; |
220 | } | 225 | } |
221 | 226 | ||
222 | div.commit-subject { | 227 | div.commit-subject { |
223 | font-weight: bold; | 228 | font-weight: bold; |
@@ -140,43 +140,43 @@ extern void html_attr(char *txt); | |||
140 | extern void html_hidden(char *name, char *value); | 140 | extern void html_hidden(char *name, char *value); |
141 | extern void html_link_open(char *url, char *title, char *class); | 141 | extern void html_link_open(char *url, char *title, char *class); |
142 | extern void html_link_close(void); | 142 | extern void html_link_close(void); |
143 | extern void html_filemode(unsigned short mode); | 143 | extern void html_filemode(unsigned short mode); |
144 | 144 | ||
145 | extern int cgit_read_config(const char *filename, configfn fn); | 145 | extern int cgit_read_config(const char *filename, configfn fn); |
146 | extern int cgit_parse_query(char *txt, configfn fn); | 146 | extern int cgit_parse_query(char *txt, configfn fn); |
147 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 147 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
148 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 148 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
149 | 149 | ||
150 | extern char *cache_safe_filename(const char *unsafe); | 150 | extern char *cache_safe_filename(const char *unsafe); |
151 | extern int cache_lock(struct cacheitem *item); | 151 | extern int cache_lock(struct cacheitem *item); |
152 | extern int cache_unlock(struct cacheitem *item); | 152 | extern int cache_unlock(struct cacheitem *item); |
153 | extern int cache_cancel_lock(struct cacheitem *item); | 153 | extern int cache_cancel_lock(struct cacheitem *item); |
154 | extern int cache_exist(struct cacheitem *item); | 154 | extern int cache_exist(struct cacheitem *item); |
155 | extern int cache_expired(struct cacheitem *item); | 155 | extern int cache_expired(struct cacheitem *item); |
156 | 156 | ||
157 | extern char *cgit_repourl(const char *reponame); | 157 | extern char *cgit_repourl(const char *reponame); |
158 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 158 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
159 | const char *query); | 159 | const char *query); |
160 | 160 | ||
161 | extern void cgit_print_error(char *msg); | 161 | extern void cgit_print_error(char *msg); |
162 | extern void cgit_print_date(unsigned long secs); | 162 | extern void cgit_print_date(unsigned long secs); |
163 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 163 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
164 | extern void cgit_print_docend(); | 164 | extern void cgit_print_docend(); |
165 | extern void cgit_print_pageheader(char *title, int show_search); | 165 | extern void cgit_print_pageheader(char *title, int show_search); |
166 | extern void cgit_print_snapshot_start(const char *mimetype, | 166 | extern void cgit_print_snapshot_start(const char *mimetype, |
167 | const char *filename, | 167 | const char *filename, |
168 | struct cacheitem *item); | 168 | struct cacheitem *item); |
169 | 169 | ||
170 | extern void cgit_print_repolist(struct cacheitem *item); | 170 | extern void cgit_print_repolist(struct cacheitem *item); |
171 | extern void cgit_print_summary(); | 171 | extern void cgit_print_summary(); |
172 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep); | 172 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path); |
173 | extern void cgit_print_view(const char *hex, char *path); | 173 | extern void cgit_print_view(const char *hex, char *path); |
174 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | 174 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
175 | extern void cgit_print_tree(const char *hex, char *path); | 175 | extern void cgit_print_tree(const char *rev, const char *hex, char *path); |
176 | extern void cgit_print_commit(const char *hex); | 176 | extern void cgit_print_commit(const char *hex); |
177 | extern void cgit_print_diff(const char *old_hex, const char *new_hex, char *path); | 177 | extern void cgit_print_diff(const char *old_hex, const char *new_hex, char *path); |
178 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, | 178 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, |
179 | const char *format, const char *prefix, | 179 | const char *format, const char *prefix, |
180 | const char *filename); | 180 | const char *filename); |
181 | 181 | ||
182 | #endif /* CGIT_H */ | 182 | #endif /* CGIT_H */ |
diff --git a/ui-commit.c b/ui-commit.c index b3d1c28..20a7cb2 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -157,65 +157,66 @@ void cgit_print_commit(const char *hex) | |||
157 | unsigned char sha1[20]; | 157 | unsigned char sha1[20]; |
158 | char *query; | 158 | char *query; |
159 | char *filename; | 159 | char *filename; |
160 | int i; | 160 | int i; |
161 | 161 | ||
162 | if (get_sha1(hex, sha1)) { | 162 | if (get_sha1(hex, sha1)) { |
163 | cgit_print_error(fmt("Bad object id: %s", hex)); | 163 | cgit_print_error(fmt("Bad object id: %s", hex)); |
164 | return; | 164 | return; |
165 | } | 165 | } |
166 | commit = lookup_commit_reference(sha1); | 166 | commit = lookup_commit_reference(sha1); |
167 | if (!commit) { | 167 | if (!commit) { |
168 | cgit_print_error(fmt("Bad commit reference: %s", hex)); | 168 | cgit_print_error(fmt("Bad commit reference: %s", hex)); |
169 | return; | 169 | return; |
170 | } | 170 | } |
171 | info = cgit_parse_commit(commit); | 171 | info = cgit_parse_commit(commit); |
172 | 172 | ||
173 | html("<table class='commit-info'>\n"); | 173 | html("<table class='commit-info'>\n"); |
174 | html("<tr><th>author</th><td>"); | 174 | html("<tr><th>author</th><td>"); |
175 | html_txt(info->author); | 175 | html_txt(info->author); |
176 | html(" "); | 176 | html(" "); |
177 | html_txt(info->author_email); | 177 | html_txt(info->author_email); |
178 | html("</td><td class='right'>"); | 178 | html("</td><td class='right'>"); |
179 | cgit_print_date(info->author_date); | 179 | cgit_print_date(info->author_date); |
180 | html("</td></tr>\n"); | 180 | html("</td></tr>\n"); |
181 | html("<tr><th>committer</th><td>"); | 181 | html("<tr><th>committer</th><td>"); |
182 | html_txt(info->committer); | 182 | html_txt(info->committer); |
183 | html(" "); | 183 | html(" "); |
184 | html_txt(info->committer_email); | 184 | html_txt(info->committer_email); |
185 | html("</td><td class='right'>"); | 185 | html("</td><td class='right'>"); |
186 | cgit_print_date(info->committer_date); | 186 | cgit_print_date(info->committer_date); |
187 | html("</td></tr>\n"); | 187 | html("</td></tr>\n"); |
188 | html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='"); | 188 | html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='"); |
189 | query = fmt("id=%s", sha1_to_hex(commit->tree->object.sha1)); | 189 | query = fmt("h=%s&id=%s", sha1_to_hex(commit->object.sha1), |
190 | sha1_to_hex(commit->tree->object.sha1)); | ||
190 | html_attr(cgit_pageurl(cgit_query_repo, "tree", query)); | 191 | html_attr(cgit_pageurl(cgit_query_repo, "tree", query)); |
191 | htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1)); | 192 | htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1)); |
192 | for (p = commit->parents; p ; p = p->next) { | 193 | for (p = commit->parents; p ; p = p->next) { |
193 | parent = lookup_commit_reference(p->item->object.sha1); | 194 | parent = lookup_commit_reference(p->item->object.sha1); |
194 | if (!parent) { | 195 | if (!parent) { |
195 | html("<tr><td colspan='3'>"); | 196 | html("<tr><td colspan='3'>"); |
196 | cgit_print_error("Error reading parent commit"); | 197 | cgit_print_error("Error reading parent commit"); |
197 | html("</td></tr>"); | 198 | html("</td></tr>"); |
198 | continue; | 199 | continue; |
199 | } | 200 | } |
200 | html("<tr><th>parent</th>" | 201 | html("<tr><th>parent</th>" |
201 | "<td colspan='2' class='sha1'>" | 202 | "<td colspan='2' class='sha1'>" |
202 | "<a href='"); | 203 | "<a href='"); |
203 | query = fmt("id=%s", sha1_to_hex(p->item->object.sha1)); | 204 | query = fmt("id=%s", sha1_to_hex(p->item->object.sha1)); |
204 | html_attr(cgit_pageurl(cgit_query_repo, "commit", query)); | 205 | html_attr(cgit_pageurl(cgit_query_repo, "commit", query)); |
205 | htmlf("'>%s</a> (<a href='", | 206 | htmlf("'>%s</a> (<a href='", |
206 | sha1_to_hex(p->item->object.sha1)); | 207 | sha1_to_hex(p->item->object.sha1)); |
207 | query = fmt("id=%s&id2=%s", sha1_to_hex(parent->tree->object.sha1), | 208 | query = fmt("id=%s&id2=%s", sha1_to_hex(parent->tree->object.sha1), |
208 | sha1_to_hex(commit->tree->object.sha1)); | 209 | sha1_to_hex(commit->tree->object.sha1)); |
209 | html_attr(cgit_pageurl(cgit_query_repo, "diff", query)); | 210 | html_attr(cgit_pageurl(cgit_query_repo, "diff", query)); |
210 | html("'>diff</a>)</td></tr>"); | 211 | html("'>diff</a>)</td></tr>"); |
211 | } | 212 | } |
212 | if (cgit_repo->snapshots) { | 213 | if (cgit_repo->snapshots) { |
213 | htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='"); | 214 | htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='"); |
214 | filename = fmt("%s-%s.zip", cgit_query_repo, hex); | 215 | filename = fmt("%s-%s.zip", cgit_query_repo, hex); |
215 | html_attr(cgit_pageurl(cgit_query_repo, "snapshot", | 216 | html_attr(cgit_pageurl(cgit_query_repo, "snapshot", |
216 | fmt("id=%s&name=%s", hex, filename))); | 217 | fmt("id=%s&name=%s", hex, filename))); |
217 | htmlf("'>%s</a></td></tr>", filename); | 218 | htmlf("'>%s</a></td></tr>", filename); |
218 | } | 219 | } |
219 | html("</table>\n"); | 220 | html("</table>\n"); |
220 | html("<div class='commit-subject'>"); | 221 | html("<div class='commit-subject'>"); |
221 | html_txt(info->subject); | 222 | html_txt(info->subject); |
@@ -24,74 +24,78 @@ void inspect_files(struct diff_filepair *pair) | |||
24 | 24 | ||
25 | void print_commit(struct commit *commit) | 25 | void print_commit(struct commit *commit) |
26 | { | 26 | { |
27 | char buf[32]; | 27 | char buf[32]; |
28 | struct commitinfo *info; | 28 | struct commitinfo *info; |
29 | struct tm *time; | 29 | struct tm *time; |
30 | 30 | ||
31 | info = cgit_parse_commit(commit); | 31 | info = cgit_parse_commit(commit); |
32 | time = gmtime(&commit->date); | 32 | time = gmtime(&commit->date); |
33 | html("<tr><td>"); | 33 | html("<tr><td>"); |
34 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", time); | 34 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", time); |
35 | html_txt(buf); | 35 | html_txt(buf); |
36 | html("</td><td>"); | 36 | html("</td><td>"); |
37 | char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1)); | 37 | char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1)); |
38 | char *url = cgit_pageurl(cgit_query_repo, "commit", qry); | 38 | char *url = cgit_pageurl(cgit_query_repo, "commit", qry); |
39 | html_link_open(url, NULL, NULL); | 39 | html_link_open(url, NULL, NULL); |
40 | html_ntxt(cgit_max_msg_len, info->subject); | 40 | html_ntxt(cgit_max_msg_len, info->subject); |
41 | html_link_close(); | 41 | html_link_close(); |
42 | files = 0; | 42 | files = 0; |
43 | lines = 0; | 43 | lines = 0; |
44 | cgit_diff_commit(commit, inspect_files); | 44 | cgit_diff_commit(commit, inspect_files); |
45 | html("</td><td class='right'>"); | 45 | html("</td><td class='right'>"); |
46 | htmlf("%d", files); | 46 | htmlf("%d", files); |
47 | html("</td><td class='right'>"); | 47 | html("</td><td class='right'>"); |
48 | htmlf("%d", lines); | 48 | htmlf("%d", lines); |
49 | html("</td><td>"); | 49 | html("</td><td>"); |
50 | html_txt(info->author); | 50 | html_txt(info->author); |
51 | html("</td></tr>\n"); | 51 | html("</td></tr>\n"); |
52 | cgit_free_commitinfo(info); | 52 | cgit_free_commitinfo(info); |
53 | } | 53 | } |
54 | 54 | ||
55 | 55 | ||
56 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep) | 56 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path) |
57 | { | 57 | { |
58 | struct rev_info rev; | 58 | struct rev_info rev; |
59 | struct commit *commit; | 59 | struct commit *commit; |
60 | const char *argv[3] = {NULL, tip, NULL}; | 60 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; |
61 | int argc = 2; | 61 | int argc = 2; |
62 | int i; | 62 | int i; |
63 | 63 | ||
64 | if (grep) | 64 | if (grep) |
65 | argv[argc++] = fmt("--grep=%s", grep); | 65 | argv[argc++] = fmt("--grep=%s", grep); |
66 | if (path) { | ||
67 | argv[argc++] = "--"; | ||
68 | argv[argc++] = path; | ||
69 | } | ||
66 | init_revisions(&rev, NULL); | 70 | init_revisions(&rev, NULL); |
67 | rev.abbrev = DEFAULT_ABBREV; | 71 | rev.abbrev = DEFAULT_ABBREV; |
68 | rev.commit_format = CMIT_FMT_DEFAULT; | 72 | rev.commit_format = CMIT_FMT_DEFAULT; |
69 | rev.verbose_header = 1; | 73 | rev.verbose_header = 1; |
70 | rev.show_root_diff = 0; | 74 | rev.show_root_diff = 0; |
71 | setup_revisions(argc, argv, &rev, NULL); | 75 | setup_revisions(argc, argv, &rev, NULL); |
72 | if (rev.grep_filter) { | 76 | if (rev.grep_filter) { |
73 | rev.grep_filter->regflags |= REG_ICASE; | 77 | rev.grep_filter->regflags |= REG_ICASE; |
74 | compile_grep_patterns(rev.grep_filter); | 78 | compile_grep_patterns(rev.grep_filter); |
75 | } | 79 | } |
76 | prepare_revision_walk(&rev); | 80 | prepare_revision_walk(&rev); |
77 | 81 | ||
78 | html("<table class='list nowrap'>"); | 82 | html("<table class='list nowrap'>"); |
79 | html("<tr class='nohover'><th class='left'>Date</th>" | 83 | html("<tr class='nohover'><th class='left'>Date</th>" |
80 | "<th class='left'>Message</th>" | 84 | "<th class='left'>Message</th>" |
81 | "<th class='left'>Files</th>" | 85 | "<th class='left'>Files</th>" |
82 | "<th class='left'>Lines</th>" | 86 | "<th class='left'>Lines</th>" |
83 | "<th class='left'>Author</th></tr>\n"); | 87 | "<th class='left'>Author</th></tr>\n"); |
84 | 88 | ||
85 | if (ofs<0) | 89 | if (ofs<0) |
86 | ofs = 0; | 90 | ofs = 0; |
87 | 91 | ||
88 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { | 92 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { |
89 | free(commit->buffer); | 93 | free(commit->buffer); |
90 | commit->buffer = NULL; | 94 | commit->buffer = NULL; |
91 | free_commit_list(commit->parents); | 95 | free_commit_list(commit->parents); |
92 | commit->parents = NULL; | 96 | commit->parents = NULL; |
93 | } | 97 | } |
94 | 98 | ||
95 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { | 99 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { |
96 | print_commit(commit); | 100 | print_commit(commit); |
97 | free(commit->buffer); | 101 | free(commit->buffer); |
@@ -1,81 +1,94 @@ | |||
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 | char *curr_rev; | ||
11 | 12 | ||
12 | static int print_entry(const unsigned char *sha1, const char *base, | 13 | static int print_entry(const unsigned char *sha1, const char *base, |
13 | int baselen, const char *pathname, unsigned int mode, | 14 | int baselen, const char *pathname, unsigned int mode, |
14 | int stage) | 15 | int stage) |
15 | { | 16 | { |
16 | char *name; | 17 | char *name; |
17 | enum object_type type; | 18 | enum object_type type; |
18 | unsigned long size = 0; | 19 | unsigned long size = 0; |
19 | 20 | ||
20 | name = xstrdup(pathname); | 21 | name = xstrdup(pathname); |
21 | type = sha1_object_info(sha1, &size); | 22 | type = sha1_object_info(sha1, &size); |
22 | if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { | 23 | if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { |
23 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", | 24 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
24 | name, | 25 | name, |
25 | sha1_to_hex(sha1)); | 26 | sha1_to_hex(sha1)); |
26 | return 0; | 27 | return 0; |
27 | } | 28 | } |
28 | html("<tr><td class='filemode'>"); | 29 | html("<tr><td class='filemode'>"); |
29 | html_filemode(mode); | 30 | html_filemode(mode); |
30 | html("</td><td "); | 31 | html("</td><td "); |
31 | if (S_ISDIRLNK(mode)) { | 32 | if (S_ISDIRLNK(mode)) { |
32 | htmlf("class='ls-mod'><a href='"); | 33 | htmlf("class='ls-mod'><a href='"); |
33 | html_attr(fmt(cgit_repo->module_link, | 34 | html_attr(fmt(cgit_repo->module_link, |
34 | name, | 35 | name, |
35 | sha1_to_hex(sha1))); | 36 | sha1_to_hex(sha1))); |
36 | } else if (S_ISDIR(mode)) { | 37 | } else if (S_ISDIR(mode)) { |
37 | html("class='ls-dir'><a href='"); | 38 | html("class='ls-dir'><a href='"); |
38 | html_attr(cgit_pageurl(cgit_query_repo, "tree", | 39 | html_attr(cgit_pageurl(cgit_query_repo, "tree", |
39 | fmt("id=%s&path=%s%s/", | 40 | fmt("h=%s&id=%s&path=%s%s/", |
41 | curr_rev, | ||
40 | sha1_to_hex(sha1), | 42 | sha1_to_hex(sha1), |
41 | cgit_query_path ? cgit_query_path : "", | 43 | cgit_query_path ? cgit_query_path : "", |
42 | pathname))); | 44 | pathname))); |
43 | } else { | 45 | } else { |
44 | html("class='ls-blob'><a href='"); | 46 | html("class='ls-blob'><a href='"); |
45 | html_attr(cgit_pageurl(cgit_query_repo, "view", | 47 | html_attr(cgit_pageurl(cgit_query_repo, "view", |
46 | fmt("id=%s&path=%s%s", sha1_to_hex(sha1), | 48 | fmt("h=%s&id=%s&path=%s%s", curr_rev, |
49 | sha1_to_hex(sha1), | ||
47 | cgit_query_path ? cgit_query_path : "", | 50 | cgit_query_path ? cgit_query_path : "", |
48 | pathname))); | 51 | pathname))); |
49 | } | 52 | } |
50 | htmlf("'>%s</a></div></td>", name); | 53 | htmlf("'>%s</a></div></td>", name); |
51 | htmlf("<td class='filesize'>%li</td>", size); | 54 | htmlf("<td class='filesize'>%li</td>", size); |
55 | |||
56 | html("<td class='links'><a href='"); | ||
57 | html_attr(cgit_pageurl(cgit_query_repo, "log", | ||
58 | fmt("h=%s&path=%s%s", | ||
59 | curr_rev, | ||
60 | cgit_query_path ? cgit_query_path : "", | ||
61 | pathname))); | ||
62 | html("'>history</a></td>"); | ||
52 | html("</tr>\n"); | 63 | html("</tr>\n"); |
53 | free(name); | 64 | free(name); |
54 | return 0; | 65 | return 0; |
55 | } | 66 | } |
56 | 67 | ||
57 | void cgit_print_tree(const char *hex, char *path) | 68 | void cgit_print_tree(const char *rev, const char *hex, char *path) |
58 | { | 69 | { |
59 | struct tree *tree; | 70 | struct tree *tree; |
60 | unsigned char sha1[20]; | 71 | unsigned char sha1[20]; |
61 | 72 | ||
73 | curr_rev = xstrdup(rev); | ||
62 | if (get_sha1_hex(hex, sha1)) { | 74 | if (get_sha1_hex(hex, sha1)) { |
63 | cgit_print_error(fmt("Invalid object id: %s", hex)); | 75 | cgit_print_error(fmt("Invalid object id: %s", hex)); |
64 | return; | 76 | return; |
65 | } | 77 | } |
66 | tree = parse_tree_indirect(sha1); | 78 | tree = parse_tree_indirect(sha1); |
67 | if (!tree) { | 79 | if (!tree) { |
68 | cgit_print_error(fmt("Not a tree object: %s", hex)); | 80 | cgit_print_error(fmt("Not a tree object: %s", hex)); |
69 | return; | 81 | return; |
70 | } | 82 | } |
71 | 83 | ||
72 | html_txt(path); | 84 | html_txt(path); |
73 | html("<table class='list'>\n"); | 85 | html("<table class='list'>\n"); |
74 | html("<tr class='nohover'>"); | 86 | html("<tr class='nohover'>"); |
75 | html("<th class='left'>Mode</th>"); | 87 | html("<th class='left'>Mode</th>"); |
76 | html("<th class='left'>Name</th>"); | 88 | html("<th class='left'>Name</th>"); |
77 | html("<th class='right'>Size</th>"); | 89 | html("<th class='right'>Size</th>"); |
90 | html("<th/>"); | ||
78 | html("</tr>\n"); | 91 | html("</tr>\n"); |
79 | read_tree_recursive(tree, "", 0, 1, NULL, print_entry); | 92 | read_tree_recursive(tree, "", 0, 1, NULL, print_entry); |
80 | html("</table>\n"); | 93 | html("</table>\n"); |
81 | } | 94 | } |