commit 8957da7c28eda864d43699ccb657c9b48278d7c4 from: Omar Polo date: Fri Dec 8 10:42:50 2023 UTC gotwebd: dedup the bulk of the tree listing code commit - f6c7567b8a08e575b7caa23fcea4f93569553835 commit + 8957da7c28eda864d43699ccb657c9b48278d7c4 blob - 885a22e5fd3853508cf60ca2c14474a54087fb75 blob + 99a7c70488d6b2491287f77419bd029e71eaf201 --- gotwebd/pages.tmpl +++ gotwebd/pages.tmpl @@ -51,6 +51,7 @@ static int blame_line(struct template *, const char *, static inline int gotweb_render_more(struct template *, int); +static inline int tree_listing(struct template *); static inline int diff_line(struct template *, char *); static inline int tag_item(struct template *, struct repo_tag *); static inline int branch(struct template *, struct got_reflist_entry *); @@ -641,18 +642,74 @@ nextsep(char *s, char **t) {{ end }} +{{ define tree_listing(struct template *tp) }} +{! + const struct got_error *error; + struct request *c = tp->tp_arg; + struct transport *t = c->t; + struct querystring *qs = c->t->qs; + struct gotweb_url url; + char *readme = NULL; + int binary; + const uint8_t *buf; + size_t len; +!} + + {{ render got_output_repo_tree(c, &readme, gotweb_render_tree_item) }} +
+ {{ if readme }} + {! + error = got_open_blob_for_output(&t->blob, &t->fd, &binary, c, + qs->folder, readme, qs->commit); + if (error) { + free(readme); + return (-1); + } + + memset(&url, 0, sizeof(url)); + url.index_page = -1; + url.page = -1; + url.action = BLOB; + url.path = t->qs->path; + url.file = readme; + url.folder = t->qs->folder; + url.commit = t->qs->commit; + !} + {{ if !binary }} +

+ + {{ readme }} + +

+
+        {!
+		for (;;) {
+			error = got_object_blob_read_block(&len, t->blob);
+			if (error) {
+				free(readme);
+				return (-1);
+			}
+			if (len == 0)
+				break;
+			buf = got_object_blob_get_read_buf(t->blob);
+			if (tp_write_htmlescape(tp, buf, len) == -1) {
+				free(readme);
+				return (-1);
+			}
+		}
+        !}
+      
+ {{ end }} + {{ end }} +{{ finally }} + {! free(readme); !} +{{ end }} + {{ define gotweb_render_tree(struct template *tp) }} {! - const struct got_error *error; struct request *c = tp->tp_arg; struct transport *t = c->t; - struct querystring *qs = t->qs; struct repo_commit *rc = TAILQ_FIRST(&t->repo_commits); - struct gotweb_url url; - char *readme = NULL; - int binary; - const uint8_t *buf; - size_t len; !}

Tree

@@ -671,56 +728,8 @@ nextsep(char *s, char **t)
- - {{ render got_output_repo_tree(c, &readme, gotweb_render_tree_item) }} -
- {{ if readme }} - {! - error = got_open_blob_for_output(&t->blob, &t->fd, &binary, c, - qs->folder, readme, qs->commit); - if (error) { - free(readme); - return (-1); - } - - memset(&url, 0, sizeof(url)); - url.index_page = -1; - url.page = -1; - url.action = BLOB; - url.path = t->qs->path; - url.file = readme; - url.folder = t->qs->folder; - url.commit = t->qs->commit; - !} - {{ if !binary }} -

- - {{ readme }} - -

-
-        {!
-		for (;;) {
-			error = got_object_blob_read_block(&len, t->blob);
-			if (error) {
-				free(readme);
-				return (-1);
-			}
-			if (len == 0)
-				break;
-			buf = got_object_blob_get_read_buf(t->blob);
-			if (tp_write_htmlescape(tp, buf, len) == -1) {
-				free(readme);
-				return (-1);
-			}
-		}
-        !}
-      
- {{ end }} - {{ end }} + {{ render tree_listing(tp) }} -{{ finally }} -{! free(readme); !} {{ end }} {{ define gotweb_render_tree_item(struct template *tp, @@ -1084,16 +1093,10 @@ nextsep(char *s, char **t) {{ define gotweb_render_summary(struct template *tp) }} {! - const struct got_error *error; struct request *c = tp->tp_arg; struct server *srv = c->srv; struct transport *t = c->t; struct got_reflist_head *refs = &t->refs; - struct gotweb_url url; - char *readme = NULL; - int binary; - const uint8_t *buf; - size_t len; !}
- - {{ render got_output_repo_tree(c, &readme, gotweb_render_tree_item) }} -
- {{ if readme }} - {! - error = got_open_blob_for_output(&t->blob, &t->fd, &binary, c, - "/", readme, NULL); - if (error) { - free(readme); - return (-1); - } - - memset(&url, 0, sizeof(url)); - url.index_page = -1; - url.page = -1; - url.action = BLOB; - url.path = t->qs->path; - url.file = readme; - url.folder = t->qs->folder; - url.commit = t->qs->commit; - !} - {{ if !binary }} -

- - {{ readme }} - -

-
-        {!
-		for (;;) {
-			error = got_object_blob_read_block(&len, t->blob);
-			if (error) {
-				free(readme);
-				return (-1);
-			}
-			if (len == 0)
-				break;
-			buf = got_object_blob_get_read_buf(t->blob);
-			if (tp_write_htmlescape(tp, buf, len) == -1) {
-				free(readme);
-				return (-1);
-			}
-		}
-        !}
-      
- {{ end }} - {{ end }} + {{ render tree_listing(tp) }}
-{{ finally }} -{! free(readme); !} {{ end }} {{ define gotweb_render_blame(struct template *tp) }}