2 * Copyright (c) 2019, 2020 Tracey Emery <tracey@traceyemery.net>
3 * Copyright (c) 2018, 2019 Stefan Sperling <stsp@openbsd.org>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <sys/queue.h>
20 #include <sys/types.h>
33 #include <got_object.h>
34 #include <got_reference.h>
35 #include <got_repository.h>
37 #include <got_cancel.h>
38 #include <got_worktree.h>
40 #include <got_commit_graph.h>
41 #include <got_blame.h>
42 #include <got_privsep.h>
43 #include <got_opentemp.h>
50 #include "gotweb_ui.h"
53 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
57 TAILQ_HEAD(dirs, gw_dir) gw_dirs;
58 struct gw_dir *gw_dir;
59 struct gotweb_conf *gw_conf;
60 struct ktemplate *gw_tmpl;
61 struct khtmlreq *gw_html_req;
72 unsigned int repos_total;
88 TAILQ_ENTRY(gw_dir) entry;
134 static const char *const templs[TEMPL__MAX] = {
144 static const struct kvalid gw_keys[KEY__ZMAX] = {
145 { kvalid_stringne, "action" },
146 { kvalid_stringne, "commit" },
147 { kvalid_stringne, "file" },
148 { kvalid_stringne, "folder" },
149 { kvalid_stringne, "headref" },
150 { kvalid_int, "page" },
151 { kvalid_stringne, "path" },
154 int gw_get_repo_log_count(struct trans *, char *);
156 static struct gw_dir *gw_init_gw_dir(char *);
158 static char *gw_get_repo_description(struct trans *,
160 static char *gw_get_repo_owner(struct trans *,
162 static char *gw_get_time_str(time_t, int);
163 static char *gw_get_repo_age(struct trans *,
164 char *, char *, int);
165 static char *gw_get_repo_log(struct trans *, const char *,
167 static char *gw_get_file_blame(struct trans *, char *);
168 static char *gw_get_repo_tree(struct trans *, char *);
169 static char *gw_get_repo_diff(struct trans *, char *,
171 static char *gw_get_repo_tags(struct trans *, int, int);
172 static char *gw_get_repo_heads(struct trans *);
173 static char *gw_get_clone_url(struct trans *, char *);
174 static char *gw_get_got_link(struct trans *);
175 static char *gw_get_site_link(struct trans *);
176 static char *gw_html_escape(const char *);
177 static char *color_diff_line(char *);
179 static void gw_display_open(struct trans *, enum khttp,
181 static void gw_display_index(struct trans *,
182 const struct got_error *);
184 static int gw_template(size_t, void *);
186 static const struct got_error* apply_unveil(const char *, const char *);
187 static const struct got_error* cmp_tags(void *, int *,
188 struct got_reference *,
189 struct got_reference *);
190 static const struct got_error* resolve_commit_arg(struct got_object_id **,
191 const char *, struct got_repository *);
192 static const struct got_error* match_object_id(struct got_object_id **,
193 char **, const char *r, int, int,
194 struct got_repository *);
195 static const struct got_error* blame_cb(void *, int, int,
196 struct got_object_id *);
197 static const struct got_error* gw_load_got_paths(struct trans *);
198 static const struct got_error* gw_load_got_path(struct trans *,
200 static const struct got_error* gw_parse_querystring(struct trans *);
201 static const struct got_error* match_logmsg(int *, struct got_object_id *,
202 struct got_commit_object *, regex_t *);
204 static const struct got_error* gw_blame(struct trans *);
205 static const struct got_error* gw_commit(struct trans *);
206 static const struct got_error* gw_commitdiff(struct trans *);
207 static const struct got_error* gw_index(struct trans *);
208 static const struct got_error* gw_log(struct trans *);
209 static const struct got_error* gw_raw(struct trans *);
210 static const struct got_error* gw_logbriefs(struct trans *);
211 static const struct got_error* gw_summary(struct trans *);
212 static const struct got_error* gw_tag(struct trans *);
213 static const struct got_error* gw_tree(struct trans *);
215 struct gw_query_action {
216 unsigned int func_id;
217 const char *func_name;
218 const struct got_error *(*func_main)(struct trans *);
222 enum gw_query_actions {
236 static struct gw_query_action gw_query_funcs[] = {
237 { GW_BLAME, "blame", gw_blame, "gw_tmpl/index.tmpl" },
238 { GW_COMMIT, "commit", gw_commit, "gw_tmpl/index.tmpl" },
239 { GW_COMMITDIFF, "commitdiff", gw_commitdiff, "gw_tmpl/index.tmpl" },
240 { GW_ERR, NULL, NULL, "gw_tmpl/index.tmpl" },
241 { GW_INDEX, "index", gw_index, "gw_tmpl/index.tmpl" },
242 { GW_LOG, "log", gw_log, "gw_tmpl/index.tmpl" },
243 { GW_RAW, "raw", gw_raw, "gw_tmpl/index.tmpl" },
244 { GW_LOGBRIEFS, "logbriefs", gw_logbriefs, "gw_tmpl/index.tmpl" },
245 { GW_SUMMARY, "summary", gw_summary, "gw_tmpl/index.tmpl" },
246 { GW_TAG, "tag", gw_tag, "gw_tmpl/index.tmpl" },
247 { GW_TREE, "tree", gw_tree, "gw_tmpl/index.tmpl" },
250 static const struct got_error *
251 apply_unveil(const char *repo_path, const char *repo_file)
253 const struct got_error *err;
255 if (repo_path && repo_file) {
257 if ((asprintf(&full_path, "%s/%s", repo_path, repo_file)) == -1)
258 return got_error_from_errno("asprintf unveil");
259 if (unveil(full_path, "r") != 0)
260 return got_error_from_errno2("unveil", full_path);
263 if (repo_path && unveil(repo_path, "r") != 0)
264 return got_error_from_errno2("unveil", repo_path);
266 if (unveil("/tmp", "rwc") != 0)
267 return got_error_from_errno2("unveil", "/tmp");
269 err = got_privsep_unveil_exec_helpers();
273 if (unveil(NULL, NULL) != 0)
274 return got_error_from_errno("unveil");
279 static const struct got_error *
280 cmp_tags(void *arg, int *cmp, struct got_reference *ref1,
281 struct got_reference *ref2)
283 const struct got_error *err = NULL;
284 struct got_repository *repo = arg;
285 struct got_object_id *id1, *id2 = NULL;
286 struct got_tag_object *tag1 = NULL, *tag2 = NULL;
291 err = got_ref_resolve(&id1, repo, ref1);
294 err = got_object_open_as_tag(&tag1, repo, id1);
298 err = got_ref_resolve(&id2, repo, ref2);
301 err = got_object_open_as_tag(&tag2, repo, id2);
305 time1 = got_object_tag_get_tagger_time(tag1);
306 time2 = got_object_tag_get_tagger_time(tag2);
308 /* Put latest tags first. */
311 else if (time1 > time2)
314 err = got_ref_cmp_by_name(NULL, cmp, ref2, ref1);
319 got_object_tag_close(tag1);
321 got_object_tag_close(tag2);
325 static const struct got_error *
326 resolve_commit_arg(struct got_object_id **commit_id,
327 const char *commit_id_arg, struct got_repository *repo)
329 const struct got_error *err;
330 struct got_reference *ref;
331 struct got_tag_object *tag;
333 err = got_repo_object_match_tag(&tag, commit_id_arg,
334 GOT_OBJ_TYPE_COMMIT, repo);
336 *commit_id = got_object_id_dup(
337 got_object_tag_get_object_id(tag));
338 if (*commit_id == NULL)
339 err = got_error_from_errno("got_object_id_dup");
340 got_object_tag_close(tag);
342 } else if (err->code != GOT_ERR_NO_OBJ)
345 err = got_ref_open(&ref, repo, commit_id_arg, 0);
347 err = got_ref_resolve(commit_id, repo, ref);
350 if (err->code != GOT_ERR_NOT_REF)
352 err = got_repo_match_object_id_prefix(commit_id,
353 commit_id_arg, GOT_OBJ_TYPE_COMMIT, repo);
358 static const struct got_error *
359 match_object_id(struct got_object_id **id, char **label,
360 const char *id_str, int obj_type, int resolve_tags,
361 struct got_repository *repo)
363 const struct got_error *err;
364 struct got_tag_object *tag;
365 struct got_reference *ref = NULL;
371 err = got_repo_object_match_tag(&tag, id_str, GOT_OBJ_TYPE_ANY,
374 *id = got_object_id_dup(
375 got_object_tag_get_object_id(tag));
377 err = got_error_from_errno("got_object_id_dup");
378 else if (asprintf(label, "refs/tags/%s",
379 got_object_tag_get_name(tag)) == -1) {
380 err = got_error_from_errno("asprintf");
384 got_object_tag_close(tag);
386 } else if (err->code != GOT_ERR_NO_OBJ)
390 err = got_repo_match_object_id_prefix(id, id_str, obj_type, repo);
392 if (err->code != GOT_ERR_BAD_OBJ_ID_STR)
394 err = got_ref_open(&ref, repo, id_str, 0);
397 *label = strdup(got_ref_get_name(ref));
398 if (*label == NULL) {
399 err = got_error_from_errno("strdup");
402 err = got_ref_resolve(id, repo, ref);
404 err = got_object_id_str(label, *id);
405 if (*label == NULL) {
406 err = got_error_from_errno("strdup");
417 gw_get_repo_log_count(struct trans *gw_trans, char *start_commit)
419 const struct got_error *error;
420 struct got_repository *repo = NULL;
421 struct got_reflist_head refs;
422 struct got_commit_object *commit = NULL;
423 struct got_object_id *id = NULL;
424 struct got_commit_graph *graph = NULL;
425 char *in_repo_path = NULL, *path = NULL;
428 error = got_repo_open(&repo, gw_trans->repo_path, NULL);
434 if (start_commit == NULL) {
435 struct got_reference *head_ref;
436 error = got_ref_open(&head_ref, repo, gw_trans->headref, 0);
440 error = got_ref_resolve(&id, repo, head_ref);
441 got_ref_close(head_ref);
445 error = got_object_open_as_commit(&commit, repo, id);
447 struct got_reference *ref;
448 error = got_ref_open(&ref, repo, start_commit, 0);
451 error = got_ref_resolve(&id, repo, ref);
455 error = got_object_get_type(&obj_type, repo, id);
458 if (obj_type == GOT_OBJ_TYPE_TAG) {
459 struct got_tag_object *tag;
460 error = got_object_open_as_tag(&tag, repo, id);
463 if (got_object_tag_get_object_type(tag) !=
464 GOT_OBJ_TYPE_COMMIT) {
465 got_object_tag_close(tag);
466 error = got_error(GOT_ERR_OBJ_TYPE);
470 id = got_object_id_dup(
471 got_object_tag_get_object_id(tag));
473 error = got_error_from_errno(
474 "got_object_id_dup");
475 got_object_tag_close(tag);
478 } else if (obj_type != GOT_OBJ_TYPE_COMMIT) {
479 error = got_error(GOT_ERR_OBJ_TYPE);
482 error = got_object_open_as_commit(&commit, repo, id);
486 if (commit == NULL) {
487 error = got_repo_match_object_id_prefix(&id,
488 start_commit, GOT_OBJ_TYPE_COMMIT, repo);
492 error = got_repo_match_object_id_prefix(&id,
493 start_commit, GOT_OBJ_TYPE_COMMIT, repo);
498 error = got_object_open_as_commit(&commit, repo, id);
502 error = got_repo_map_path(&in_repo_path, repo, gw_trans->repo_path, 1);
511 error = got_ref_list(&refs, repo, NULL, got_ref_cmp_by_name, NULL);
515 error = got_commit_graph_open(&graph, path, 0);
519 error = got_commit_graph_iter_start(graph, id, repo, NULL, NULL);
524 error = got_commit_graph_iter_next(&id, graph, repo, NULL,
527 if (error->code == GOT_ERR_ITER_COMPLETED)
541 got_commit_graph_close(graph);
543 error = got_repo_close(repo);
548 khttp_puts(gw_trans->gw_req, "Error: ");
549 khttp_puts(gw_trans->gw_req, error->msg);
555 static const struct got_error *
556 gw_blame(struct trans *gw_trans)
558 const struct got_error *error = NULL;
560 char *log, *log_html;
562 error = apply_unveil(gw_trans->gw_dir->path, NULL);
566 log = gw_get_repo_log(gw_trans, NULL, gw_trans->commit, 1, LOGBLAME);
568 if (log != NULL && strcmp(log, "") != 0) {
569 if ((asprintf(&log_html, log_blame, log)) == -1)
570 return got_error_from_errno("asprintf");
571 khttp_puts(gw_trans->gw_req, log_html);
578 static const struct got_error *
579 gw_commit(struct trans *gw_trans)
581 const struct got_error *error = NULL;
582 char *log, *log_html;
584 error = apply_unveil(gw_trans->gw_dir->path, NULL);
588 log = gw_get_repo_log(gw_trans, NULL, gw_trans->commit, 1, LOGCOMMIT);
590 if (log != NULL && strcmp(log, "") != 0) {
591 if ((asprintf(&log_html, log_commit, log)) == -1)
592 return got_error_from_errno("asprintf");
593 khttp_puts(gw_trans->gw_req, log_html);
600 static const struct got_error *
601 gw_commitdiff(struct trans *gw_trans)
603 const struct got_error *error = NULL;
604 char *log, *log_html;
606 error = apply_unveil(gw_trans->gw_dir->path, NULL);
610 log = gw_get_repo_log(gw_trans, NULL, gw_trans->commit, 1, LOGDIFF);
612 if (log != NULL && strcmp(log, "") != 0) {
613 if ((asprintf(&log_html, log_diff, log)) == -1)
614 return got_error_from_errno("asprintf");
615 khttp_puts(gw_trans->gw_req, log_html);
622 static const struct got_error *
623 gw_index(struct trans *gw_trans)
625 const struct got_error *error = NULL;
626 struct gw_dir *gw_dir = NULL;
627 char *html, *navs, *next, *prev;
628 unsigned int prev_disp = 0, next_disp = 1, dir_c = 0;
630 error = apply_unveil(gw_trans->gw_conf->got_repos_path, NULL);
634 error = gw_load_got_paths(gw_trans);
638 khttp_puts(gw_trans->gw_req, index_projects_header);
640 TAILQ_FOREACH(gw_dir, &gw_trans->gw_dirs, entry)
643 TAILQ_FOREACH(gw_dir, &gw_trans->gw_dirs, entry) {
644 if (gw_trans->page > 0 && (gw_trans->page *
645 gw_trans->gw_conf->got_max_repos_display) > prev_disp) {
651 if((asprintf(&navs, index_navs, gw_dir->name, gw_dir->name,
652 gw_dir->name, gw_dir->name)) == -1)
653 return got_error_from_errno("asprintf");
655 if ((asprintf(&html, index_projects, gw_dir->name, gw_dir->name,
656 gw_dir->description, gw_dir->owner, gw_dir->age,
658 return got_error_from_errno("asprintf");
660 khttp_puts(gw_trans->gw_req, html);
665 if (gw_trans->gw_conf->got_max_repos_display == 0)
668 if (next_disp == gw_trans->gw_conf->got_max_repos_display)
669 khttp_puts(gw_trans->gw_req, np_wrapper_start);
670 else if ((gw_trans->gw_conf->got_max_repos_display > 0) &&
671 (gw_trans->page > 0) &&
672 (next_disp == gw_trans->gw_conf->got_max_repos_display ||
673 prev_disp == gw_trans->repos_total))
674 khttp_puts(gw_trans->gw_req, np_wrapper_start);
676 if ((gw_trans->gw_conf->got_max_repos_display > 0) &&
677 (gw_trans->page > 0) &&
678 (next_disp == gw_trans->gw_conf->got_max_repos_display ||
679 prev_disp == gw_trans->repos_total)) {
680 if ((asprintf(&prev, nav_prev,
681 gw_trans->page - 1)) == -1)
682 return got_error_from_errno("asprintf");
683 khttp_puts(gw_trans->gw_req, prev);
687 khttp_puts(gw_trans->gw_req, div_end);
689 if (gw_trans->gw_conf->got_max_repos_display > 0 &&
690 next_disp == gw_trans->gw_conf->got_max_repos_display &&
691 dir_c != (gw_trans->page + 1) *
692 gw_trans->gw_conf->got_max_repos_display) {
693 if ((asprintf(&next, nav_next,
694 gw_trans->page + 1)) == -1)
695 return got_error_from_errno("calloc");
696 khttp_puts(gw_trans->gw_req, next);
697 khttp_puts(gw_trans->gw_req, div_end);
703 if ((gw_trans->gw_conf->got_max_repos_display > 0) &&
704 (gw_trans->page > 0) &&
705 (next_disp == gw_trans->gw_conf->got_max_repos_display ||
706 prev_disp == gw_trans->repos_total))
707 khttp_puts(gw_trans->gw_req, div_end);
714 static const struct got_error *
715 gw_log(struct trans *gw_trans)
717 const struct got_error *error = NULL;
718 char *log, *log_html;
720 error = apply_unveil(gw_trans->gw_dir->path, NULL);
724 log = gw_get_repo_log(gw_trans, NULL, gw_trans->commit,
725 gw_trans->gw_conf->got_max_commits_display, LOGFULL);
727 if (log != NULL && strcmp(log, "") != 0) {
728 if ((asprintf(&log_html, logs, log)) == -1)
729 return got_error_from_errno("asprintf");
730 khttp_puts(gw_trans->gw_req, log_html);
737 static const struct got_error *
738 gw_raw(struct trans *gw_trans)
740 const struct got_error *error = NULL;
745 static const struct got_error *
746 gw_logbriefs(struct trans *gw_trans)
748 const struct got_error *error = NULL;
749 char *log, *log_html;
751 error = apply_unveil(gw_trans->gw_dir->path, NULL);
755 log = gw_get_repo_log(gw_trans, NULL, gw_trans->commit,
756 gw_trans->gw_conf->got_max_commits_display, LOGBRIEF);
758 if (log != NULL && strcmp(log, "") != 0) {
759 if ((asprintf(&log_html, summary_logbriefs,
761 return got_error_from_errno("asprintf");
762 khttp_puts(gw_trans->gw_req, log_html);
769 static const struct got_error *
770 gw_summary(struct trans *gw_trans)
772 const struct got_error *error = NULL;
773 char *description_html, *repo_owner_html, *repo_age_html,
774 *cloneurl_html, *log, *log_html, *tags, *heads, *tags_html,
777 error = apply_unveil(gw_trans->gw_dir->path, NULL);
781 khttp_puts(gw_trans->gw_req, summary_wrapper);
782 if (gw_trans->gw_conf->got_show_repo_description) {
783 if (gw_trans->gw_dir->description != NULL &&
784 (strcmp(gw_trans->gw_dir->description, "") != 0)) {
785 if ((asprintf(&description_html, description,
786 gw_trans->gw_dir->description)) == -1)
787 return got_error_from_errno("asprintf");
789 khttp_puts(gw_trans->gw_req, description_html);
790 free(description_html);
794 if (gw_trans->gw_conf->got_show_repo_owner) {
795 if (gw_trans->gw_dir->owner != NULL &&
796 (strcmp(gw_trans->gw_dir->owner, "") != 0)) {
797 if ((asprintf(&repo_owner_html, repo_owner,
798 gw_trans->gw_dir->owner)) == -1)
799 return got_error_from_errno("asprintf");
801 khttp_puts(gw_trans->gw_req, repo_owner_html);
802 free(repo_owner_html);
806 if (gw_trans->gw_conf->got_show_repo_age) {
807 age = gw_get_repo_age(gw_trans, gw_trans->gw_dir->path,
808 "refs/heads", TM_LONG);
809 if (age != NULL && (strcmp(age, "") != 0)) {
810 if ((asprintf(&repo_age_html, last_change, age)) == -1)
811 return got_error_from_errno("asprintf");
813 khttp_puts(gw_trans->gw_req, repo_age_html);
819 if (gw_trans->gw_conf->got_show_repo_cloneurl) {
820 if (gw_trans->gw_dir->url != NULL &&
821 (strcmp(gw_trans->gw_dir->url, "") != 0)) {
822 if ((asprintf(&cloneurl_html, cloneurl,
823 gw_trans->gw_dir->url)) == -1)
824 return got_error_from_errno("asprintf");
826 khttp_puts(gw_trans->gw_req, cloneurl_html);
830 khttp_puts(gw_trans->gw_req, div_end);
832 log = gw_get_repo_log(gw_trans, NULL, NULL, D_MAXSLCOMMDISP, 0);
833 tags = gw_get_repo_tags(gw_trans, D_MAXSLCOMMDISP, TAGBRIEF);
834 heads = gw_get_repo_heads(gw_trans);
836 if (log != NULL && strcmp(log, "") != 0) {
837 if ((asprintf(&log_html, summary_logbriefs,
839 return got_error_from_errno("asprintf");
840 khttp_puts(gw_trans->gw_req, log_html);
845 if (tags != NULL && strcmp(tags, "") != 0) {
846 if ((asprintf(&tags_html, summary_tags,
848 return got_error_from_errno("asprintf");
849 khttp_puts(gw_trans->gw_req, tags_html);
854 if (heads != NULL && strcmp(heads, "") != 0) {
855 if ((asprintf(&heads_html, summary_heads,
857 return got_error_from_errno("asprintf");
858 khttp_puts(gw_trans->gw_req, heads_html);
865 static const struct got_error *
866 gw_tag(struct trans *gw_trans)
868 const struct got_error *error = NULL;
869 char *log, *log_html;
871 error = apply_unveil(gw_trans->gw_dir->path, NULL);
875 log = gw_get_repo_log(gw_trans, NULL, gw_trans->commit, 1, LOGTAG);
877 if (log != NULL && strcmp(log, "") != 0) {
878 if ((asprintf(&log_html, log_tag, log)) == -1)
879 return got_error_from_errno("asprintf");
880 khttp_puts(gw_trans->gw_req, log_html);
887 static const struct got_error *
888 gw_tree(struct trans *gw_trans)
890 const struct got_error *error = NULL;
891 char *log, *log_html;
893 error = apply_unveil(gw_trans->gw_dir->path, NULL);
897 log = gw_get_repo_log(gw_trans, NULL, gw_trans->commit, 1, LOGTREE);
899 if (log != NULL && strcmp(log, "") != 0) {
900 if ((asprintf(&log_html, log_tree, log)) == -1)
901 return got_error_from_errno("asprintf");
902 khttp_puts(gw_trans->gw_req, log_html);
909 static const struct got_error *
910 gw_load_got_path(struct trans *gw_trans, struct gw_dir *gw_dir)
912 const struct got_error *error = NULL;
917 if ((asprintf(&dir_test, "%s/%s/%s",
918 gw_trans->gw_conf->got_repos_path, gw_dir->name,
919 GOTWEB_GIT_DIR)) == -1)
920 return got_error_from_errno("asprintf");
922 dt = opendir(dir_test);
926 gw_dir->path = strdup(dir_test);
931 if ((asprintf(&dir_test, "%s/%s/%s",
932 gw_trans->gw_conf->got_repos_path, gw_dir->name,
933 GOTWEB_GOT_DIR)) == -1)
934 return got_error_from_errno("asprintf");
936 dt = opendir(dir_test);
941 error = got_error(GOT_ERR_NOT_GIT_REPO);
945 if ((asprintf(&dir_test, "%s/%s",
946 gw_trans->gw_conf->got_repos_path, gw_dir->name)) == -1)
947 return got_error_from_errno("asprintf");
949 gw_dir->path = strdup(dir_test);
952 gw_dir->description = gw_get_repo_description(gw_trans,
954 gw_dir->owner = gw_get_repo_owner(gw_trans, gw_dir->path);
955 gw_dir->age = gw_get_repo_age(gw_trans, gw_dir->path, "refs/heads",
957 gw_dir->url = gw_get_clone_url(gw_trans, gw_dir->path);
966 static const struct got_error *
967 gw_load_got_paths(struct trans *gw_trans)
969 const struct got_error *error = NULL;
971 struct dirent **sd_dent;
972 struct gw_dir *gw_dir;
974 unsigned int d_cnt, d_i;
976 d = opendir(gw_trans->gw_conf->got_repos_path);
978 error = got_error_from_errno2("opendir",
979 gw_trans->gw_conf->got_repos_path);
983 d_cnt = scandir(gw_trans->gw_conf->got_repos_path, &sd_dent, NULL,
986 error = got_error_from_errno2("scandir",
987 gw_trans->gw_conf->got_repos_path);
991 for (d_i = 0; d_i < d_cnt; d_i++) {
992 if (gw_trans->gw_conf->got_max_repos > 0 &&
993 (d_i - 2) == gw_trans->gw_conf->got_max_repos)
994 break; /* account for parent and self */
996 if (strcmp(sd_dent[d_i]->d_name, ".") == 0 ||
997 strcmp(sd_dent[d_i]->d_name, "..") == 0)
1000 if ((gw_dir = gw_init_gw_dir(sd_dent[d_i]->d_name)) == NULL)
1001 return got_error_from_errno("gw_dir malloc");
1003 error = gw_load_got_path(gw_trans, gw_dir);
1004 if (error && error->code == GOT_ERR_NOT_GIT_REPO)
1009 if (lstat(gw_dir->path, &st) == 0 && S_ISDIR(st.st_mode) &&
1010 !got_path_dir_is_empty(gw_dir->path)) {
1011 TAILQ_INSERT_TAIL(&gw_trans->gw_dirs, gw_dir,
1013 gw_trans->repos_total++;
1021 static const struct got_error *
1022 gw_parse_querystring(struct trans *gw_trans)
1024 const struct got_error *error = NULL;
1026 struct gw_query_action *action = NULL;
1029 if (gw_trans->gw_req->fieldnmap[0]) {
1030 error = got_error_from_errno("bad parse");
1032 } else if ((p = gw_trans->gw_req->fieldmap[KEY_PATH])) {
1033 /* define gw_trans->repo_path */
1034 if ((asprintf(&gw_trans->repo_name, "%s", p->parsed.s)) == -1)
1035 return got_error_from_errno("asprintf");
1037 if ((asprintf(&gw_trans->repo_path, "%s/%s",
1038 gw_trans->gw_conf->got_repos_path, p->parsed.s)) == -1)
1039 return got_error_from_errno("asprintf");
1041 /* get action and set function */
1042 if ((p = gw_trans->gw_req->fieldmap[KEY_ACTION]))
1043 for (i = 0; i < nitems(gw_query_funcs); i++) {
1044 action = &gw_query_funcs[i];
1045 if (action->func_name == NULL)
1048 if (strcmp(action->func_name,
1049 p->parsed.s) == 0) {
1050 gw_trans->action = i;
1051 if ((asprintf(&gw_trans->action_name,
1052 "%s", action->func_name)) == -1)
1054 got_error_from_errno(
1063 if ((p = gw_trans->gw_req->fieldmap[KEY_COMMIT_ID]))
1064 if ((asprintf(&gw_trans->commit, "%s",
1065 p->parsed.s)) == -1)
1066 return got_error_from_errno("asprintf");
1068 if ((p = gw_trans->gw_req->fieldmap[KEY_FILE]))
1069 if ((asprintf(&gw_trans->repo_file, "%s",
1070 p->parsed.s)) == -1)
1071 return got_error_from_errno("asprintf");
1073 if ((p = gw_trans->gw_req->fieldmap[KEY_FOLDER]))
1074 if ((asprintf(&gw_trans->repo_folder, "%s",
1075 p->parsed.s)) == -1)
1076 return got_error_from_errno("asprintf");
1078 if ((p = gw_trans->gw_req->fieldmap[KEY_HEADREF]))
1079 if ((asprintf(&gw_trans->headref, "%s",
1080 p->parsed.s)) == -1)
1081 return got_error_from_errno("asprintf");
1083 if (action == NULL) {
1084 error = got_error_from_errno("invalid action");
1087 if ((gw_trans->gw_dir =
1088 gw_init_gw_dir(gw_trans->repo_name)) == NULL)
1089 return got_error_from_errno("gw_dir malloc");
1091 error = gw_load_got_path(gw_trans, gw_trans->gw_dir);
1095 gw_trans->action = GW_INDEX;
1097 if ((p = gw_trans->gw_req->fieldmap[KEY_PAGE]))
1098 gw_trans->page = p->parsed.i;
1100 if (gw_trans->action == GW_RAW)
1101 gw_trans->mime = KMIME_TEXT_PLAIN;
1106 static struct gw_dir *
1107 gw_init_gw_dir(char *dir)
1109 struct gw_dir *gw_dir;
1111 if ((gw_dir = malloc(sizeof(*gw_dir))) == NULL)
1114 if ((asprintf(&gw_dir->name, "%s", dir)) == -1)
1120 static const struct got_error*
1121 match_logmsg(int *have_match, struct got_object_id *id,
1122 struct got_commit_object *commit, regex_t *regex)
1124 const struct got_error *err = NULL;
1125 regmatch_t regmatch;
1126 char *id_str = NULL, *logmsg = NULL;
1130 err = got_object_id_str(&id_str, id);
1134 err = got_object_commit_get_logmsg(&logmsg, commit);
1138 if (regexec(regex, logmsg, 1, ®match, 0) == 0)
1147 gw_display_open(struct trans *gw_trans, enum khttp code, enum kmime mime)
1149 khttp_head(gw_trans->gw_req, kresps[KRESP_ALLOW], "GET");
1150 khttp_head(gw_trans->gw_req, kresps[KRESP_STATUS], "%s",
1152 khttp_head(gw_trans->gw_req, kresps[KRESP_CONTENT_TYPE], "%s",
1154 khttp_head(gw_trans->gw_req, "X-Content-Type-Options", "nosniff");
1155 khttp_head(gw_trans->gw_req, "X-Frame-Options", "DENY");
1156 khttp_head(gw_trans->gw_req, "X-XSS-Protection", "1; mode=block");
1157 khttp_body(gw_trans->gw_req);
1161 gw_display_index(struct trans *gw_trans, const struct got_error *err)
1163 gw_display_open(gw_trans, KHTTP_200, gw_trans->mime);
1164 khtml_open(gw_trans->gw_html_req, gw_trans->gw_req, 0);
1167 khttp_puts(gw_trans->gw_req, err->msg);
1169 khttp_template(gw_trans->gw_req, gw_trans->gw_tmpl,
1170 gw_query_funcs[gw_trans->action].template);
1172 khtml_close(gw_trans->gw_html_req);
1176 gw_template(size_t key, void *arg)
1178 const struct got_error *error = NULL;
1179 struct trans *gw_trans = arg;
1180 char *gw_got_link, *gw_site_link;
1181 char *site_owner_name, *site_owner_name_h;
1185 khttp_puts(gw_trans->gw_req, head);
1188 gw_got_link = gw_get_got_link(gw_trans);
1189 if (gw_got_link != NULL)
1190 khttp_puts(gw_trans->gw_req, gw_got_link);
1194 case (TEMPL_SITEPATH):
1195 gw_site_link = gw_get_site_link(gw_trans);
1196 if (gw_site_link != NULL)
1197 khttp_puts(gw_trans->gw_req, gw_site_link);
1202 if (gw_trans->gw_conf->got_site_name != NULL)
1203 khtml_puts(gw_trans->gw_html_req,
1204 gw_trans->gw_conf->got_site_name);
1207 case (TEMPL_SEARCH):
1208 khttp_puts(gw_trans->gw_req, search);
1210 case(TEMPL_SITEOWNER):
1211 if (gw_trans->gw_conf->got_site_owner != NULL &&
1212 gw_trans->gw_conf->got_show_site_owner) {
1214 gw_html_escape(gw_trans->gw_conf->got_site_owner);
1215 if ((asprintf(&site_owner_name_h, site_owner,
1220 khttp_puts(gw_trans->gw_req, site_owner_name_h);
1221 free(site_owner_name);
1222 free(site_owner_name_h);
1225 case(TEMPL_CONTENT):
1226 error = gw_query_funcs[gw_trans->action].func_main(gw_trans);
1228 khttp_puts(gw_trans->gw_req, error->msg);
1239 gw_get_repo_description(struct trans *gw_trans, char *dir)
1242 char *description = NULL, *d_file = NULL;
1245 if (gw_trans->gw_conf->got_show_repo_description == false)
1248 if ((asprintf(&d_file, "%s/description", dir)) == -1)
1251 if ((f = fopen(d_file, "r")) == NULL)
1254 fseek(f, 0, SEEK_END);
1256 fseek(f, 0, SEEK_SET);
1257 if ((description = calloc(len, sizeof(char *))) == NULL)
1260 fread(description, 1, len, f);
1265 if ((asprintf(&description, "%s", "")) == -1)
1272 gw_get_time_str(time_t committer_time, int ref_tm)
1276 char *years = "years ago", *months = "months ago";
1277 char *weeks = "weeks ago", *days = "days ago", *hours = "hours ago";
1278 char *minutes = "minutes ago", *seconds = "seconds ago";
1279 char *now = "right now";
1285 diff_time = time(NULL) - committer_time;
1286 if (diff_time > 60 * 60 * 24 * 365 * 2) {
1287 if ((asprintf(&repo_age, "%lld %s",
1288 (diff_time / 60 / 60 / 24 / 365), years)) == -1)
1290 } else if (diff_time > 60 * 60 * 24 * (365 / 12) * 2) {
1291 if ((asprintf(&repo_age, "%lld %s",
1292 (diff_time / 60 / 60 / 24 / (365 / 12)),
1295 } else if (diff_time > 60 * 60 * 24 * 7 * 2) {
1296 if ((asprintf(&repo_age, "%lld %s",
1297 (diff_time / 60 / 60 / 24 / 7), weeks)) == -1)
1299 } else if (diff_time > 60 * 60 * 24 * 2) {
1300 if ((asprintf(&repo_age, "%lld %s",
1301 (diff_time / 60 / 60 / 24), days)) == -1)
1303 } else if (diff_time > 60 * 60 * 2) {
1304 if ((asprintf(&repo_age, "%lld %s",
1305 (diff_time / 60 / 60), hours)) == -1)
1307 } else if (diff_time > 60 * 2) {
1308 if ((asprintf(&repo_age, "%lld %s", (diff_time / 60),
1311 } else if (diff_time > 2) {
1312 if ((asprintf(&repo_age, "%lld %s", diff_time,
1316 if ((asprintf(&repo_age, "%s", now)) == -1)
1321 if (gmtime_r(&committer_time, &tm) == NULL)
1324 s = asctime_r(&tm, datebuf);
1328 if ((asprintf(&repo_age, "%s UTC", datebuf)) == -1)
1336 gw_get_repo_age(struct trans *gw_trans, char *dir, char *repo_ref, int ref_tm)
1338 const struct got_error *error = NULL;
1339 struct got_object_id *id = NULL;
1340 struct got_repository *repo = NULL;
1341 struct got_commit_object *commit = NULL;
1342 struct got_reflist_head refs;
1343 struct got_reflist_entry *re;
1344 struct got_reference *head_ref;
1346 time_t committer_time = 0, cmp_time = 0;
1347 const char *refname;
1348 char *repo_age = NULL;
1350 if (repo_ref == NULL)
1353 if (strncmp(repo_ref, "refs/heads/", 11) == 0)
1356 SIMPLEQ_INIT(&refs);
1357 if (gw_trans->gw_conf->got_show_repo_age == false) {
1358 if ((asprintf(&repo_age, "")) == -1)
1363 error = got_repo_open(&repo, dir, NULL);
1368 error = got_ref_list(&refs, repo, "refs/heads",
1369 got_ref_cmp_by_name, NULL);
1371 error = got_ref_list(&refs, repo, repo_ref,
1372 got_ref_cmp_by_name, NULL);
1376 SIMPLEQ_FOREACH(re, &refs, entry) {
1378 refname = strdup(repo_ref);
1380 refname = got_ref_get_name(re->ref);
1381 error = got_ref_open(&head_ref, repo, refname, 0);
1385 error = got_ref_resolve(&id, repo, head_ref);
1386 got_ref_close(head_ref);
1390 error = got_object_open_as_commit(&commit, repo, id);
1395 got_object_commit_get_committer_time(commit);
1397 if (cmp_time < committer_time)
1398 cmp_time = committer_time;
1401 if (cmp_time != 0) {
1402 committer_time = cmp_time;
1403 repo_age = gw_get_time_str(committer_time, ref_tm);
1405 if ((asprintf(&repo_age, "")) == -1)
1407 got_ref_list_free(&refs);
1411 if ((asprintf(&repo_age, "%s", error->msg)) == -1)
1418 gw_get_repo_diff(struct trans *gw_trans, char *id_str1, char *id_str2)
1420 const struct got_error *error;
1422 struct got_object_id *id1 = NULL, *id2 = NULL;
1423 struct got_repository *repo = NULL;
1424 struct buf *diffbuf = NULL;
1425 char *label1 = NULL, *label2 = NULL, *diff_html = NULL, *buf = NULL,
1434 error = buf_alloc(&diffbuf, 0);
1438 error = got_repo_open(&repo, gw_trans->repo_path, NULL);
1442 error = match_object_id(&id1, &label1, id_str1, GOT_OBJ_TYPE_ANY, 1,
1448 error = match_object_id(&id2, &label2, id_str2,
1449 GOT_OBJ_TYPE_ANY, 1, repo);
1453 error = got_object_get_type(&type2, repo, id2);
1458 error = got_object_get_type(&type1, repo, id1);
1462 if (id_str2 && type1 != type2) {
1463 error = got_error(GOT_ERR_OBJ_TYPE);
1468 case GOT_OBJ_TYPE_BLOB:
1469 error = got_diff_objects_as_blobs(id2, id1, NULL, NULL, 3, 0,
1472 case GOT_OBJ_TYPE_TREE:
1473 error = got_diff_objects_as_trees(id2, id1, "", "", 3, 0, repo,
1476 case GOT_OBJ_TYPE_COMMIT:
1477 error = got_diff_objects_as_commits(id2, id1, 3, 0, repo, f);
1480 error = got_error(GOT_ERR_OBJ_TYPE);
1483 if ((buf = calloc(128, sizeof(char *))) == NULL)
1486 fseek(f, 0, SEEK_SET);
1488 while ((fgets(buf, 128, f)) != NULL) {
1489 buf_color = color_diff_line(buf);
1490 error = buf_puts(&newsize, diffbuf, buf_color);
1494 error = buf_puts(&newsize, diffbuf, div_end);
1499 if (buf_len(diffbuf) > 0) {
1500 error = buf_putc(diffbuf, '\0');
1501 diff_html = strdup(buf_get(diffbuf));
1513 got_repo_close(repo);
1522 gw_get_repo_owner(struct trans *gw_trans, char *dir)
1525 char *owner = NULL, *d_file = NULL;
1526 char *gotweb = "[gotweb]", *gitweb = "[gitweb]", *gw_owner = "owner";
1527 char *comp, *pos, *buf;
1530 if (gw_trans->gw_conf->got_show_repo_owner == false)
1533 if ((asprintf(&d_file, "%s/config", dir)) == -1)
1536 if ((f = fopen(d_file, "r")) == NULL)
1539 if ((buf = calloc(128, sizeof(char *))) == NULL)
1542 while ((fgets(buf, 128, f)) != NULL) {
1543 if ((pos = strstr(buf, gotweb)) != NULL)
1546 if ((pos = strstr(buf, gitweb)) != NULL)
1555 } while ((comp = strcasestr(buf, gw_owner)) == NULL);
1560 if (strncmp(gw_owner, comp, strlen(gw_owner)) != 0)
1563 for (i = 0; i < 2; i++) {
1564 owner = strsep(&buf, "\"");
1574 if ((asprintf(&owner, "%s", "")) == -1)
1581 gw_get_clone_url(struct trans *gw_trans, char *dir)
1584 char *url = NULL, *d_file = NULL;
1587 if ((asprintf(&d_file, "%s/cloneurl", dir)) == -1)
1590 if ((f = fopen(d_file, "r")) == NULL)
1593 fseek(f, 0, SEEK_END);
1595 fseek(f, 0, SEEK_SET);
1597 if ((url = calloc(len, sizeof(char *))) == NULL)
1600 fread(url, 1, len, f);
1607 gw_get_repo_log(struct trans *gw_trans, const char *search_pattern,
1608 char *start_commit, int limit, int log_type)
1610 const struct got_error *error;
1611 struct got_repository *repo = NULL;
1612 struct got_reflist_head refs;
1613 struct got_reflist_entry *re;
1614 struct got_commit_object *commit = NULL;
1615 struct got_object_id *id1 = NULL, *id2 = NULL;
1616 struct got_object_qid *parent_id;
1617 struct got_commit_graph *graph = NULL;
1618 char *logs = NULL, *id_str1 = NULL, *id_str2 = NULL, *path = NULL,
1619 *in_repo_path = NULL, *refs_str = NULL, *refs_str_disp = NULL,
1620 *treeid = NULL, *commit_row = NULL, *commit_commit = NULL,
1621 *commit_commit_disp = NULL, *commit_age_diff = NULL,
1622 *commit_age_diff_disp = NULL, *commit_age_long = NULL,
1623 *commit_age_long_disp = NULL, *commit_author = NULL,
1624 *commit_author_disp = NULL, *commit_committer = NULL,
1625 *commit_committer_disp = NULL, *commit_log = NULL,
1626 *commit_log_disp = NULL, *commit_parent = NULL,
1627 *commit_diff_disp = NULL, *logbriefs_navs_html = NULL,
1628 *log_tree_html = NULL, *log_commit_html = NULL,
1629 *log_diff_html = NULL, *commit_tree = NULL,
1630 *commit_tree_disp = NULL, *log_tag_html = NULL,
1631 *log_blame_html = NULL;
1632 char *commit_log0, *newline;
1634 int have_match, log_count = 0, has_parent = 1;
1636 struct buf *diffbuf = NULL;
1637 time_t committer_time;
1639 if (gw_trans->action == GW_LOG || gw_trans->action == GW_LOGBRIEFS)
1640 log_count = gw_get_repo_log_count(gw_trans, start_commit);
1642 error = buf_alloc(&diffbuf, 0);
1646 if (search_pattern &&
1647 regcomp(®ex, search_pattern, REG_EXTENDED | REG_NOSUB |
1651 error = got_repo_open(&repo, gw_trans->repo_path, NULL);
1655 SIMPLEQ_INIT(&refs);
1657 if (start_commit == NULL) {
1658 struct got_reference *head_ref;
1659 error = got_ref_open(&head_ref, repo, gw_trans->headref, 0);
1663 error = got_ref_resolve(&id1, repo, head_ref);
1664 got_ref_close(head_ref);
1668 error = got_object_open_as_commit(&commit, repo, id1);
1670 struct got_reference *ref;
1671 error = got_ref_open(&ref, repo, start_commit, 0);
1672 if (error == NULL) {
1674 error = got_ref_resolve(&id1, repo, ref);
1678 error = got_object_get_type(&obj_type, repo, id1);
1681 if (obj_type == GOT_OBJ_TYPE_TAG) {
1682 struct got_tag_object *tag;
1683 error = got_object_open_as_tag(&tag, repo, id1);
1686 if (got_object_tag_get_object_type(tag) !=
1687 GOT_OBJ_TYPE_COMMIT) {
1688 got_object_tag_close(tag);
1689 error = got_error(GOT_ERR_OBJ_TYPE);
1693 id1 = got_object_id_dup(
1694 got_object_tag_get_object_id(tag));
1696 error = got_error_from_errno(
1697 "got_object_id_dup");
1698 got_object_tag_close(tag);
1701 } else if (obj_type != GOT_OBJ_TYPE_COMMIT) {
1702 error = got_error(GOT_ERR_OBJ_TYPE);
1705 error = got_object_open_as_commit(&commit, repo, id1);
1709 if (commit == NULL) {
1710 error = got_repo_match_object_id_prefix(&id1,
1711 start_commit, GOT_OBJ_TYPE_COMMIT, repo);
1715 error = got_repo_match_object_id_prefix(&id1,
1716 start_commit, GOT_OBJ_TYPE_COMMIT, repo);
1722 error = got_repo_map_path(&in_repo_path, repo, gw_trans->repo_path, 1);
1728 path = in_repo_path;
1731 error = got_ref_list(&refs, repo, NULL, got_ref_cmp_by_name, NULL);
1735 error = got_commit_graph_open(&graph, path, 0);
1739 error = got_commit_graph_iter_start(graph, id1, repo, NULL, NULL);
1744 error = got_commit_graph_iter_next(&id1, graph, repo, NULL,
1747 if (error->code == GOT_ERR_ITER_COMPLETED)
1754 error = got_object_open_as_commit(&commit, repo, id1);
1758 if (search_pattern) {
1759 error = match_logmsg(&have_match, id1, commit,
1762 got_object_commit_close(commit);
1765 if (have_match == 0) {
1766 got_object_commit_close(commit);
1771 SIMPLEQ_FOREACH(re, &refs, entry) {
1774 struct got_tag_object *tag = NULL;
1777 name = got_ref_get_name(re->ref);
1778 if (strcmp(name, GOT_REF_HEAD) == 0)
1780 if (strncmp(name, "refs/", 5) == 0)
1782 if (strncmp(name, "got/", 4) == 0)
1784 if (strncmp(name, "heads/", 6) == 0)
1786 if (strncmp(name, "remotes/", 8) == 0)
1788 if (strncmp(name, "tags/", 5) == 0) {
1789 error = got_object_open_as_tag(&tag, repo,
1792 if (error->code != GOT_ERR_OBJ_TYPE)
1795 * Ref points at something other
1802 cmp = got_object_id_cmp(tag ?
1803 got_object_tag_get_object_id(tag) : re->id, id1);
1805 got_object_tag_close(tag);
1809 if ((asprintf(&refs_str, "%s%s%s", s ? s : "",
1810 s ? ", " : "", name)) == -1) {
1811 error = got_error_from_errno("asprintf");
1818 if (refs_str == NULL)
1819 refs_str_disp = strdup("");
1821 if ((asprintf(&refs_str_disp, "(%s)",
1823 error = got_error_from_errno("asprintf");
1829 error = got_object_id_str(&id_str1, id1);
1833 error = got_object_id_str(&treeid,
1834 got_object_commit_get_tree_id(commit));
1838 if (gw_trans->action == GW_COMMIT ||
1839 gw_trans->action == GW_COMMITDIFF) {
1842 got_object_commit_get_parent_ids(commit));
1843 if (parent_id != NULL) {
1844 id2 = got_object_id_dup(parent_id->id);
1846 error = got_object_id_str(&id_str2, id2);
1852 id_str2 = strdup("/dev/null");
1857 got_object_commit_get_committer_time(commit);
1859 if ((asprintf(&commit_parent, "%s", id_str2)) == -1) {
1860 error = got_error_from_errno("asprintf");
1864 if ((asprintf(&commit_tree, "%s", treeid)) == -1) {
1865 error = got_error_from_errno("asprintf");
1869 if ((asprintf(&commit_tree_disp, commit_tree_html,
1871 error = got_error_from_errno("asprintf");
1875 if ((asprintf(&commit_diff_disp, commit_diff_html, id_str2,
1877 error = got_error_from_errno("asprintf");
1881 if ((asprintf(&commit_commit, "%s", id_str1)) == -1) {
1882 error = got_error_from_errno("asprintf");
1886 if ((asprintf(&commit_commit_disp, commit_commit_html,
1887 commit_commit, refs_str_disp)) == -1) {
1888 error = got_error_from_errno("asprintf");
1892 if ((asprintf(&commit_age_long, "%s",
1893 gw_get_time_str(committer_time, TM_LONG))) == -1) {
1894 error = got_error_from_errno("asprintf");
1898 if ((asprintf(&commit_age_long_disp, commit_age_html,
1899 commit_age_long)) == -1) {
1900 error = got_error_from_errno("asprintf");
1904 if ((asprintf(&commit_age_diff, "%s",
1905 gw_get_time_str(committer_time, TM_DIFF))) == -1) {
1906 error = got_error_from_errno("asprintf");
1910 if ((asprintf(&commit_age_diff_disp, commit_age_html,
1911 commit_age_diff)) == -1) {
1912 error = got_error_from_errno("asprintf");
1916 if ((asprintf(&commit_author, "%s",
1917 got_object_commit_get_author(commit))) == -1) {
1918 error = got_error_from_errno("asprintf");
1922 if ((asprintf(&commit_author_disp, commit_author_html,
1923 gw_html_escape(commit_author))) == -1) {
1924 error = got_error_from_errno("asprintf");
1928 if ((asprintf(&commit_committer, "%s",
1929 got_object_commit_get_committer(commit))) == -1) {
1930 error = got_error_from_errno("asprintf");
1934 if ((asprintf(&commit_committer_disp, commit_committer_html,
1935 gw_html_escape(commit_committer))) == -1) {
1936 error = got_error_from_errno("asprintf");
1940 if (strcmp(commit_author, commit_committer) == 0) {
1941 free(commit_committer_disp);
1942 commit_committer_disp = strdup("");
1945 error = got_object_commit_get_logmsg(&commit_log0, commit);
1949 commit_log = commit_log0;
1950 while (*commit_log == '\n')
1955 newline = strchr(commit_log, '\n');
1959 if ((asprintf(&logbriefs_navs_html, logbriefs_navs,
1960 gw_trans->repo_name, id_str1, gw_trans->repo_name,
1961 id_str1, gw_trans->repo_name, id_str1,
1962 gw_trans->repo_name, id_str1)) == -1) {
1963 error = got_error_from_errno("asprintf");
1967 if ((asprintf(&commit_row, logbriefs_row,
1968 commit_age_diff, commit_author, commit_log,
1969 logbriefs_navs_html)) == -1) {
1970 error = got_error_from_errno("asprintf");
1974 free(logbriefs_navs_html);
1975 logbriefs_navs_html = NULL;
1978 if ((asprintf(&logbriefs_navs_html, logbriefs_navs,
1979 gw_trans->repo_name, id_str1, gw_trans->repo_name,
1980 id_str1, gw_trans->repo_name, id_str1,
1981 gw_trans->repo_name, id_str1)) == -1) {
1982 error = got_error_from_errno("asprintf");
1986 if ((asprintf(&commit_row, logs_row, commit_commit_disp,
1987 commit_author_disp, commit_committer_disp,
1988 commit_age_long_disp, gw_html_escape(commit_log),
1989 logbriefs_navs_html)) == -1) {
1990 error = got_error_from_errno("asprintf");
1994 free(logbriefs_navs_html);
1995 logbriefs_navs_html = NULL;
1998 log_tag_html = strdup("tag log here");
2000 if ((asprintf(&commit_row, log_tag_row,
2001 gw_html_escape(commit_log), log_tag_html)) == -1) {
2002 error = got_error_from_errno("asprintf");
2009 log_blame_html = gw_get_file_blame(gw_trans,
2012 if ((asprintf(&commit_row, log_blame_row,
2013 gw_html_escape(commit_log), log_blame_html)) == -1) {
2014 error = got_error_from_errno("asprintf");
2018 free(log_blame_html);
2021 log_tree_html = gw_get_repo_tree(gw_trans,
2024 if ((asprintf(&commit_row, log_tree_row,
2025 gw_html_escape(commit_log), log_tree_html)) == -1) {
2026 error = got_error_from_errno("asprintf");
2030 free(log_tree_html);
2033 if ((asprintf(&commit_log_disp, commit_log_html,
2034 gw_html_escape(commit_log))) == -1) {
2035 error = got_error_from_errno("asprintf");
2039 log_commit_html = strdup("commit here");
2041 if ((asprintf(&commit_row, log_commit_row,
2042 commit_diff_disp, commit_commit_disp,
2043 commit_tree_disp, commit_author_disp,
2044 commit_committer_disp, commit_age_long_disp,
2045 commit_log_disp, log_commit_html)) == -1) {
2046 error = got_error_from_errno("asprintf");
2049 free(commit_log_disp);
2050 free(log_commit_html);
2054 if ((asprintf(&commit_log_disp, commit_log_html,
2055 gw_html_escape(commit_log))) == -1) {
2056 error = got_error_from_errno("asprintf");
2061 log_diff_html = gw_get_repo_diff(gw_trans,
2062 commit_commit, commit_parent);
2064 log_diff_html = gw_get_repo_diff(gw_trans,
2065 commit_commit, NULL);
2067 if ((asprintf(&commit_row, log_diff_row,
2068 commit_diff_disp, commit_commit_disp,
2069 commit_tree_disp, commit_author_disp,
2070 commit_committer_disp, commit_age_long_disp,
2071 commit_log_disp, log_diff_html)) == -1) {
2072 error = got_error_from_errno("asprintf");
2075 free(commit_log_disp);
2076 free(log_diff_html);
2083 error = buf_puts(&newsize, diffbuf, commit_row);
2085 free(commit_parent);
2086 free(commit_diff_disp);
2087 free(commit_tree_disp);
2088 free(commit_age_diff);
2089 free(commit_age_diff_disp);
2090 free(commit_age_long);
2091 free(commit_age_long_disp);
2092 free(commit_author);
2093 free(commit_author_disp);
2094 free(commit_committer);
2095 free(commit_committer_disp);
2098 free(refs_str_disp);
2106 if (error || (limit && --limit == 0))
2113 if (buf_len(diffbuf) > 0) {
2114 error = buf_putc(diffbuf, '\0');
2115 logs = strdup(buf_get(diffbuf));
2121 got_object_commit_close(commit);
2125 got_commit_graph_close(graph);
2127 error = got_repo_close(repo);
2132 khttp_puts(gw_trans->gw_req, "Error: ");
2133 khttp_puts(gw_trans->gw_req, error->msg);
2140 gw_get_repo_tags(struct trans *gw_trans, int limit, int tag_type)
2142 const struct got_error *error = NULL;
2143 struct got_repository *repo = NULL;
2144 struct got_reflist_head refs;
2145 struct got_reflist_entry *re;
2146 char *tags = NULL, *tag_row = NULL, *tags_navs_disp = NULL,
2149 struct buf *diffbuf = NULL;
2152 error = buf_alloc(&diffbuf, 0);
2155 SIMPLEQ_INIT(&refs);
2157 error = got_repo_open(&repo, gw_trans->repo_path, NULL);
2161 error = got_ref_list(&refs, repo, "refs/tags", cmp_tags, repo);
2165 SIMPLEQ_FOREACH(re, &refs, entry) {
2166 const char *refname;
2167 char *refstr, *tag_log0, *tag_log, *id_str;
2169 struct got_object_id *id;
2170 struct got_tag_object *tag;
2172 refname = got_ref_get_name(re->ref);
2173 if (strncmp(refname, "refs/tags/", 10) != 0)
2176 refstr = got_ref_to_str(re->ref);
2177 if (refstr == NULL) {
2178 error = got_error_from_errno("got_ref_to_str");
2182 error = got_ref_resolve(&id, repo, re->ref);
2185 error = got_object_open_as_tag(&tag, repo, id);
2190 tagger_time = got_object_tag_get_tagger_time(tag);
2192 error = got_object_id_str(&id_str,
2193 got_object_tag_get_object_id(tag));
2197 tag_log0 = strdup(got_object_tag_get_message(tag));
2199 if (tag_log0 == NULL) {
2200 error = got_error_from_errno("strdup");
2205 while (*tag_log == '\n')
2210 newline = strchr(tag_log, '\n');
2214 if ((asprintf(&age, "%s", gw_get_time_str(tagger_time,
2216 error = got_error_from_errno("asprintf");
2220 if ((asprintf(&tags_navs_disp, tags_navs,
2221 gw_trans->repo_name, id_str, gw_trans->repo_name,
2222 id_str, gw_trans->repo_name, id_str,
2223 gw_trans->repo_name, id_str)) == -1) {
2224 error = got_error_from_errno("asprintf");
2228 if ((asprintf(&tag_row, tags_row, age, refname, tag_log,
2229 tags_navs_disp)) == -1) {
2230 error = got_error_from_errno("asprintf");
2234 free(tags_navs_disp);
2242 got_object_tag_close(tag);
2244 error = buf_puts(&newsize, diffbuf, tag_row);
2252 if (error || (limit && --limit == 0))
2256 if (buf_len(diffbuf) > 0) {
2257 error = buf_putc(diffbuf, '\0');
2258 tags = strdup(buf_get(diffbuf));
2262 got_ref_list_free(&refs);
2264 got_repo_close(repo);
2275 char datebuf[11]; /* YYYY-MM-DD + NUL */
2278 struct blame_cb_args {
2279 struct blame_line *lines;
2283 off_t *line_offsets;
2285 struct got_repository *repo;
2286 struct trans *gw_trans;
2287 struct buf *blamebuf;
2290 static const struct got_error *
2291 blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
2293 const struct got_error *err = NULL;
2294 struct blame_cb_args *a = arg;
2295 struct blame_line *bline;
2297 size_t linesize = 0, newsize;
2298 struct got_commit_object *commit = NULL;
2301 time_t committer_time;
2303 if (nlines != a->nlines ||
2304 (lineno != -1 && lineno < 1) || lineno > a->nlines)
2305 return got_error(GOT_ERR_RANGE);
2308 return NULL; /* no change in this commit */
2310 /* Annotate this line. */
2311 bline = &a->lines[lineno - 1];
2312 if (bline->annotated)
2314 err = got_object_id_str(&bline->id_str, id);
2318 err = got_object_open_as_commit(&commit, a->repo, id);
2322 bline->committer = strdup(got_object_commit_get_committer(commit));
2323 if (bline->committer == NULL) {
2324 err = got_error_from_errno("strdup");
2328 committer_time = got_object_commit_get_committer_time(commit);
2329 if (localtime_r(&committer_time, &tm) == NULL)
2330 return got_error_from_errno("localtime_r");
2331 if (strftime(bline->datebuf, sizeof(bline->datebuf), "%G-%m-%d",
2332 &tm) >= sizeof(bline->datebuf)) {
2333 err = got_error(GOT_ERR_NO_SPACE);
2336 bline->annotated = 1;
2338 /* Print lines annotated so far. */
2339 bline = &a->lines[a->lineno_cur - 1];
2340 if (!bline->annotated)
2343 offset = a->line_offsets[a->lineno_cur - 1];
2344 if (fseeko(a->f, offset, SEEK_SET) == -1) {
2345 err = got_error_from_errno("fseeko");
2349 while (bline->annotated) {
2350 char *smallerthan, *at, *nl, *committer, *blame_row = NULL;
2353 if (getline(&line, &linesize, a->f) == -1) {
2355 err = got_error_from_errno("getline");
2359 committer = bline->committer;
2360 smallerthan = strchr(committer, '<');
2361 if (smallerthan && smallerthan[1] != '\0')
2362 committer = smallerthan + 1;
2363 at = strchr(committer, '@');
2366 len = strlen(committer);
2368 committer[8] = '\0';
2370 nl = strchr(line, '\n');
2373 asprintf(&blame_row, log_blame_line, a->nlines_prec,
2374 a->lineno_cur, bline->id_str, bline->datebuf, committer,
2377 err = buf_puts(&newsize, a->blamebuf, blame_row);
2381 bline = &a->lines[a->lineno_cur - 1];
2386 got_object_commit_close(commit);
2392 gw_get_file_blame(struct trans *gw_trans, char *commit_str)
2394 const struct got_error *error = NULL;
2395 struct got_repository *repo = NULL;
2396 struct got_object_id *obj_id = NULL;
2397 struct got_object_id *commit_id = NULL;
2398 struct got_blob_object *blob = NULL;
2399 char *blame_html = NULL, *path = NULL, *in_repo_path = NULL,
2401 struct blame_cb_args bca;
2405 error = got_repo_open(&repo, gw_trans->repo_path, NULL);
2409 if (gw_trans->repo_folder != NULL) {
2410 if ((asprintf(&folder, "%s/", gw_trans->repo_folder)) == -1) {
2411 error = got_error_from_errno("asprintf");
2415 folder = strdup("");
2417 if ((asprintf(&path, "%s%s", folder, gw_trans->repo_file)) == -1) {
2418 error = got_error_from_errno("asprintf");
2423 error = got_repo_map_path(&in_repo_path, repo, path, 1);
2427 error = resolve_commit_arg(&commit_id, commit_str, repo);
2431 error = got_object_id_by_path(&obj_id, repo, commit_id, in_repo_path);
2435 if (obj_id == NULL) {
2436 error = got_error(GOT_ERR_NO_OBJ);
2440 error = got_object_get_type(&obj_type, repo, obj_id);
2444 if (obj_type != GOT_OBJ_TYPE_BLOB) {
2445 error = got_error(GOT_ERR_OBJ_TYPE);
2449 error = got_object_open_as_blob(&blob, repo, obj_id, 8192);
2453 error = buf_alloc(&bca.blamebuf, 0);
2457 bca.f = got_opentemp();
2458 if (bca.f == NULL) {
2459 error = got_error_from_errno("got_opentemp");
2462 error = got_object_blob_dump_to_file(&filesize, &bca.nlines,
2463 &bca.line_offsets, bca.f, blob);
2464 if (error || bca.nlines == 0)
2467 /* Don't include \n at EOF in the blame line count. */
2468 if (bca.line_offsets[bca.nlines - 1] == filesize)
2471 bca.lines = calloc(bca.nlines, sizeof(*bca.lines));
2472 if (bca.lines == NULL) {
2473 error = got_error_from_errno("calloc");
2477 bca.nlines_prec = 0;
2484 bca.gw_trans = gw_trans;
2486 error = got_blame(in_repo_path, commit_id, repo, blame_cb, &bca, NULL,
2488 if (buf_len(bca.blamebuf) > 0) {
2489 error = buf_putc(bca.blamebuf, '\0');
2490 blame_html = strdup(buf_get(bca.blamebuf));
2500 error = got_object_blob_close(blob);
2502 error = got_repo_close(repo);
2506 for (i = 0; i < bca.nlines; i++) {
2507 struct blame_line *bline = &bca.lines[i];
2508 free(bline->id_str);
2509 free(bline->committer);
2513 free(bca.line_offsets);
2514 if (bca.f && fclose(bca.f) == EOF && error == NULL)
2515 error = got_error_from_errno("fclose");
2523 gw_get_repo_tree(struct trans *gw_trans, char *commit_str)
2525 const struct got_error *error = NULL;
2526 struct got_repository *repo = NULL;
2527 struct got_object_id *tree_id = NULL, *commit_id = NULL;
2528 struct got_tree_object *tree = NULL;
2529 struct buf *diffbuf = NULL;
2531 char *tree_html = NULL, *path = NULL, *in_repo_path = NULL,
2532 *tree_row = NULL, *id_str;
2535 error = buf_alloc(&diffbuf, 0);
2539 error = got_repo_open(&repo, gw_trans->repo_path, NULL);
2543 error = got_repo_map_path(&in_repo_path, repo, gw_trans->repo_path, 1);
2547 if (gw_trans->repo_folder != NULL)
2548 path = strdup(gw_trans->repo_folder);
2549 else if (in_repo_path) {
2551 path = in_repo_path;
2554 if (commit_str == NULL) {
2555 struct got_reference *head_ref;
2556 error = got_ref_open(&head_ref, repo, gw_trans->headref, 0);
2560 error = got_ref_resolve(&commit_id, repo, head_ref);
2561 got_ref_close(head_ref);
2564 error = resolve_commit_arg(&commit_id, commit_str, repo);
2568 error = got_object_id_by_path(&tree_id, repo, commit_id, path);
2572 error = got_object_open_as_tree(&tree, repo, tree_id);
2576 nentries = got_object_tree_get_nentries(tree);
2578 for (i = 0; i < nentries; i++) {
2579 struct got_tree_entry *te;
2580 const char *modestr = "";
2581 char *id = NULL, *url_html = NULL;
2583 te = got_object_tree_get_entry(tree, i);
2585 error = got_object_id_str(&id_str, got_tree_entry_get_id(te));
2589 if ((asprintf(&id, "%s", id_str)) == -1) {
2590 error = got_error_from_errno("asprintf");
2595 mode_t mode = got_tree_entry_get_mode(te);
2597 if (got_object_tree_entry_is_submodule(te))
2599 else if (S_ISLNK(mode))
2601 else if (S_ISDIR(mode))
2603 else if (mode & S_IXUSR)
2606 char *build_folder = NULL;
2607 if (S_ISDIR(got_tree_entry_get_mode(te))) {
2608 if (gw_trans->repo_folder != NULL) {
2609 if ((asprintf(&build_folder, "%s/%s",
2610 gw_trans->repo_folder,
2611 got_tree_entry_get_name(te))) == -1) {
2613 got_error_from_errno("asprintf");
2617 if (asprintf(&build_folder, "%s",
2618 got_tree_entry_get_name(te)) == -1)
2622 if ((asprintf(&url_html, folder_html,
2623 gw_trans->repo_name, gw_trans->action_name,
2624 gw_trans->commit, build_folder,
2625 got_tree_entry_get_name(te), modestr)) == -1) {
2626 error = got_error_from_errno("asprintf");
2630 if (gw_trans->repo_folder != NULL) {
2631 if ((asprintf(&build_folder, "%s",
2632 gw_trans->repo_folder)) == -1) {
2634 got_error_from_errno("asprintf");
2638 build_folder = strdup("");
2640 if ((asprintf(&url_html, file_html, gw_trans->repo_name,
2641 "blame", gw_trans->commit,
2642 got_tree_entry_get_name(te), build_folder,
2643 got_tree_entry_get_name(te), modestr)) == -1) {
2644 error = got_error_from_errno("asprintf");
2653 if ((asprintf(&tree_row, trees_row, "", url_html)) == -1) {
2654 error = got_error_from_errno("asprintf");
2657 error = buf_puts(&newsize, diffbuf, tree_row);
2667 if (buf_len(diffbuf) > 0) {
2668 error = buf_putc(diffbuf, '\0');
2669 tree_html = strdup(buf_get(diffbuf));
2673 got_object_tree_close(tree);
2675 got_repo_close(repo);
2687 gw_get_repo_heads(struct trans *gw_trans)
2689 const struct got_error *error = NULL;
2690 struct got_repository *repo = NULL;
2691 struct got_reflist_head refs;
2692 struct got_reflist_entry *re;
2693 char *heads, *head_row = NULL, *head_navs_disp = NULL, *age = NULL;
2694 struct buf *diffbuf = NULL;
2697 error = buf_alloc(&diffbuf, 0);
2701 error = got_repo_open(&repo, gw_trans->repo_path, NULL);
2705 SIMPLEQ_INIT(&refs);
2706 error = got_ref_list(&refs, repo, "refs/heads", got_ref_cmp_by_name,
2711 SIMPLEQ_FOREACH(re, &refs, entry) {
2714 refname = strdup(got_ref_get_name(re->ref));
2715 if (refname == NULL) {
2716 error = got_error_from_errno("got_ref_to_str");
2720 if (strncmp(refname, "refs/heads/", 11) != 0) {
2725 age = gw_get_repo_age(gw_trans, gw_trans->gw_dir->path, refname,
2728 if ((asprintf(&head_navs_disp, heads_navs, gw_trans->repo_name,
2729 refname, gw_trans->repo_name, refname,
2730 gw_trans->repo_name, refname, gw_trans->repo_name,
2732 error = got_error_from_errno("asprintf");
2736 if (strncmp(refname, "refs/heads/", 11) == 0)
2739 if ((asprintf(&head_row, heads_row, age, refname,
2740 head_navs_disp)) == -1) {
2741 error = got_error_from_errno("asprintf");
2745 error = buf_puts(&newsize, diffbuf, head_row);
2747 free(head_navs_disp);
2751 if (buf_len(diffbuf) > 0) {
2752 error = buf_putc(diffbuf, '\0');
2753 heads = strdup(buf_get(diffbuf));
2757 got_ref_list_free(&refs);
2759 got_repo_close(repo);
2767 gw_get_got_link(struct trans *gw_trans)
2771 if ((asprintf(&link, got_link, gw_trans->gw_conf->got_logo_url,
2772 gw_trans->gw_conf->got_logo)) == -1)
2779 gw_get_site_link(struct trans *gw_trans)
2781 char *link, *repo = "", *action = "";
2783 if (gw_trans->repo_name != NULL)
2784 if ((asprintf(&repo, " / <a href='?path=%s&action=summary'>%s" \
2785 "</a>", gw_trans->repo_name, gw_trans->repo_name)) == -1)
2788 if (gw_trans->action_name != NULL)
2789 if ((asprintf(&action, " / %s", gw_trans->action_name)) == -1)
2792 if ((asprintf(&link, site_link, GOTWEB,
2793 gw_trans->gw_conf->got_site_link, repo, action)) == -1)
2800 color_diff_line(char *buf)
2802 const struct got_error *error = NULL;
2803 char *colorized_line = NULL, *div_diff_line_div = NULL, *color = NULL;
2804 struct buf *diffbuf = NULL;
2807 error = buf_alloc(&diffbuf, 0);
2811 if (strncmp(buf, "-", 1) == 0)
2812 color = "diff_minus";
2813 if (strncmp(buf, "+", 1) == 0)
2814 color = "diff_plus";
2815 if (strncmp(buf, "@@", 2) == 0)
2816 color = "diff_chunk_header";
2817 if (strncmp(buf, "@@", 2) == 0)
2818 color = "diff_chunk_header";
2819 if (strncmp(buf, "commit +", 8) == 0)
2820 color = "diff_meta";
2821 if (strncmp(buf, "commit -", 8) == 0)
2822 color = "diff_meta";
2823 if (strncmp(buf, "blob +", 6) == 0)
2824 color = "diff_meta";
2825 if (strncmp(buf, "blob -", 6) == 0)
2826 color = "diff_meta";
2827 if (strncmp(buf, "file +", 6) == 0)
2828 color = "diff_meta";
2829 if (strncmp(buf, "file -", 6) == 0)
2830 color = "diff_meta";
2831 if (strncmp(buf, "from:", 5) == 0)
2832 color = "diff_author";
2833 if (strncmp(buf, "via:", 4) == 0)
2834 color = "diff_author";
2835 if (strncmp(buf, "date:", 5) == 0)
2836 color = "diff_date";
2838 if ((asprintf(&div_diff_line_div, div_diff_line, color)) == -1)
2841 error = buf_puts(&newsize, diffbuf, div_diff_line_div);
2845 error = buf_puts(&newsize, diffbuf, buf);
2849 if (buf_len(diffbuf) > 0) {
2850 error = buf_putc(diffbuf, '\0');
2851 colorized_line = strdup(buf_get(diffbuf));
2855 free(div_diff_line_div);
2856 return colorized_line;
2860 gw_html_escape(const char *html)
2862 char *escaped_str = NULL, *buf;
2864 size_t sz, i, buff_sz = 2048;
2866 if ((buf = calloc(buff_sz, sizeof(char *))) == NULL)
2872 if ((sz = strlen(html)) == 0)
2875 /* only work with buff_sz */
2879 for (i = 0; i < sz; i++) {
2883 strcat(buf, ">");
2886 strcat(buf, "&");
2889 strcat(buf, "<");
2892 strcat(buf, """);
2895 strcat(buf, "'");
2898 strcat(buf, "<br />");
2904 asprintf(&escaped_str, "%s", buf);
2912 const struct got_error *error = NULL;
2913 struct trans *gw_trans;
2914 struct gw_dir *dir = NULL, *tdir;
2915 const char *page = "index";
2918 if ((gw_trans = malloc(sizeof(struct trans))) == NULL)
2921 if ((gw_trans->gw_req = malloc(sizeof(struct kreq))) == NULL)
2924 if ((gw_trans->gw_html_req = malloc(sizeof(struct khtmlreq))) == NULL)
2927 if ((gw_trans->gw_tmpl = malloc(sizeof(struct ktemplate))) == NULL)
2930 if (KCGI_OK != khttp_parse(gw_trans->gw_req, gw_keys, KEY__ZMAX,
2932 errx(1, "khttp_parse");
2934 if ((gw_trans->gw_conf =
2935 malloc(sizeof(struct gotweb_conf))) == NULL) {
2937 error = got_error_from_errno("malloc");
2941 if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
2943 error = got_error_from_errno("pledge");
2947 TAILQ_INIT(&gw_trans->gw_dirs);
2950 gw_trans->repos_total = 0;
2951 gw_trans->repo_path = NULL;
2952 gw_trans->commit = NULL;
2953 gw_trans->headref = strdup(GOT_REF_HEAD);
2954 gw_trans->mime = KMIME_TEXT_HTML;
2955 gw_trans->gw_tmpl->key = templs;
2956 gw_trans->gw_tmpl->keysz = TEMPL__MAX;
2957 gw_trans->gw_tmpl->arg = gw_trans;
2958 gw_trans->gw_tmpl->cb = gw_template;
2959 error = parse_conf(GOTWEB_CONF, gw_trans->gw_conf);
2963 gw_trans->mime = KMIME_TEXT_PLAIN;
2964 gw_trans->action = GW_ERR;
2965 gw_display_index(gw_trans, error);
2969 error = gw_parse_querystring(gw_trans);
2973 gw_display_index(gw_trans, error);
2977 free(gw_trans->gw_conf->got_repos_path);
2978 free(gw_trans->gw_conf->got_www_path);
2979 free(gw_trans->gw_conf->got_site_name);
2980 free(gw_trans->gw_conf->got_site_owner);
2981 free(gw_trans->gw_conf->got_site_link);
2982 free(gw_trans->gw_conf->got_logo);
2983 free(gw_trans->gw_conf->got_logo_url);
2984 free(gw_trans->gw_conf);
2985 free(gw_trans->commit);
2986 free(gw_trans->repo_path);
2987 free(gw_trans->repo_name);
2988 free(gw_trans->repo_file);
2989 free(gw_trans->action_name);
2990 free(gw_trans->headref);
2992 TAILQ_FOREACH_SAFE(dir, &gw_trans->gw_dirs, entry, tdir) {
2994 free(dir->description);
3003 khttp_free(gw_trans->gw_req);
3004 return EXIT_SUCCESS;