summaryrefslogtreecommitdiffabout
authorLars Hjemli <larsh@hatman.(none)>2008-07-21 08:10:48 (UTC)
committer Lars Hjemli <larsh@hatman.(none)>2008-07-21 08:10:48 (UTC)
commit566f92b27618f67f59cc3642e17d9cb9c12634fa (patch) (unidiff)
tree3945996da0cce9a348a803d91c87df4e303c178b
parentd2eb4fddb0fb7cd1751debcff6fe1219b9c619c8 (diff)
downloadcgit-566f92b27618f67f59cc3642e17d9cb9c12634fa.zip
cgit-566f92b27618f67f59cc3642e17d9cb9c12634fa.tar.gz
cgit-566f92b27618f67f59cc3642e17d9cb9c12634fa.tar.bz2
Adjust to new calling convention for read_tree_recursive()
In GIT-1.6.0, read_tree_recursive takes an extra void pointer for callback data. We might want to use this to avoid some global variables, but for now lets just make sure that we can still compile. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ui-blob.c5
-rw-r--r--ui-tree.c12
2 files changed, 10 insertions, 7 deletions
diff --git a/ui-blob.c b/ui-blob.c
index 73a8c1d..3cda03d 100644
--- a/ui-blob.c
+++ b/ui-blob.c
@@ -1,72 +1,73 @@
1/* ui-blob.c: show blob content 1/* ui-blob.c: show blob content
2 * 2 *
3 * Copyright (C) 2008 Lars Hjemli 3 * Copyright (C) 2008 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
13static char *match_path; 13static char *match_path;
14static unsigned char *matched_sha1; 14static unsigned char *matched_sha1;
15 15
16static int walk_tree(const unsigned char *sha1, const char *base,int baselen, const char *pathname, unsigned mode, int stage) { 16static int walk_tree(const unsigned char *sha1, const char *base,int baselen,
17 const char *pathname, unsigned mode, int stage, void *cbdata) {
17 if(strncmp(base,match_path,baselen) 18 if(strncmp(base,match_path,baselen)
18 || strcmp(match_path+baselen,pathname) ) 19 || strcmp(match_path+baselen,pathname) )
19 return READ_TREE_RECURSIVE; 20 return READ_TREE_RECURSIVE;
20 memmove(matched_sha1,sha1,20); 21 memmove(matched_sha1,sha1,20);
21 return 0; 22 return 0;
22} 23}
23 24
24void cgit_print_blob(const char *hex, char *path, const char *head) 25void cgit_print_blob(const char *hex, char *path, const char *head)
25{ 26{
26 27
27 unsigned char sha1[20]; 28 unsigned char sha1[20];
28 enum object_type type; 29 enum object_type type;
29 unsigned char *buf; 30 unsigned char *buf;
30 unsigned long size; 31 unsigned long size;
31 struct commit *commit; 32 struct commit *commit;
32 const char *paths[] = {path, NULL}; 33 const char *paths[] = {path, NULL};
33 34
34 if (hex) { 35 if (hex) {
35 if (get_sha1_hex(hex, sha1)){ 36 if (get_sha1_hex(hex, sha1)){
36 cgit_print_error(fmt("Bad hex value: %s", hex)); 37 cgit_print_error(fmt("Bad hex value: %s", hex));
37 return; 38 return;
38 } 39 }
39 } else { 40 } else {
40 if (get_sha1(head,sha1)) { 41 if (get_sha1(head,sha1)) {
41 cgit_print_error(fmt("Bad ref: %s", head)); 42 cgit_print_error(fmt("Bad ref: %s", head));
42 return; 43 return;
43 } 44 }
44 } 45 }
45 46
46 type = sha1_object_info(sha1, &size); 47 type = sha1_object_info(sha1, &size);
47 48
48 if((!hex) && type == OBJ_COMMIT && path) { 49 if((!hex) && type == OBJ_COMMIT && path) {
49 commit = lookup_commit_reference(sha1); 50 commit = lookup_commit_reference(sha1);
50 match_path = path; 51 match_path = path;
51 matched_sha1 = sha1; 52 matched_sha1 = sha1;
52 read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree); 53 read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree, NULL);
53 type = sha1_object_info(sha1,&size); 54 type = sha1_object_info(sha1,&size);
54 } 55 }
55 56
56 if (type == OBJ_BAD) { 57 if (type == OBJ_BAD) {
57 cgit_print_error(fmt("Bad object name: %s", hex)); 58 cgit_print_error(fmt("Bad object name: %s", hex));
58 return; 59 return;
59 } 60 }
60 61
61 buf = read_sha1_file(sha1, &type, &size); 62 buf = read_sha1_file(sha1, &type, &size);
62 if (!buf) { 63 if (!buf) {
63 cgit_print_error(fmt("Error reading object %s", hex)); 64 cgit_print_error(fmt("Error reading object %s", hex));
64 return; 65 return;
65 } 66 }
66 67
67 buf[size] = '\0'; 68 buf[size] = '\0';
68 ctx.page.mimetype = ctx.qry.mimetype; 69 ctx.page.mimetype = ctx.qry.mimetype;
69 ctx.page.filename = path; 70 ctx.page.filename = path;
70 cgit_print_http_headers(&ctx); 71 cgit_print_http_headers(&ctx);
71 write(htmlfd, buf, size); 72 write(htmlfd, buf, size);
72} 73}
diff --git a/ui-tree.c b/ui-tree.c
index 5a2dd3f..9a837e2 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -1,221 +1,223 @@
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#include "html.h" 10#include "html.h"
11#include "ui-shared.h" 11#include "ui-shared.h"
12 12
13char *curr_rev; 13char *curr_rev;
14char *match_path; 14char *match_path;
15int header = 0; 15int header = 0;
16 16
17static void print_object(const unsigned char *sha1, char *path) 17static void print_object(const unsigned char *sha1, char *path)
18{ 18{
19 enum object_type type; 19 enum object_type type;
20 char *buf; 20 char *buf;
21 unsigned long size, lineno, start, idx; 21 unsigned long size, lineno, start, idx;
22 const char *linefmt = "<tr><td class='no'><a id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a></td><td class='txt'>"; 22 const char *linefmt = "<tr><td class='no'><a id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a></td><td class='txt'>";
23 23
24 type = sha1_object_info(sha1, &size); 24 type = sha1_object_info(sha1, &size);
25 if (type == OBJ_BAD) { 25 if (type == OBJ_BAD) {
26 cgit_print_error(fmt("Bad object name: %s", 26 cgit_print_error(fmt("Bad object name: %s",
27 sha1_to_hex(sha1))); 27 sha1_to_hex(sha1)));
28 return; 28 return;
29 } 29 }
30 30
31 buf = read_sha1_file(sha1, &type, &size); 31 buf = read_sha1_file(sha1, &type, &size);
32 if (!buf) { 32 if (!buf) {
33 cgit_print_error(fmt("Error reading object %s", 33 cgit_print_error(fmt("Error reading object %s",
34 sha1_to_hex(sha1))); 34 sha1_to_hex(sha1)));
35 return; 35 return;
36 } 36 }
37 37
38 html(" blob: <a href='"); 38 html(" blob: <a href='");
39 html_attr(cgit_pageurl(ctx.qry.repo, "blob", 39 html_attr(cgit_pageurl(ctx.qry.repo, "blob",
40 fmt("id=%s&path=%s", sha1_to_hex(sha1), path))); 40 fmt("id=%s&path=%s", sha1_to_hex(sha1), path)));
41 htmlf("'>%s</a>",sha1_to_hex(sha1)); 41 htmlf("'>%s</a>",sha1_to_hex(sha1));
42 42
43 html("<table summary='blob content' class='blob'>\n"); 43 html("<table summary='blob content' class='blob'>\n");
44 idx = 0; 44 idx = 0;
45 start = 0; 45 start = 0;
46 lineno = 0; 46 lineno = 0;
47 while(idx < size) { 47 while(idx < size) {
48 if (buf[idx] == '\n') { 48 if (buf[idx] == '\n') {
49 buf[idx] = '\0'; 49 buf[idx] = '\0';
50 htmlf(linefmt, ++lineno); 50 htmlf(linefmt, ++lineno);
51 html_txt(buf + start); 51 html_txt(buf + start);
52 html("</td></tr>\n"); 52 html("</td></tr>\n");
53 start = idx + 1; 53 start = idx + 1;
54 } 54 }
55 idx++; 55 idx++;
56 } 56 }
57 htmlf(linefmt, ++lineno); 57 htmlf(linefmt, ++lineno);
58 html_txt(buf + start); 58 html_txt(buf + start);
59 html("</td></tr>\n"); 59 html("</td></tr>\n");
60 html("</table>\n"); 60 html("</table>\n");
61} 61}
62 62
63 63
64static int ls_item(const unsigned char *sha1, const char *base, int baselen, 64static int ls_item(const unsigned char *sha1, const char *base, int baselen,
65 const char *pathname, unsigned int mode, int stage) 65 const char *pathname, unsigned int mode, int stage,
66 void *cbdata)
66{ 67{
67 char *name; 68 char *name;
68 char *fullpath; 69 char *fullpath;
69 enum object_type type; 70 enum object_type type;
70 unsigned long size = 0; 71 unsigned long size = 0;
71 72
72 name = xstrdup(pathname); 73 name = xstrdup(pathname);
73 fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", 74 fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "",
74 ctx.qry.path ? "/" : "", name); 75 ctx.qry.path ? "/" : "", name);
75 76
76 if (!S_ISGITLINK(mode)) { 77 if (!S_ISGITLINK(mode)) {
77 type = sha1_object_info(sha1, &size); 78 type = sha1_object_info(sha1, &size);
78 if (type == OBJ_BAD) { 79 if (type == OBJ_BAD) {
79 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", 80 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
80 name, 81 name,
81 sha1_to_hex(sha1)); 82 sha1_to_hex(sha1));
82 return 0; 83 return 0;
83 } 84 }
84 } 85 }
85 86
86 html("<tr><td class='ls-mode'>"); 87 html("<tr><td class='ls-mode'>");
87 cgit_print_filemode(mode); 88 cgit_print_filemode(mode);
88 html("</td><td>"); 89 html("</td><td>");
89 if (S_ISGITLINK(mode)) { 90 if (S_ISGITLINK(mode)) {
90 htmlf("<a class='ls-mod' href='"); 91 htmlf("<a class='ls-mod' href='");
91 html_attr(fmt(ctx.repo->module_link, 92 html_attr(fmt(ctx.repo->module_link,
92 name, 93 name,
93 sha1_to_hex(sha1))); 94 sha1_to_hex(sha1)));
94 html("'>"); 95 html("'>");
95 html_txt(name); 96 html_txt(name);
96 html("</a>"); 97 html("</a>");
97 } else if (S_ISDIR(mode)) { 98 } else if (S_ISDIR(mode)) {
98 cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, 99 cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head,
99 curr_rev, fullpath); 100 curr_rev, fullpath);
100 } else { 101 } else {
101 cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head, 102 cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head,
102 curr_rev, fullpath); 103 curr_rev, fullpath);
103 } 104 }
104 htmlf("</td><td class='ls-size'>%li</td>", size); 105 htmlf("</td><td class='ls-size'>%li</td>", size);
105 106
106 html("<td>"); 107 html("<td>");
107 cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev, 108 cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev,
108 fullpath, 0, NULL, NULL); 109 fullpath, 0, NULL, NULL);
109 html("</td></tr>\n"); 110 html("</td></tr>\n");
110 free(name); 111 free(name);
111 return 0; 112 return 0;
112} 113}
113 114
114static void ls_head() 115static void ls_head()
115{ 116{
116 html("<table summary='tree listing' class='list'>\n"); 117 html("<table summary='tree listing' class='list'>\n");
117 html("<tr class='nohover'>"); 118 html("<tr class='nohover'>");
118 html("<th class='left'>Mode</th>"); 119 html("<th class='left'>Mode</th>");
119 html("<th class='left'>Name</th>"); 120 html("<th class='left'>Name</th>");
120 html("<th class='right'>Size</th>"); 121 html("<th class='right'>Size</th>");
121 html("<th/>"); 122 html("<th/>");
122 html("</tr>\n"); 123 html("</tr>\n");
123 header = 1; 124 header = 1;
124} 125}
125 126
126static void ls_tail() 127static void ls_tail()
127{ 128{
128 if (!header) 129 if (!header)
129 return; 130 return;
130 html("</table>\n"); 131 html("</table>\n");
131 header = 0; 132 header = 0;
132} 133}
133 134
134static void ls_tree(const unsigned char *sha1, char *path) 135static void ls_tree(const unsigned char *sha1, char *path)
135{ 136{
136 struct tree *tree; 137 struct tree *tree;
137 138
138 tree = parse_tree_indirect(sha1); 139 tree = parse_tree_indirect(sha1);
139 if (!tree) { 140 if (!tree) {
140 cgit_print_error(fmt("Not a tree object: %s", 141 cgit_print_error(fmt("Not a tree object: %s",
141 sha1_to_hex(sha1))); 142 sha1_to_hex(sha1)));
142 return; 143 return;
143 } 144 }
144 145
145 ls_head(); 146 ls_head();
146 read_tree_recursive(tree, "", 0, 1, NULL, ls_item); 147 read_tree_recursive(tree, "", 0, 1, NULL, ls_item, NULL);
147 ls_tail(); 148 ls_tail();
148} 149}
149 150
150 151
151static int walk_tree(const unsigned char *sha1, const char *base, int baselen, 152static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
152 const char *pathname, unsigned mode, int stage) 153 const char *pathname, unsigned mode, int stage,
154 void *cbdata)
153{ 155{
154 static int state; 156 static int state;
155 static char buffer[PATH_MAX]; 157 static char buffer[PATH_MAX];
156 char *url; 158 char *url;
157 159
158 if (state == 0) { 160 if (state == 0) {
159 memcpy(buffer, base, baselen); 161 memcpy(buffer, base, baselen);
160 strcpy(buffer+baselen, pathname); 162 strcpy(buffer+baselen, pathname);
161 url = cgit_pageurl(ctx.qry.repo, "tree", 163 url = cgit_pageurl(ctx.qry.repo, "tree",
162 fmt("h=%s&amp;path=%s", curr_rev, buffer)); 164 fmt("h=%s&amp;path=%s", curr_rev, buffer));
163 html("/"); 165 html("/");
164 cgit_tree_link(xstrdup(pathname), NULL, NULL, ctx.qry.head, 166 cgit_tree_link(xstrdup(pathname), NULL, NULL, ctx.qry.head,
165 curr_rev, buffer); 167 curr_rev, buffer);
166 168
167 if (strcmp(match_path, buffer)) 169 if (strcmp(match_path, buffer))
168 return READ_TREE_RECURSIVE; 170 return READ_TREE_RECURSIVE;
169 171
170 if (S_ISDIR(mode)) { 172 if (S_ISDIR(mode)) {
171 state = 1; 173 state = 1;
172 ls_head(); 174 ls_head();
173 return READ_TREE_RECURSIVE; 175 return READ_TREE_RECURSIVE;
174 } else { 176 } else {
175 print_object(sha1, buffer); 177 print_object(sha1, buffer);
176 return 0; 178 return 0;
177 } 179 }
178 } 180 }
179 ls_item(sha1, base, baselen, pathname, mode, stage); 181 ls_item(sha1, base, baselen, pathname, mode, stage, NULL);
180 return 0; 182 return 0;
181} 183}
182 184
183 185
184/* 186/*
185 * Show a tree or a blob 187 * Show a tree or a blob
186 * rev: the commit pointing at the root tree object 188 * rev: the commit pointing at the root tree object
187 * path: path to tree or blob 189 * path: path to tree or blob
188 */ 190 */
189void cgit_print_tree(const char *rev, char *path) 191void cgit_print_tree(const char *rev, char *path)
190{ 192{
191 unsigned char sha1[20]; 193 unsigned char sha1[20];
192 struct commit *commit; 194 struct commit *commit;
193 const char *paths[] = {path, NULL}; 195 const char *paths[] = {path, NULL};
194 196
195 if (!rev) 197 if (!rev)
196 rev = ctx.qry.head; 198 rev = ctx.qry.head;
197 199
198 curr_rev = xstrdup(rev); 200 curr_rev = xstrdup(rev);
199 if (get_sha1(rev, sha1)) { 201 if (get_sha1(rev, sha1)) {
200 cgit_print_error(fmt("Invalid revision name: %s", rev)); 202 cgit_print_error(fmt("Invalid revision name: %s", rev));
201 return; 203 return;
202 } 204 }
203 commit = lookup_commit_reference(sha1); 205 commit = lookup_commit_reference(sha1);
204 if (!commit || parse_commit(commit)) { 206 if (!commit || parse_commit(commit)) {
205 cgit_print_error(fmt("Invalid commit reference: %s", rev)); 207 cgit_print_error(fmt("Invalid commit reference: %s", rev));
206 return; 208 return;
207 } 209 }
208 210
209 html("path: <a href='"); 211 html("path: <a href='");
210 html_attr(cgit_pageurl(ctx.qry.repo, "tree", fmt("h=%s", rev))); 212 html_attr(cgit_pageurl(ctx.qry.repo, "tree", fmt("h=%s", rev)));
211 html("'>root</a>"); 213 html("'>root</a>");
212 214
213 if (path == NULL) { 215 if (path == NULL) {
214 ls_tree(commit->tree->object.sha1, NULL); 216 ls_tree(commit->tree->object.sha1, NULL);
215 return; 217 return;
216 } 218 }
217 219
218 match_path = path; 220 match_path = path;
219 read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree); 221 read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree, NULL);
220 ls_tail(); 222 ls_tail();
221} 223}