commit f9b5f5fbdf2ae49a4e217212d261d89d83dacd7e from: Omar Polo date: Sat Apr 01 14:24:39 2023 UTC gotwebd: don't special case BLOB, BLOBRAW and RSS shuffle some code to handle all the page types in the switch. ok tracey@ commit - e9e0377f452e9d3f600011e0714cc6c779f10bab commit + f9b5f5fbdf2ae49a4e217212d261d89d83dacd7e blob - d7c46fec7c87d40438428eec977f6b44df1daed1 blob + 532cb2f0f6b9415c1433f00e174bb0fd10c72992 --- gotwebd/gotweb.c +++ gotwebd/gotweb.c @@ -147,6 +147,10 @@ gotweb_process_request(struct request *c) struct server *srv = NULL; struct querystring *qs = NULL; struct repo_dir *repo_dir = NULL; + const char *rss_ctype = "application/rss+xml;charset=utf-8"; + const uint8_t *buf; + size_t len; + int r, binary = 0; /* init the transport */ error = gotweb_init_transport(&c->t); @@ -201,11 +205,7 @@ gotweb_process_request(struct request *c) goto err; } - if (qs->action == BLOBRAW) { - const uint8_t *buf; - size_t len; - int binary, r; - + if (qs->action == BLOBRAW || qs->action == BLOB) { error = got_get_repo_commits(c, 1); if (error) goto err; @@ -214,7 +214,40 @@ gotweb_process_request(struct request *c) &binary, c); if (error) goto err; + } + + switch(qs->action) { + case BLAME: + error = got_get_repo_commits(c, 1); + if (error) { + log_warnx("%s: %s", __func__, error->msg); + goto err; + } + if (gotweb_reply(c, 200, "text/html", NULL) == -1) + return; + gotweb_render_page(c->tp, gotweb_render_blame); + return; + case BLOB: + if (binary) { + struct gotweb_url url = { + .index_page = -1, + .page = -1, + .action = BLOBRAW, + .path = qs->path, + .commit = qs->commit, + .folder = qs->folder, + .file = qs->file, + }; + gotweb_reply(c, 302, NULL, &url); + return; + } + + if (gotweb_reply(c, 200, "text/html", NULL) == -1) + return; + gotweb_render_page(c->tp, gotweb_render_blob); + return; + case BLOBRAW: if (binary) r = gotweb_reply_file(c, "application/octet-stream", qs->file, NULL); @@ -232,68 +265,8 @@ gotweb_process_request(struct request *c) buf = got_object_blob_get_read_buf(c->t->blob); if (fcgi_gen_binary_response(c, buf, len) == -1) break; - } - - return; - } - - if (qs->action == BLOB) { - int binary; - struct gotweb_url url = { - .index_page = -1, - .page = -1, - .action = BLOBRAW, - .path = qs->path, - .commit = qs->commit, - .folder = qs->folder, - .file = qs->file, - }; - - error = got_get_repo_commits(c, 1); - if (error) - goto err; - - error = got_open_blob_for_output(&c->t->blob, &c->t->fd, - &binary, c); - if (error) - goto err; - if (binary) { - gotweb_reply(c, 302, NULL, &url); - return; } - } - - if (qs->action == RSS) { - const char *ctype = "application/rss+xml;charset=utf-8"; - - if (gotweb_reply_file(c, ctype, repo_dir->name, ".rss") == -1) - return; - - error = got_get_repo_tags(c, D_MAXSLCOMMDISP); - if (error) { - log_warnx("%s: %s", __func__, error->msg); - return; - } - gotweb_render_rss(c->tp); return; - } - - switch(qs->action) { - case BLAME: - error = got_get_repo_commits(c, 1); - if (error) { - log_warnx("%s: %s", __func__, error->msg); - goto err; - } - if (gotweb_reply(c, 200, "text/html", NULL) == -1) - return; - gotweb_render_page(c->tp, gotweb_render_blame); - return; - case BLOB: - if (gotweb_reply(c, 200, "text/html", NULL) == -1) - return; - gotweb_render_page(c->tp, gotweb_render_blob); - return; case BRIEFS: if (gotweb_reply(c, 200, "text/html", NULL) == -1) return; @@ -337,6 +310,15 @@ gotweb_process_request(struct request *c) return; gotweb_render_page(c->tp, gotweb_render_index); return; + case RSS: + error = got_get_repo_tags(c, D_MAXSLCOMMDISP); + if (error) + goto err; + if (gotweb_reply_file(c, rss_ctype, repo_dir->name, ".rss") + == -1) + return; + gotweb_render_rss(c->tp); + return; case SUMMARY: error = got_ref_list(&c->t->refs, c->t->repo, "refs/heads", got_ref_cmp_by_name, NULL);