commit feaddee622f43226923713b48d635518d166e5e5 from: Omar Polo via: Thomas Adam date: Sun Dec 03 21:51:13 2023 UTC gotwebd: add patch action to serve diffs in plain text ok tracey@ commit - 83d26b5a9e22759c3b6527a68e5d2953720652f9 commit + feaddee622f43226923713b48d635518d166e5e5 blob - 493b0eb04d060577b13e460e71c376ff81efcaf0 blob + a61c40244d702d5e9cb4633eb08abed90853f4f3 --- 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 - 88fdbf3c6940353008b960a1fac5f50fcd1c3ce7 blob + 06ca65abbaad14c30a35126368ccc1133817c47c --- gotwebd/gotweb.c +++ gotwebd/gotweb.c @@ -71,6 +71,7 @@ static const struct action_keys action_keys[] = { { "diff", DIFF }, { "error", ERR }, { "index", INDEX }, + { "patch", PATCH }, { "summary", SUMMARY }, { "tag", TAG }, { "tags", TAGS }, @@ -186,7 +187,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; @@ -313,6 +315,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) @@ -986,6 +1003,8 @@ gotweb_action_name(int action) return "err"; case INDEX: return "index"; + case PATCH: + return "patch"; case SUMMARY: return "summary"; case TAG: blob - 5cc80cef226f35b18328aff9d58e25581e26d9e0 blob + 0f8dabd8f5dbe97f51673c139c7ac29805124338 --- gotwebd/gotwebd.h +++ gotwebd/gotwebd.h @@ -438,6 +438,7 @@ enum query_actions { DIFF, ERR, INDEX, + PATCH, SUMMARY, TAG, TAGS, @@ -495,6 +496,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 - 357b1db90c24be59648f929f542810f3c61c0fae blob + 756c636e366f60c02a51701359775f11387439ca --- 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; !}