aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Lukas Fleischer <cgit@cryptocrack.de>2013-03-04 01:10:19 (JST)
committerGravatar Jason A. Donenfeld <Jason@zx2c4.com>2013-03-04 23:12:54 (JST)
commita6317505ead198c23925c93abbb0926f70e02861 (patch)
tree79eea985f4622431a98e6d879a7b6b5b30e6f02d
parent41f9c4e2f66252c83c6524fa4a346839d4c454b2 (diff)
downloadcgit-a6317505ead198c23925c93abbb0926f70e02861.zip
cgit-a6317505ead198c23925c93abbb0926f70e02861.tar.gz
ui-plain.c: Do not access match variable in print_*()
Move all code setting the match variable to walk_tree(). This allows for easily moving this variable into a context structure without having to pass the context to print_*(). Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
-rw-r--r--ui-plain.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/ui-plain.c b/ui-plain.c
index c21d38f..c90ae59 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -54,7 +54,7 @@ static char *get_mimetype_from_file(const char *filename, const char *ext)
54 return result; 54 return result;
55} 55}
56 56
57static void print_object(const unsigned char *sha1, const char *path) 57static int print_object(const unsigned char *sha1, const char *path)
58{ 58{
59 enum object_type type; 59 enum object_type type;
60 char *buf, *ext; 60 char *buf, *ext;
@@ -65,13 +65,13 @@ static void print_object(const unsigned char *sha1, const char *path)
65 type = sha1_object_info(sha1, &size); 65 type = sha1_object_info(sha1, &size);
66 if (type == OBJ_BAD) { 66 if (type == OBJ_BAD) {
67 html_status(404, "Not found", 0); 67 html_status(404, "Not found", 0);
68 return; 68 return 0;
69 } 69 }
70 70
71 buf = read_sha1_file(sha1, &type, &size); 71 buf = read_sha1_file(sha1, &type, &size);
72 if (!buf) { 72 if (!buf) {
73 html_status(404, "Not found", 0); 73 html_status(404, "Not found", 0);
74 return; 74 return 0;
75 } 75 }
76 ctx.page.mimetype = NULL; 76 ctx.page.mimetype = NULL;
77 ext = strrchr(path, '.'); 77 ext = strrchr(path, '.');
@@ -97,9 +97,9 @@ static void print_object(const unsigned char *sha1, const char *path)
97 ctx.page.etag = sha1_to_hex(sha1); 97 ctx.page.etag = sha1_to_hex(sha1);
98 cgit_print_http_headers(&ctx); 98 cgit_print_http_headers(&ctx);
99 html_raw(buf, size); 99 html_raw(buf, size);
100 match = 1;
101 if (freemime) 100 if (freemime)
102 free(ctx.page.mimetype); 101 free(ctx.page.mimetype);
102 return 1;
103} 103}
104 104
105static char *buildpath(const char *base, int baselen, const char *path) 105static char *buildpath(const char *base, int baselen, const char *path)
@@ -138,7 +138,6 @@ static void print_dir(const unsigned char *sha1, const char *base,
138 fullpath); 138 fullpath);
139 html("</li>\n"); 139 html("</li>\n");
140 } 140 }
141 match = 2;
142} 141}
143 142
144static void print_dir_entry(const unsigned char *sha1, const char *base, 143static void print_dir_entry(const unsigned char *sha1, const char *base,
@@ -156,7 +155,6 @@ static void print_dir_entry(const unsigned char *sha1, const char *base,
156 cgit_plain_link(path, NULL, NULL, ctx.qry.head, ctx.qry.sha1, 155 cgit_plain_link(path, NULL, NULL, ctx.qry.head, ctx.qry.sha1,
157 fullpath); 156 fullpath);
158 html("</li>\n"); 157 html("</li>\n");
159 match = 2;
160} 158}
161 159
162static void print_dir_tail(void) 160static void print_dir_tail(void)
@@ -169,17 +167,20 @@ static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
169 void *cbdata) 167 void *cbdata)
170{ 168{
171 if (baselen == match_baselen) { 169 if (baselen == match_baselen) {
172 if (S_ISREG(mode)) 170 if (S_ISREG(mode)) {
173 print_object(sha1, pathname); 171 if (print_object(sha1, pathname))
174 else if (S_ISDIR(mode)) { 172 match = 1;
173 } else if (S_ISDIR(mode)) {
175 print_dir(sha1, base, baselen, pathname); 174 print_dir(sha1, base, baselen, pathname);
175 match = 2;
176 return READ_TREE_RECURSIVE; 176 return READ_TREE_RECURSIVE;
177 } 177 }
178 } 178 } else if (baselen > match_baselen) {
179 else if (baselen > match_baselen)
180 print_dir_entry(sha1, base, baselen, pathname, mode); 179 print_dir_entry(sha1, base, baselen, pathname, mode);
181 else if (S_ISDIR(mode)) 180 match = 2;
181 } else if (S_ISDIR(mode)) {
182 return READ_TREE_RECURSIVE; 182 return READ_TREE_RECURSIVE;
183 }
183 184
184 return 0; 185 return 0;
185} 186}
@@ -222,6 +223,7 @@ void cgit_print_plain(struct cgit_context *ctx)
222 path_items.match = ""; 223 path_items.match = "";
223 match_baselen = -1; 224 match_baselen = -1;
224 print_dir(commit->tree->object.sha1, "", 0, ""); 225 print_dir(commit->tree->object.sha1, "", 0, "");
226 match = 2;
225 } 227 }
226 else 228 else
227 match_baselen = basedir_len(path_items.match); 229 match_baselen = basedir_len(path_items.match);