commit 7f65bb55b8cfe0f964fd7cb845acfbc28621730e from: Omar Polo date: Fri Dec 01 19:33:28 2023 UTC gotwebd: add patch action to serve diffs in plain text ok tracey@ commit - 4ba8b606a0a1ebe0d9a9daf6909948315c313d36 commit + 7f65bb55b8cfe0f964fd7cb845acfbc28621730e blob - 45a8a36ea39f6f705bfc81c145d550389dd82872 blob + 769fcfb189a08622b7b60081be7781b819637fad --- gotwebd/got_operations.c +++ gotwebd/got_operations.c @@ -259,7 +259,7 @@ got_get_repo_commit(struct request *c, struct repo_com if (error) return error; - if (qs->action == DIFF) { + if (qs->action == DIFF || qs->action == PATCH) { parent_id = STAILQ_FIRST( got_object_commit_get_parent_ids(commit)); if (parent_id != NULL) { blob - e5f7034e08396bd55ab20a409d6dbd8d8acf4c88 blob + 5a9e5219a1429b6a682151e03ff69c6f506f26b2 --- gotwebd/gotweb.c +++ gotwebd/gotweb.c @@ -72,6 +72,7 @@ static const struct action_keys action_keys[] = { { "diff", DIFF }, { "error", ERR }, { "index", INDEX }, + { "patch", PATCH }, { "summary", SUMMARY }, { "tag", TAG }, { "tags", TAGS }, @@ -187,7 +188,8 @@ gotweb_process_request(struct request *c) */ if (qs->action == BLAME || qs->action == BLOB || - qs->action == BLOBRAW || qs->action == DIFF) { + qs->action == BLOBRAW || qs->action == DIFF || + qs->action == PATCH) { if (qs->commit == NULL) { error = got_error(GOT_ERR_BAD_QUERYSTRING); goto err; @@ -314,6 +316,21 @@ gotweb_process_request(struct request *c) return; gotweb_render_page(c->tp, gotweb_render_index); return; + case PATCH: + error = got_get_repo_commits(c, 1); + if (error) { + log_warnx("%s: %s", __func__, error->msg); + goto err; + } + error = got_open_diff_for_output(&c->t->fp, c); + if (error) { + log_warnx("%s: %s", __func__, error->msg); + goto err; + } + if (gotweb_reply(c, 200, "text/plain", NULL) == -1) + return; + gotweb_render_patch(c->tp); + return; case RSS: error = got_get_repo_tags(c, D_MAXSLCOMMDISP); if (error) @@ -987,6 +1004,8 @@ gotweb_action_name(int action) return "err"; case INDEX: return "index"; + case PATCH: + return "patch"; case SUMMARY: return "summary"; case TAG: blob - 8005d4db4e8e1da67b226c26b8e1640b5c42645d blob + 4cd99ce853542b1e2a0684ce76da6d122f7cf05a --- gotwebd/gotwebd.h +++ gotwebd/gotwebd.h @@ -436,6 +436,7 @@ enum query_actions { DIFF, ERR, INDEX, + PATCH, SUMMARY, TAG, TAGS, @@ -493,6 +494,7 @@ int gotweb_render_diff(struct template *); int gotweb_render_branches(struct template *, struct got_reflist_head *); int gotweb_render_summary(struct template *); int gotweb_render_blame(struct template *); +int gotweb_render_patch(struct template *); int gotweb_render_rss(struct template *); /* parse.y */ blob - bac391d8a08e90c6c0b28bba4f935029591ab0c8 blob + 10f919b21d90a1aaa02ec7f87e82570e56e481e0 --- gotwebd/pages.tmpl +++ gotwebd/pages.tmpl @@ -346,11 +346,18 @@ nextsep(char *s, char **t) struct querystring *qs = c->t->qs; struct repo_commit *rc; struct repo_dir *repo_dir = t->repo_dir; - struct gotweb_url diff_url, tree_url; + struct gotweb_url diff_url, patch_url, tree_url; char *tmp; diff_url = (struct gotweb_url){ .action = DIFF, + .index_page = -1, + .page = -1, + .path = repo_dir->name, + .headref = qs->headref, + }; + patch_url = (struct gotweb_url){ + .action = PATCH, .index_page = -1, .page = -1, .path = repo_dir->name, @@ -371,6 +378,7 @@ nextsep(char *s, char **t) {{ tailq-foreach rc &t->repo_commits entry }} {! diff_url.commit = rc->commit_id; + patch_url.commit = rc->commit_id; tree_url.commit = rc->commit_id; tmp = strchr(rc->committer, '<'); @@ -405,6 +413,8 @@ nextsep(char *s, char **t) @@ -479,7 +489,7 @@ nextsep(char *s, char **t) struct transport *t = c->t; struct repo_dir *repo_dir = t->repo_dir; struct repo_commit *rc; - struct gotweb_url diff, tree; + struct gotweb_url diff, patch, tree; diff = (struct gotweb_url){ .action = DIFF, @@ -487,6 +497,12 @@ nextsep(char *s, char **t) .page = -1, .path = repo_dir->name, }; + patch = (struct gotweb_url){ + .action = PATCH, + .index_page = -1, + .page = -1, + .path = repo_dir->name, + }; tree = (struct gotweb_url){ .action = TREE, .index_page = -1, @@ -501,6 +517,7 @@ nextsep(char *s, char **t) {{ tailq-foreach rc &t->repo_commits entry }} {! diff.commit = rc->commit_id; + patch.commit = rc->commit_id; tree.commit = rc->commit_id; !}