2 9460dac0 2020-01-15 tracey * Copyright (c) 2019, 2020 Tracey Emery <tracey@traceyemery.net>
3 2c251c14 2020-01-15 tracey * Copyright (c) 2018, 2019 Stefan Sperling <stsp@openbsd.org>
5 2c251c14 2020-01-15 tracey * Permission to use, copy, modify, and distribute this software for any
6 2c251c14 2020-01-15 tracey * purpose with or without fee is hereby granted, provided that the above
7 2c251c14 2020-01-15 tracey * copyright notice and this permission notice appear in all copies.
9 2c251c14 2020-01-15 tracey * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 2c251c14 2020-01-15 tracey * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 2c251c14 2020-01-15 tracey * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 2c251c14 2020-01-15 tracey * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 2c251c14 2020-01-15 tracey * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 2c251c14 2020-01-15 tracey * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 2c251c14 2020-01-15 tracey * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 2c251c14 2020-01-15 tracey #include <sys/queue.h>
19 2c251c14 2020-01-15 tracey #include <sys/stat.h>
20 2c251c14 2020-01-15 tracey #include <sys/types.h>
22 2c251c14 2020-01-15 tracey #include <dirent.h>
23 2c251c14 2020-01-15 tracey #include <err.h>
24 474370cb 2020-01-15 tracey #include <regex.h>
25 2c251c14 2020-01-15 tracey #include <stdarg.h>
26 2c251c14 2020-01-15 tracey #include <stdbool.h>
27 2c251c14 2020-01-15 tracey #include <stdint.h>
28 2c251c14 2020-01-15 tracey #include <stdio.h>
29 2c251c14 2020-01-15 tracey #include <stdlib.h>
30 2c251c14 2020-01-15 tracey #include <string.h>
31 2c251c14 2020-01-15 tracey #include <unistd.h>
33 2c251c14 2020-01-15 tracey #include <got_object.h>
34 2c251c14 2020-01-15 tracey #include <got_reference.h>
35 2c251c14 2020-01-15 tracey #include <got_repository.h>
36 2c251c14 2020-01-15 tracey #include <got_path.h>
37 2c251c14 2020-01-15 tracey #include <got_cancel.h>
38 2c251c14 2020-01-15 tracey #include <got_worktree.h>
39 2c251c14 2020-01-15 tracey #include <got_diff.h>
40 2c251c14 2020-01-15 tracey #include <got_commit_graph.h>
41 2c251c14 2020-01-15 tracey #include <got_blame.h>
42 2c251c14 2020-01-15 tracey #include <got_privsep.h>
43 2c251c14 2020-01-15 tracey #include <got_opentemp.h>
45 2c251c14 2020-01-15 tracey #include <kcgi.h>
46 2c251c14 2020-01-15 tracey #include <kcgihtml.h>
48 474370cb 2020-01-15 tracey #include "buf.h"
49 2c251c14 2020-01-15 tracey #include "gotweb.h"
50 2c251c14 2020-01-15 tracey #include "gotweb_ui.h"
52 2c251c14 2020-01-15 tracey #ifndef nitems
53 2c251c14 2020-01-15 tracey #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
56 54415d85 2020-01-15 tracey struct gw_trans {
57 2c251c14 2020-01-15 tracey TAILQ_HEAD(dirs, gw_dir) gw_dirs;
58 46b9c89b 2020-01-15 tracey struct gw_dir *gw_dir;
59 2c251c14 2020-01-15 tracey struct gotweb_conf *gw_conf;
60 2c251c14 2020-01-15 tracey struct ktemplate *gw_tmpl;
61 2c251c14 2020-01-15 tracey struct khtmlreq *gw_html_req;
62 2c251c14 2020-01-15 tracey struct kreq *gw_req;
63 2c251c14 2020-01-15 tracey char *repo_name;
64 2c251c14 2020-01-15 tracey char *repo_path;
65 2c251c14 2020-01-15 tracey char *commit;
66 2c251c14 2020-01-15 tracey char *repo_file;
67 ec46ccd7 2020-01-15 tracey char *repo_folder;
68 2c251c14 2020-01-15 tracey char *action_name;
69 8087c3c5 2020-01-15 tracey char *headref;
70 2c251c14 2020-01-15 tracey unsigned int action;
71 2c251c14 2020-01-15 tracey unsigned int page;
72 2c251c14 2020-01-15 tracey unsigned int repos_total;
73 387a29ba 2020-01-15 tracey enum kmime mime;
76 2c251c14 2020-01-15 tracey enum gw_key {
77 2c251c14 2020-01-15 tracey KEY_ACTION,
78 2c251c14 2020-01-15 tracey KEY_COMMIT_ID,
80 ec46ccd7 2020-01-15 tracey KEY_FOLDER,
81 8087c3c5 2020-01-15 tracey KEY_HEADREF,
87 2c251c14 2020-01-15 tracey struct gw_dir {
88 2c251c14 2020-01-15 tracey TAILQ_ENTRY(gw_dir) entry;
89 2c251c14 2020-01-15 tracey char *name;
90 2c251c14 2020-01-15 tracey char *owner;
91 2c251c14 2020-01-15 tracey char *description;
92 2c251c14 2020-01-15 tracey char *url;
93 2c251c14 2020-01-15 tracey char *age;
94 2c251c14 2020-01-15 tracey char *path;
97 54415d85 2020-01-15 tracey enum gw_tmpl {
98 2c251c14 2020-01-15 tracey TEMPL_HEAD,
99 2c251c14 2020-01-15 tracey TEMPL_HEADER,
100 2c251c14 2020-01-15 tracey TEMPL_SITEPATH,
101 2c251c14 2020-01-15 tracey TEMPL_SITEOWNER,
102 2c251c14 2020-01-15 tracey TEMPL_TITLE,
103 2c251c14 2020-01-15 tracey TEMPL_SEARCH,
104 2c251c14 2020-01-15 tracey TEMPL_CONTENT,
105 2c251c14 2020-01-15 tracey TEMPL__MAX
108 54415d85 2020-01-15 tracey enum gw_ref_tm {
113 54415d85 2020-01-15 tracey enum gw_logs {
114 8087c3c5 2020-01-15 tracey LOGBRIEF,
115 8087c3c5 2020-01-15 tracey LOGCOMMIT,
119 87f9ebf5 2020-01-15 tracey LOGBLAME,
123 54415d85 2020-01-15 tracey enum gw_tags {
124 87f9ebf5 2020-01-15 tracey TAGBRIEF,
128 54415d85 2020-01-15 tracey static const char *const gw_templs[TEMPL__MAX] = {
130 2c251c14 2020-01-15 tracey "header",
131 2c251c14 2020-01-15 tracey "sitepath",
132 2c251c14 2020-01-15 tracey "siteowner",
134 2c251c14 2020-01-15 tracey "search",
135 2c251c14 2020-01-15 tracey "content",
138 ec46ccd7 2020-01-15 tracey static const struct kvalid gw_keys[KEY__ZMAX] = {
139 2c251c14 2020-01-15 tracey { kvalid_stringne, "action" },
140 2c251c14 2020-01-15 tracey { kvalid_stringne, "commit" },
141 2c251c14 2020-01-15 tracey { kvalid_stringne, "file" },
142 ec46ccd7 2020-01-15 tracey { kvalid_stringne, "folder" },
143 8087c3c5 2020-01-15 tracey { kvalid_stringne, "headref" },
144 ec46ccd7 2020-01-15 tracey { kvalid_int, "page" },
145 ec46ccd7 2020-01-15 tracey { kvalid_stringne, "path" },
148 d0ea9c5b 2020-01-15 tracey int gw_get_repo_log_count(struct gw_trans *,
151 2c251c14 2020-01-15 tracey static struct gw_dir *gw_init_gw_dir(char *);
153 54415d85 2020-01-15 tracey static char *gw_get_repo_description(struct gw_trans *,
155 54415d85 2020-01-15 tracey static char *gw_get_repo_owner(struct gw_trans *,
157 474370cb 2020-01-15 tracey static char *gw_get_time_str(time_t, int);
158 54415d85 2020-01-15 tracey static char *gw_get_repo_age(struct gw_trans *,
159 387a29ba 2020-01-15 tracey char *, char *, int);
160 d0ea9c5b 2020-01-15 tracey static char *gw_get_repo_log(struct gw_trans *,
161 d0ea9c5b 2020-01-15 tracey const char *, char *, int, int);
162 54415d85 2020-01-15 tracey static char *gw_get_file_blame(struct gw_trans *, char *);
163 54415d85 2020-01-15 tracey static char *gw_get_repo_tree(struct gw_trans *, char *);
164 54415d85 2020-01-15 tracey static char *gw_get_repo_diff(struct gw_trans *, char *,
166 54415d85 2020-01-15 tracey static char *gw_get_repo_tags(struct gw_trans *, int, int);
167 54415d85 2020-01-15 tracey static char *gw_get_repo_heads(struct gw_trans *);
168 54415d85 2020-01-15 tracey static char *gw_get_clone_url(struct gw_trans *, char *);
169 54415d85 2020-01-15 tracey static char *gw_get_got_link(struct gw_trans *);
170 54415d85 2020-01-15 tracey static char *gw_get_site_link(struct gw_trans *);
171 2c251c14 2020-01-15 tracey static char *gw_html_escape(const char *);
172 d0ea9c5b 2020-01-15 tracey static char *gw_colordiff_line(char *);
174 54415d85 2020-01-15 tracey static void gw_display_open(struct gw_trans *, enum khttp,
175 2c251c14 2020-01-15 tracey enum kmime);
176 54415d85 2020-01-15 tracey static void gw_display_index(struct gw_trans *,
177 2c251c14 2020-01-15 tracey const struct got_error *);
179 2c251c14 2020-01-15 tracey static int gw_template(size_t, void *);
181 54415d85 2020-01-15 tracey static const struct got_error* gw_apply_unveil(const char *, const char *);
182 147269d5 2020-01-15 tracey static const struct got_error* gw_blame_cb(void *, int, int,
183 ec46ccd7 2020-01-15 tracey struct got_object_id *);
184 54415d85 2020-01-15 tracey static const struct got_error* gw_load_got_paths(struct gw_trans *);
185 54415d85 2020-01-15 tracey static const struct got_error* gw_load_got_path(struct gw_trans *,
186 2c251c14 2020-01-15 tracey struct gw_dir *);
187 54415d85 2020-01-15 tracey static const struct got_error* gw_parse_querystring(struct gw_trans *);
188 f2915494 2020-01-15 tracey static const struct got_error* gw_match_logmsg(int *, struct got_object_id *,
189 474370cb 2020-01-15 tracey struct got_commit_object *, regex_t *);
191 54415d85 2020-01-15 tracey static const struct got_error* gw_blame(struct gw_trans *);
192 54415d85 2020-01-15 tracey static const struct got_error* gw_commit(struct gw_trans *);
193 54415d85 2020-01-15 tracey static const struct got_error* gw_commitdiff(struct gw_trans *);
194 54415d85 2020-01-15 tracey static const struct got_error* gw_index(struct gw_trans *);
195 54415d85 2020-01-15 tracey static const struct got_error* gw_log(struct gw_trans *);
196 54415d85 2020-01-15 tracey static const struct got_error* gw_raw(struct gw_trans *);
197 54415d85 2020-01-15 tracey static const struct got_error* gw_logbriefs(struct gw_trans *);
198 54415d85 2020-01-15 tracey static const struct got_error* gw_summary(struct gw_trans *);
199 54415d85 2020-01-15 tracey static const struct got_error* gw_tag(struct gw_trans *);
200 54415d85 2020-01-15 tracey static const struct got_error* gw_tree(struct gw_trans *);
202 2c251c14 2020-01-15 tracey struct gw_query_action {
203 2c251c14 2020-01-15 tracey unsigned int func_id;
204 2c251c14 2020-01-15 tracey const char *func_name;
205 54415d85 2020-01-15 tracey const struct got_error *(*func_main)(struct gw_trans *);
206 2c251c14 2020-01-15 tracey char *template;
209 2c251c14 2020-01-15 tracey enum gw_query_actions {
210 2c251c14 2020-01-15 tracey GW_BLAME,
211 2c251c14 2020-01-15 tracey GW_COMMIT,
212 2c251c14 2020-01-15 tracey GW_COMMITDIFF,
214 2c251c14 2020-01-15 tracey GW_INDEX,
217 4ceb8155 2020-01-15 tracey GW_LOGBRIEFS,
218 2c251c14 2020-01-15 tracey GW_SUMMARY,
223 2c251c14 2020-01-15 tracey static struct gw_query_action gw_query_funcs[] = {
224 2c251c14 2020-01-15 tracey { GW_BLAME, "blame", gw_blame, "gw_tmpl/index.tmpl" },
225 2c251c14 2020-01-15 tracey { GW_COMMIT, "commit", gw_commit, "gw_tmpl/index.tmpl" },
226 8087c3c5 2020-01-15 tracey { GW_COMMITDIFF, "commitdiff", gw_commitdiff, "gw_tmpl/index.tmpl" },
227 387a29ba 2020-01-15 tracey { GW_ERR, NULL, NULL, "gw_tmpl/index.tmpl" },
228 2c251c14 2020-01-15 tracey { GW_INDEX, "index", gw_index, "gw_tmpl/index.tmpl" },
229 2c251c14 2020-01-15 tracey { GW_LOG, "log", gw_log, "gw_tmpl/index.tmpl" },
230 2c251c14 2020-01-15 tracey { GW_RAW, "raw", gw_raw, "gw_tmpl/index.tmpl" },
231 4ceb8155 2020-01-15 tracey { GW_LOGBRIEFS, "logbriefs", gw_logbriefs, "gw_tmpl/index.tmpl" },
232 46b9c89b 2020-01-15 tracey { GW_SUMMARY, "summary", gw_summary, "gw_tmpl/index.tmpl" },
233 b772de24 2020-01-15 tracey { GW_TAG, "tag", gw_tag, "gw_tmpl/index.tmpl" },
234 2c251c14 2020-01-15 tracey { GW_TREE, "tree", gw_tree, "gw_tmpl/index.tmpl" },
237 2c251c14 2020-01-15 tracey static const struct got_error *
238 54415d85 2020-01-15 tracey gw_apply_unveil(const char *repo_path, const char *repo_file)
240 2c251c14 2020-01-15 tracey const struct got_error *err;
242 2c251c14 2020-01-15 tracey if (repo_path && repo_file) {
243 2c251c14 2020-01-15 tracey char *full_path;
244 2c251c14 2020-01-15 tracey if ((asprintf(&full_path, "%s/%s", repo_path, repo_file)) == -1)
245 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf unveil");
246 2c251c14 2020-01-15 tracey if (unveil(full_path, "r") != 0)
247 2c251c14 2020-01-15 tracey return got_error_from_errno2("unveil", full_path);
250 2c251c14 2020-01-15 tracey if (repo_path && unveil(repo_path, "r") != 0)
251 2c251c14 2020-01-15 tracey return got_error_from_errno2("unveil", repo_path);
253 2c251c14 2020-01-15 tracey if (unveil("/tmp", "rwc") != 0)
254 2c251c14 2020-01-15 tracey return got_error_from_errno2("unveil", "/tmp");
256 2c251c14 2020-01-15 tracey err = got_privsep_unveil_exec_helpers();
257 2c251c14 2020-01-15 tracey if (err != NULL)
258 2c251c14 2020-01-15 tracey return err;
260 2c251c14 2020-01-15 tracey if (unveil(NULL, NULL) != 0)
261 2c251c14 2020-01-15 tracey return got_error_from_errno("unveil");
263 2c251c14 2020-01-15 tracey return NULL;
267 54415d85 2020-01-15 tracey gw_get_repo_log_count(struct gw_trans *gw_trans, char *start_commit)
269 65b95fb2 2020-01-15 tracey const struct got_error *error;
270 65b95fb2 2020-01-15 tracey struct got_repository *repo = NULL;
271 65b95fb2 2020-01-15 tracey struct got_reflist_head refs;
272 65b95fb2 2020-01-15 tracey struct got_commit_object *commit = NULL;
273 65b95fb2 2020-01-15 tracey struct got_object_id *id = NULL;
274 65b95fb2 2020-01-15 tracey struct got_commit_graph *graph = NULL;
275 65b95fb2 2020-01-15 tracey char *in_repo_path = NULL, *path = NULL;
276 65b95fb2 2020-01-15 tracey int log_count = 0;
278 65b95fb2 2020-01-15 tracey error = got_repo_open(&repo, gw_trans->repo_path, NULL);
279 ec46ccd7 2020-01-15 tracey if (error)
280 65b95fb2 2020-01-15 tracey return 0;
282 65b95fb2 2020-01-15 tracey SIMPLEQ_INIT(&refs);
284 65b95fb2 2020-01-15 tracey if (start_commit == NULL) {
285 65b95fb2 2020-01-15 tracey struct got_reference *head_ref;
286 65b95fb2 2020-01-15 tracey error = got_ref_open(&head_ref, repo, gw_trans->headref, 0);
287 ec46ccd7 2020-01-15 tracey if (error)
288 65b95fb2 2020-01-15 tracey goto done;
290 65b95fb2 2020-01-15 tracey error = got_ref_resolve(&id, repo, head_ref);
291 65b95fb2 2020-01-15 tracey got_ref_close(head_ref);
292 ec46ccd7 2020-01-15 tracey if (error)
293 65b95fb2 2020-01-15 tracey goto done;
295 65b95fb2 2020-01-15 tracey error = got_object_open_as_commit(&commit, repo, id);
297 65b95fb2 2020-01-15 tracey struct got_reference *ref;
298 65b95fb2 2020-01-15 tracey error = got_ref_open(&ref, repo, start_commit, 0);
299 65b95fb2 2020-01-15 tracey if (error == NULL) {
300 65b95fb2 2020-01-15 tracey int obj_type;
301 65b95fb2 2020-01-15 tracey error = got_ref_resolve(&id, repo, ref);
302 65b95fb2 2020-01-15 tracey got_ref_close(ref);
303 ec46ccd7 2020-01-15 tracey if (error)
304 65b95fb2 2020-01-15 tracey goto done;
305 65b95fb2 2020-01-15 tracey error = got_object_get_type(&obj_type, repo, id);
306 ec46ccd7 2020-01-15 tracey if (error)
307 65b95fb2 2020-01-15 tracey goto done;
308 65b95fb2 2020-01-15 tracey if (obj_type == GOT_OBJ_TYPE_TAG) {
309 65b95fb2 2020-01-15 tracey struct got_tag_object *tag;
310 65b95fb2 2020-01-15 tracey error = got_object_open_as_tag(&tag, repo, id);
311 ec46ccd7 2020-01-15 tracey if (error)
312 65b95fb2 2020-01-15 tracey goto done;
313 65b95fb2 2020-01-15 tracey if (got_object_tag_get_object_type(tag) !=
314 65b95fb2 2020-01-15 tracey GOT_OBJ_TYPE_COMMIT) {
315 65b95fb2 2020-01-15 tracey got_object_tag_close(tag);
316 65b95fb2 2020-01-15 tracey error = got_error(GOT_ERR_OBJ_TYPE);
317 65b95fb2 2020-01-15 tracey goto done;
319 65b95fb2 2020-01-15 tracey free(id);
320 65b95fb2 2020-01-15 tracey id = got_object_id_dup(
321 65b95fb2 2020-01-15 tracey got_object_tag_get_object_id(tag));
322 65b95fb2 2020-01-15 tracey if (id == NULL)
323 65b95fb2 2020-01-15 tracey error = got_error_from_errno(
324 65b95fb2 2020-01-15 tracey "got_object_id_dup");
325 65b95fb2 2020-01-15 tracey got_object_tag_close(tag);
326 65b95fb2 2020-01-15 tracey if (error)
327 65b95fb2 2020-01-15 tracey goto done;
328 65b95fb2 2020-01-15 tracey } else if (obj_type != GOT_OBJ_TYPE_COMMIT) {
329 65b95fb2 2020-01-15 tracey error = got_error(GOT_ERR_OBJ_TYPE);
330 65b95fb2 2020-01-15 tracey goto done;
332 65b95fb2 2020-01-15 tracey error = got_object_open_as_commit(&commit, repo, id);
333 ec46ccd7 2020-01-15 tracey if (error)
334 65b95fb2 2020-01-15 tracey goto done;
336 65b95fb2 2020-01-15 tracey if (commit == NULL) {
337 65b95fb2 2020-01-15 tracey error = got_repo_match_object_id_prefix(&id,
338 65b95fb2 2020-01-15 tracey start_commit, GOT_OBJ_TYPE_COMMIT, repo);
339 ec46ccd7 2020-01-15 tracey if (error)
340 65b95fb2 2020-01-15 tracey goto done;
342 65b95fb2 2020-01-15 tracey error = got_repo_match_object_id_prefix(&id,
343 65b95fb2 2020-01-15 tracey start_commit, GOT_OBJ_TYPE_COMMIT, repo);
344 ec46ccd7 2020-01-15 tracey if (error)
345 65b95fb2 2020-01-15 tracey goto done;
348 65b95fb2 2020-01-15 tracey error = got_object_open_as_commit(&commit, repo, id);
349 ec46ccd7 2020-01-15 tracey if (error)
350 65b95fb2 2020-01-15 tracey goto done;
352 65b95fb2 2020-01-15 tracey error = got_repo_map_path(&in_repo_path, repo, gw_trans->repo_path, 1);
353 ec46ccd7 2020-01-15 tracey if (error)
354 65b95fb2 2020-01-15 tracey goto done;
356 65b95fb2 2020-01-15 tracey if (in_repo_path) {
357 65b95fb2 2020-01-15 tracey free(path);
358 65b95fb2 2020-01-15 tracey path = in_repo_path;
361 65b95fb2 2020-01-15 tracey error = got_ref_list(&refs, repo, NULL, got_ref_cmp_by_name, NULL);
362 65b95fb2 2020-01-15 tracey if (error)
363 65b95fb2 2020-01-15 tracey goto done;
365 65b95fb2 2020-01-15 tracey error = got_commit_graph_open(&graph, path, 0);
366 65b95fb2 2020-01-15 tracey if (error)
367 65b95fb2 2020-01-15 tracey goto done;
369 65b95fb2 2020-01-15 tracey error = got_commit_graph_iter_start(graph, id, repo, NULL, NULL);
370 65b95fb2 2020-01-15 tracey if (error)
371 65b95fb2 2020-01-15 tracey goto done;
373 65b95fb2 2020-01-15 tracey for (;;) {
374 65b95fb2 2020-01-15 tracey error = got_commit_graph_iter_next(&id, graph, repo, NULL,
376 65b95fb2 2020-01-15 tracey if (error) {
377 65b95fb2 2020-01-15 tracey if (error->code == GOT_ERR_ITER_COMPLETED)
378 65b95fb2 2020-01-15 tracey error = NULL;
381 65b95fb2 2020-01-15 tracey if (id == NULL)
384 65b95fb2 2020-01-15 tracey if (error)
386 65b95fb2 2020-01-15 tracey log_count++;
389 2e676fc5 2020-01-15 tracey free(in_repo_path);
390 65b95fb2 2020-01-15 tracey if (graph)
391 65b95fb2 2020-01-15 tracey got_commit_graph_close(graph);
392 65b95fb2 2020-01-15 tracey if (repo) {
393 65b95fb2 2020-01-15 tracey error = got_repo_close(repo);
394 ec46ccd7 2020-01-15 tracey if (error)
395 65b95fb2 2020-01-15 tracey return 0;
397 65b95fb2 2020-01-15 tracey if (error) {
398 65b95fb2 2020-01-15 tracey khttp_puts(gw_trans->gw_req, "Error: ");
399 65b95fb2 2020-01-15 tracey khttp_puts(gw_trans->gw_req, error->msg);
400 65b95fb2 2020-01-15 tracey return 0;
402 65b95fb2 2020-01-15 tracey return log_count;
405 2c251c14 2020-01-15 tracey static const struct got_error *
406 54415d85 2020-01-15 tracey gw_blame(struct gw_trans *gw_trans)
408 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
410 ec46ccd7 2020-01-15 tracey char *log, *log_html;
412 54415d85 2020-01-15 tracey error = gw_apply_unveil(gw_trans->gw_dir->path, NULL);
413 ec46ccd7 2020-01-15 tracey if (error)
414 ec46ccd7 2020-01-15 tracey return error;
416 ec46ccd7 2020-01-15 tracey log = gw_get_repo_log(gw_trans, NULL, gw_trans->commit, 1, LOGBLAME);
418 ec46ccd7 2020-01-15 tracey if (log != NULL && strcmp(log, "") != 0) {
419 2e676fc5 2020-01-15 tracey if ((asprintf(&log_html, log_blame, log)) == -1)
420 ec46ccd7 2020-01-15 tracey return got_error_from_errno("asprintf");
421 ec46ccd7 2020-01-15 tracey khttp_puts(gw_trans->gw_req, log_html);
422 ec46ccd7 2020-01-15 tracey free(log_html);
423 ec46ccd7 2020-01-15 tracey free(log);
425 2c251c14 2020-01-15 tracey return error;
428 2c251c14 2020-01-15 tracey static const struct got_error *
429 54415d85 2020-01-15 tracey gw_commit(struct gw_trans *gw_trans)
431 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
432 8087c3c5 2020-01-15 tracey char *log, *log_html;
434 54415d85 2020-01-15 tracey error = gw_apply_unveil(gw_trans->gw_dir->path, NULL);
435 8087c3c5 2020-01-15 tracey if (error)
436 8087c3c5 2020-01-15 tracey return error;
438 8087c3c5 2020-01-15 tracey log = gw_get_repo_log(gw_trans, NULL, gw_trans->commit, 1, LOGCOMMIT);
440 8087c3c5 2020-01-15 tracey if (log != NULL && strcmp(log, "") != 0) {
441 8087c3c5 2020-01-15 tracey if ((asprintf(&log_html, log_commit, log)) == -1)
442 8087c3c5 2020-01-15 tracey return got_error_from_errno("asprintf");
443 8087c3c5 2020-01-15 tracey khttp_puts(gw_trans->gw_req, log_html);
444 8087c3c5 2020-01-15 tracey free(log_html);
445 8087c3c5 2020-01-15 tracey free(log);
447 2c251c14 2020-01-15 tracey return error;
450 2c251c14 2020-01-15 tracey static const struct got_error *
451 54415d85 2020-01-15 tracey gw_commitdiff(struct gw_trans *gw_trans)
453 2204c934 2020-01-15 tracey const struct got_error *error = NULL;
454 87f9ebf5 2020-01-15 tracey char *log, *log_html;
456 54415d85 2020-01-15 tracey error = gw_apply_unveil(gw_trans->gw_dir->path, NULL);
457 87f9ebf5 2020-01-15 tracey if (error)
458 87f9ebf5 2020-01-15 tracey return error;
460 87f9ebf5 2020-01-15 tracey log = gw_get_repo_log(gw_trans, NULL, gw_trans->commit, 1, LOGDIFF);
462 87f9ebf5 2020-01-15 tracey if (log != NULL && strcmp(log, "") != 0) {
463 87f9ebf5 2020-01-15 tracey if ((asprintf(&log_html, log_diff, log)) == -1)
464 87f9ebf5 2020-01-15 tracey return got_error_from_errno("asprintf");
465 87f9ebf5 2020-01-15 tracey khttp_puts(gw_trans->gw_req, log_html);
466 87f9ebf5 2020-01-15 tracey free(log_html);
467 87f9ebf5 2020-01-15 tracey free(log);
469 2204c934 2020-01-15 tracey return error;
472 2204c934 2020-01-15 tracey static const struct got_error *
473 54415d85 2020-01-15 tracey gw_index(struct gw_trans *gw_trans)
475 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
476 46b9c89b 2020-01-15 tracey struct gw_dir *gw_dir = NULL;
477 2c251c14 2020-01-15 tracey char *html, *navs, *next, *prev;
478 387a29ba 2020-01-15 tracey unsigned int prev_disp = 0, next_disp = 1, dir_c = 0;
480 54415d85 2020-01-15 tracey error = gw_apply_unveil(gw_trans->gw_conf->got_repos_path, NULL);
481 46b9c89b 2020-01-15 tracey if (error)
482 46b9c89b 2020-01-15 tracey return error;
484 2c251c14 2020-01-15 tracey error = gw_load_got_paths(gw_trans);
485 46b9c89b 2020-01-15 tracey if (error)
486 2c251c14 2020-01-15 tracey return error;
488 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, index_projects_header);
490 46b9c89b 2020-01-15 tracey TAILQ_FOREACH(gw_dir, &gw_trans->gw_dirs, entry)
493 46b9c89b 2020-01-15 tracey TAILQ_FOREACH(gw_dir, &gw_trans->gw_dirs, entry) {
494 2c251c14 2020-01-15 tracey if (gw_trans->page > 0 && (gw_trans->page *
495 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_max_repos_display) > prev_disp) {
496 2c251c14 2020-01-15 tracey prev_disp++;
497 2c251c14 2020-01-15 tracey continue;
500 2c251c14 2020-01-15 tracey prev_disp++;
501 46b9c89b 2020-01-15 tracey if((asprintf(&navs, index_navs, gw_dir->name, gw_dir->name,
502 46b9c89b 2020-01-15 tracey gw_dir->name, gw_dir->name)) == -1)
503 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
505 46b9c89b 2020-01-15 tracey if ((asprintf(&html, index_projects, gw_dir->name, gw_dir->name,
506 46b9c89b 2020-01-15 tracey gw_dir->description, gw_dir->owner, gw_dir->age,
507 46b9c89b 2020-01-15 tracey navs)) == -1)
508 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
510 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, html);
512 2c251c14 2020-01-15 tracey free(navs);
513 2c251c14 2020-01-15 tracey free(html);
515 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_max_repos_display == 0)
516 2c251c14 2020-01-15 tracey continue;
518 2c251c14 2020-01-15 tracey if (next_disp == gw_trans->gw_conf->got_max_repos_display)
519 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, np_wrapper_start);
520 2c251c14 2020-01-15 tracey else if ((gw_trans->gw_conf->got_max_repos_display > 0) &&
521 2c251c14 2020-01-15 tracey (gw_trans->page > 0) &&
522 2c251c14 2020-01-15 tracey (next_disp == gw_trans->gw_conf->got_max_repos_display ||
523 2c251c14 2020-01-15 tracey prev_disp == gw_trans->repos_total))
524 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, np_wrapper_start);
526 2c251c14 2020-01-15 tracey if ((gw_trans->gw_conf->got_max_repos_display > 0) &&
527 2c251c14 2020-01-15 tracey (gw_trans->page > 0) &&
528 2c251c14 2020-01-15 tracey (next_disp == gw_trans->gw_conf->got_max_repos_display ||
529 2c251c14 2020-01-15 tracey prev_disp == gw_trans->repos_total)) {
530 2c251c14 2020-01-15 tracey if ((asprintf(&prev, nav_prev,
531 2c251c14 2020-01-15 tracey gw_trans->page - 1)) == -1)
532 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
533 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, prev);
534 2c251c14 2020-01-15 tracey free(prev);
537 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, div_end);
539 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_max_repos_display > 0 &&
540 2c251c14 2020-01-15 tracey next_disp == gw_trans->gw_conf->got_max_repos_display &&
541 2c251c14 2020-01-15 tracey dir_c != (gw_trans->page + 1) *
542 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_max_repos_display) {
543 2c251c14 2020-01-15 tracey if ((asprintf(&next, nav_next,
544 2c251c14 2020-01-15 tracey gw_trans->page + 1)) == -1)
545 2c251c14 2020-01-15 tracey return got_error_from_errno("calloc");
546 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, next);
547 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, div_end);
548 2c251c14 2020-01-15 tracey free(next);
549 2c251c14 2020-01-15 tracey next_disp = 0;
553 2c251c14 2020-01-15 tracey if ((gw_trans->gw_conf->got_max_repos_display > 0) &&
554 2c251c14 2020-01-15 tracey (gw_trans->page > 0) &&
555 2c251c14 2020-01-15 tracey (next_disp == gw_trans->gw_conf->got_max_repos_display ||
556 2c251c14 2020-01-15 tracey prev_disp == gw_trans->repos_total))
557 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, div_end);
559 2c251c14 2020-01-15 tracey next_disp++;
561 2c251c14 2020-01-15 tracey return error;
564 2c251c14 2020-01-15 tracey static const struct got_error *
565 54415d85 2020-01-15 tracey gw_log(struct gw_trans *gw_trans)
567 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
568 4ceb8155 2020-01-15 tracey char *log, *log_html;
570 54415d85 2020-01-15 tracey error = gw_apply_unveil(gw_trans->gw_dir->path, NULL);
571 8087c3c5 2020-01-15 tracey if (error)
572 8087c3c5 2020-01-15 tracey return error;
574 87f9ebf5 2020-01-15 tracey log = gw_get_repo_log(gw_trans, NULL, gw_trans->commit,
575 8087c3c5 2020-01-15 tracey gw_trans->gw_conf->got_max_commits_display, LOGFULL);
577 4ceb8155 2020-01-15 tracey if (log != NULL && strcmp(log, "") != 0) {
578 4ceb8155 2020-01-15 tracey if ((asprintf(&log_html, logs, log)) == -1)
579 4ceb8155 2020-01-15 tracey return got_error_from_errno("asprintf");
580 4ceb8155 2020-01-15 tracey khttp_puts(gw_trans->gw_req, log_html);
581 4ceb8155 2020-01-15 tracey free(log_html);
582 4ceb8155 2020-01-15 tracey free(log);
584 2c251c14 2020-01-15 tracey return error;
587 2c251c14 2020-01-15 tracey static const struct got_error *
588 54415d85 2020-01-15 tracey gw_raw(struct gw_trans *gw_trans)
590 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
592 2c251c14 2020-01-15 tracey return error;
595 2c251c14 2020-01-15 tracey static const struct got_error *
596 54415d85 2020-01-15 tracey gw_logbriefs(struct gw_trans *gw_trans)
598 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
599 8087c3c5 2020-01-15 tracey char *log, *log_html;
601 54415d85 2020-01-15 tracey error = gw_apply_unveil(gw_trans->gw_dir->path, NULL);
602 8087c3c5 2020-01-15 tracey if (error)
603 8087c3c5 2020-01-15 tracey return error;
605 87f9ebf5 2020-01-15 tracey log = gw_get_repo_log(gw_trans, NULL, gw_trans->commit,
606 8087c3c5 2020-01-15 tracey gw_trans->gw_conf->got_max_commits_display, LOGBRIEF);
608 8087c3c5 2020-01-15 tracey if (log != NULL && strcmp(log, "") != 0) {
609 8087c3c5 2020-01-15 tracey if ((asprintf(&log_html, summary_logbriefs,
610 8087c3c5 2020-01-15 tracey log)) == -1)
611 9d84e7dd 2020-01-15 tracey return got_error_from_errno("asprintf");
612 8087c3c5 2020-01-15 tracey khttp_puts(gw_trans->gw_req, log_html);
613 8087c3c5 2020-01-15 tracey free(log_html);
614 8087c3c5 2020-01-15 tracey free(log);
616 2c251c14 2020-01-15 tracey return error;
619 2c251c14 2020-01-15 tracey static const struct got_error *
620 54415d85 2020-01-15 tracey gw_summary(struct gw_trans *gw_trans)
622 387a29ba 2020-01-15 tracey const struct got_error *error = NULL;
623 46b9c89b 2020-01-15 tracey char *description_html, *repo_owner_html, *repo_age_html,
624 8087c3c5 2020-01-15 tracey *cloneurl_html, *log, *log_html, *tags, *heads, *tags_html,
625 8087c3c5 2020-01-15 tracey *heads_html, *age;
627 54415d85 2020-01-15 tracey error = gw_apply_unveil(gw_trans->gw_dir->path, NULL);
628 46b9c89b 2020-01-15 tracey if (error)
629 46b9c89b 2020-01-15 tracey return error;
631 46b9c89b 2020-01-15 tracey khttp_puts(gw_trans->gw_req, summary_wrapper);
632 46b9c89b 2020-01-15 tracey if (gw_trans->gw_conf->got_show_repo_description) {
633 46b9c89b 2020-01-15 tracey if (gw_trans->gw_dir->description != NULL &&
634 46b9c89b 2020-01-15 tracey (strcmp(gw_trans->gw_dir->description, "") != 0)) {
635 46b9c89b 2020-01-15 tracey if ((asprintf(&description_html, description,
636 46b9c89b 2020-01-15 tracey gw_trans->gw_dir->description)) == -1)
637 46b9c89b 2020-01-15 tracey return got_error_from_errno("asprintf");
639 46b9c89b 2020-01-15 tracey khttp_puts(gw_trans->gw_req, description_html);
640 46b9c89b 2020-01-15 tracey free(description_html);
644 46b9c89b 2020-01-15 tracey if (gw_trans->gw_conf->got_show_repo_owner) {
645 46b9c89b 2020-01-15 tracey if (gw_trans->gw_dir->owner != NULL &&
646 46b9c89b 2020-01-15 tracey (strcmp(gw_trans->gw_dir->owner, "") != 0)) {
647 46b9c89b 2020-01-15 tracey if ((asprintf(&repo_owner_html, repo_owner,
648 46b9c89b 2020-01-15 tracey gw_trans->gw_dir->owner)) == -1)
649 46b9c89b 2020-01-15 tracey return got_error_from_errno("asprintf");
651 46b9c89b 2020-01-15 tracey khttp_puts(gw_trans->gw_req, repo_owner_html);
652 46b9c89b 2020-01-15 tracey free(repo_owner_html);
656 46b9c89b 2020-01-15 tracey if (gw_trans->gw_conf->got_show_repo_age) {
657 c6b62706 2020-01-15 tracey age = gw_get_repo_age(gw_trans, gw_trans->gw_dir->path,
658 c6b62706 2020-01-15 tracey "refs/heads", TM_LONG);
659 c6b62706 2020-01-15 tracey if (age != NULL && (strcmp(age, "") != 0)) {
660 c6b62706 2020-01-15 tracey if ((asprintf(&repo_age_html, last_change, age)) == -1)
661 46b9c89b 2020-01-15 tracey return got_error_from_errno("asprintf");
663 46b9c89b 2020-01-15 tracey khttp_puts(gw_trans->gw_req, repo_age_html);
664 46b9c89b 2020-01-15 tracey free(repo_age_html);
665 c6b62706 2020-01-15 tracey free(age);
669 46b9c89b 2020-01-15 tracey if (gw_trans->gw_conf->got_show_repo_cloneurl) {
670 46b9c89b 2020-01-15 tracey if (gw_trans->gw_dir->url != NULL &&
671 46b9c89b 2020-01-15 tracey (strcmp(gw_trans->gw_dir->url, "") != 0)) {
672 46b9c89b 2020-01-15 tracey if ((asprintf(&cloneurl_html, cloneurl,
673 46b9c89b 2020-01-15 tracey gw_trans->gw_dir->url)) == -1)
674 46b9c89b 2020-01-15 tracey return got_error_from_errno("asprintf");
676 46b9c89b 2020-01-15 tracey khttp_puts(gw_trans->gw_req, cloneurl_html);
677 46b9c89b 2020-01-15 tracey free(cloneurl_html);
680 46b9c89b 2020-01-15 tracey khttp_puts(gw_trans->gw_req, div_end);
682 8087c3c5 2020-01-15 tracey log = gw_get_repo_log(gw_trans, NULL, NULL, D_MAXSLCOMMDISP, 0);
683 87f9ebf5 2020-01-15 tracey tags = gw_get_repo_tags(gw_trans, D_MAXSLCOMMDISP, TAGBRIEF);
684 8d4d2453 2020-01-15 tracey heads = gw_get_repo_heads(gw_trans);
686 8087c3c5 2020-01-15 tracey if (log != NULL && strcmp(log, "") != 0) {
687 8087c3c5 2020-01-15 tracey if ((asprintf(&log_html, summary_logbriefs,
688 8087c3c5 2020-01-15 tracey log)) == -1)
689 8d4d2453 2020-01-15 tracey return got_error_from_errno("asprintf");
690 8087c3c5 2020-01-15 tracey khttp_puts(gw_trans->gw_req, log_html);
691 8087c3c5 2020-01-15 tracey free(log_html);
692 8087c3c5 2020-01-15 tracey free(log);
695 8d4d2453 2020-01-15 tracey if (tags != NULL && strcmp(tags, "") != 0) {
696 8d4d2453 2020-01-15 tracey if ((asprintf(&tags_html, summary_tags,
697 8d4d2453 2020-01-15 tracey tags)) == -1)
698 8d4d2453 2020-01-15 tracey return got_error_from_errno("asprintf");
699 8d4d2453 2020-01-15 tracey khttp_puts(gw_trans->gw_req, tags_html);
700 8d4d2453 2020-01-15 tracey free(tags_html);
701 8d4d2453 2020-01-15 tracey free(tags);
704 8d4d2453 2020-01-15 tracey if (heads != NULL && strcmp(heads, "") != 0) {
705 8d4d2453 2020-01-15 tracey if ((asprintf(&heads_html, summary_heads,
706 8d4d2453 2020-01-15 tracey heads)) == -1)
707 8d4d2453 2020-01-15 tracey return got_error_from_errno("asprintf");
708 8d4d2453 2020-01-15 tracey khttp_puts(gw_trans->gw_req, heads_html);
709 8d4d2453 2020-01-15 tracey free(heads_html);
710 8d4d2453 2020-01-15 tracey free(heads);
712 2204c934 2020-01-15 tracey return error;
715 2204c934 2020-01-15 tracey static const struct got_error *
716 54415d85 2020-01-15 tracey gw_tag(struct gw_trans *gw_trans)
718 b772de24 2020-01-15 tracey const struct got_error *error = NULL;
719 b772de24 2020-01-15 tracey char *log, *log_html;
721 54415d85 2020-01-15 tracey error = gw_apply_unveil(gw_trans->gw_dir->path, NULL);
722 b772de24 2020-01-15 tracey if (error)
723 b772de24 2020-01-15 tracey return error;
725 b772de24 2020-01-15 tracey log = gw_get_repo_log(gw_trans, NULL, gw_trans->commit, 1, LOGTAG);
727 b772de24 2020-01-15 tracey if (log != NULL && strcmp(log, "") != 0) {
728 9460dac0 2020-01-15 tracey if ((asprintf(&log_html, log_tag, log)) == -1)
729 b772de24 2020-01-15 tracey return got_error_from_errno("asprintf");
730 b772de24 2020-01-15 tracey khttp_puts(gw_trans->gw_req, log_html);
731 b772de24 2020-01-15 tracey free(log_html);
732 b772de24 2020-01-15 tracey free(log);
734 b772de24 2020-01-15 tracey return error;
737 b772de24 2020-01-15 tracey static const struct got_error *
738 54415d85 2020-01-15 tracey gw_tree(struct gw_trans *gw_trans)
740 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
741 8087c3c5 2020-01-15 tracey char *log, *log_html;
743 54415d85 2020-01-15 tracey error = gw_apply_unveil(gw_trans->gw_dir->path, NULL);
744 8087c3c5 2020-01-15 tracey if (error)
745 8087c3c5 2020-01-15 tracey return error;
747 8087c3c5 2020-01-15 tracey log = gw_get_repo_log(gw_trans, NULL, gw_trans->commit, 1, LOGTREE);
749 8087c3c5 2020-01-15 tracey if (log != NULL && strcmp(log, "") != 0) {
750 8087c3c5 2020-01-15 tracey if ((asprintf(&log_html, log_tree, log)) == -1)
751 8087c3c5 2020-01-15 tracey return got_error_from_errno("asprintf");
752 8087c3c5 2020-01-15 tracey khttp_puts(gw_trans->gw_req, log_html);
753 8087c3c5 2020-01-15 tracey free(log_html);
754 8087c3c5 2020-01-15 tracey free(log);
756 2c251c14 2020-01-15 tracey return error;
759 2c251c14 2020-01-15 tracey static const struct got_error *
760 54415d85 2020-01-15 tracey gw_load_got_path(struct gw_trans *gw_trans, struct gw_dir *gw_dir)
762 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
764 2c251c14 2020-01-15 tracey char *dir_test;
765 4ceb8155 2020-01-15 tracey int opened = 0;
767 2c251c14 2020-01-15 tracey if ((asprintf(&dir_test, "%s/%s/%s",
768 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path, gw_dir->name,
769 2c251c14 2020-01-15 tracey GOTWEB_GIT_DIR)) == -1)
770 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
772 2c251c14 2020-01-15 tracey dt = opendir(dir_test);
773 2c251c14 2020-01-15 tracey if (dt == NULL) {
774 2c251c14 2020-01-15 tracey free(dir_test);
776 2c251c14 2020-01-15 tracey gw_dir->path = strdup(dir_test);
777 4ceb8155 2020-01-15 tracey opened = 1;
778 2c251c14 2020-01-15 tracey goto done;
781 2c251c14 2020-01-15 tracey if ((asprintf(&dir_test, "%s/%s/%s",
782 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path, gw_dir->name,
783 2c251c14 2020-01-15 tracey GOTWEB_GOT_DIR)) == -1)
784 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
786 2c251c14 2020-01-15 tracey dt = opendir(dir_test);
787 2c251c14 2020-01-15 tracey if (dt == NULL)
788 2c251c14 2020-01-15 tracey free(dir_test);
790 4ceb8155 2020-01-15 tracey opened = 1;
791 2c251c14 2020-01-15 tracey error = got_error(GOT_ERR_NOT_GIT_REPO);
792 2c251c14 2020-01-15 tracey goto errored;
795 2c251c14 2020-01-15 tracey if ((asprintf(&dir_test, "%s/%s",
796 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path, gw_dir->name)) == -1)
797 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
799 2c251c14 2020-01-15 tracey gw_dir->path = strdup(dir_test);
802 2c251c14 2020-01-15 tracey gw_dir->description = gw_get_repo_description(gw_trans,
803 2c251c14 2020-01-15 tracey gw_dir->path);
804 2c251c14 2020-01-15 tracey gw_dir->owner = gw_get_repo_owner(gw_trans, gw_dir->path);
805 387a29ba 2020-01-15 tracey gw_dir->age = gw_get_repo_age(gw_trans, gw_dir->path, "refs/heads",
806 387a29ba 2020-01-15 tracey TM_DIFF);
807 2c251c14 2020-01-15 tracey gw_dir->url = gw_get_clone_url(gw_trans, gw_dir->path);
810 2c251c14 2020-01-15 tracey free(dir_test);
811 2c251c14 2020-01-15 tracey if (opened)
812 2c251c14 2020-01-15 tracey closedir(dt);
813 2c251c14 2020-01-15 tracey return error;
816 2c251c14 2020-01-15 tracey static const struct got_error *
817 54415d85 2020-01-15 tracey gw_load_got_paths(struct gw_trans *gw_trans)
819 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
821 2c251c14 2020-01-15 tracey struct dirent **sd_dent;
822 2c251c14 2020-01-15 tracey struct gw_dir *gw_dir;
823 2c251c14 2020-01-15 tracey struct stat st;
824 2c251c14 2020-01-15 tracey unsigned int d_cnt, d_i;
826 2c251c14 2020-01-15 tracey d = opendir(gw_trans->gw_conf->got_repos_path);
827 2c251c14 2020-01-15 tracey if (d == NULL) {
828 2c251c14 2020-01-15 tracey error = got_error_from_errno2("opendir",
829 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path);
830 2c251c14 2020-01-15 tracey return error;
833 2c251c14 2020-01-15 tracey d_cnt = scandir(gw_trans->gw_conf->got_repos_path, &sd_dent, NULL,
834 2c251c14 2020-01-15 tracey alphasort);
835 2c251c14 2020-01-15 tracey if (d_cnt == -1) {
836 2c251c14 2020-01-15 tracey error = got_error_from_errno2("scandir",
837 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_repos_path);
838 2c251c14 2020-01-15 tracey return error;
841 2c251c14 2020-01-15 tracey for (d_i = 0; d_i < d_cnt; d_i++) {
842 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_max_repos > 0 &&
843 2c251c14 2020-01-15 tracey (d_i - 2) == gw_trans->gw_conf->got_max_repos)
844 2c251c14 2020-01-15 tracey break; /* account for parent and self */
846 2c251c14 2020-01-15 tracey if (strcmp(sd_dent[d_i]->d_name, ".") == 0 ||
847 2c251c14 2020-01-15 tracey strcmp(sd_dent[d_i]->d_name, "..") == 0)
848 2c251c14 2020-01-15 tracey continue;
850 2c251c14 2020-01-15 tracey if ((gw_dir = gw_init_gw_dir(sd_dent[d_i]->d_name)) == NULL)
851 2c251c14 2020-01-15 tracey return got_error_from_errno("gw_dir malloc");
853 2c251c14 2020-01-15 tracey error = gw_load_got_path(gw_trans, gw_dir);
854 2c251c14 2020-01-15 tracey if (error && error->code == GOT_ERR_NOT_GIT_REPO)
855 2c251c14 2020-01-15 tracey continue;
856 2c251c14 2020-01-15 tracey else if (error)
857 2c251c14 2020-01-15 tracey return error;
859 2c251c14 2020-01-15 tracey if (lstat(gw_dir->path, &st) == 0 && S_ISDIR(st.st_mode) &&
860 2c251c14 2020-01-15 tracey !got_path_dir_is_empty(gw_dir->path)) {
861 2c251c14 2020-01-15 tracey TAILQ_INSERT_TAIL(&gw_trans->gw_dirs, gw_dir,
863 2c251c14 2020-01-15 tracey gw_trans->repos_total++;
867 2c251c14 2020-01-15 tracey closedir(d);
868 2c251c14 2020-01-15 tracey return error;
871 2c251c14 2020-01-15 tracey static const struct got_error *
872 54415d85 2020-01-15 tracey gw_parse_querystring(struct gw_trans *gw_trans)
874 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
875 2c251c14 2020-01-15 tracey struct kpair *p;
876 2c251c14 2020-01-15 tracey struct gw_query_action *action = NULL;
877 2c251c14 2020-01-15 tracey unsigned int i;
879 2c251c14 2020-01-15 tracey if (gw_trans->gw_req->fieldnmap[0]) {
880 2c251c14 2020-01-15 tracey error = got_error_from_errno("bad parse");
881 2c251c14 2020-01-15 tracey return error;
882 2c251c14 2020-01-15 tracey } else if ((p = gw_trans->gw_req->fieldmap[KEY_PATH])) {
883 2c251c14 2020-01-15 tracey /* define gw_trans->repo_path */
884 2c251c14 2020-01-15 tracey if ((asprintf(&gw_trans->repo_name, "%s", p->parsed.s)) == -1)
885 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
887 2c251c14 2020-01-15 tracey if ((asprintf(&gw_trans->repo_path, "%s/%s",
888 387a29ba 2020-01-15 tracey gw_trans->gw_conf->got_repos_path, p->parsed.s)) == -1)
889 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
891 2c251c14 2020-01-15 tracey /* get action and set function */
892 2c251c14 2020-01-15 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_ACTION]))
893 2c251c14 2020-01-15 tracey for (i = 0; i < nitems(gw_query_funcs); i++) {
894 2c251c14 2020-01-15 tracey action = &gw_query_funcs[i];
895 2c251c14 2020-01-15 tracey if (action->func_name == NULL)
896 2c251c14 2020-01-15 tracey continue;
898 2c251c14 2020-01-15 tracey if (strcmp(action->func_name,
899 2c251c14 2020-01-15 tracey p->parsed.s) == 0) {
900 2c251c14 2020-01-15 tracey gw_trans->action = i;
901 2c251c14 2020-01-15 tracey if ((asprintf(&gw_trans->action_name,
902 2c251c14 2020-01-15 tracey "%s", action->func_name)) == -1)
904 b772de24 2020-01-15 tracey got_error_from_errno(
905 2c251c14 2020-01-15 tracey "asprintf");
910 2c251c14 2020-01-15 tracey action = NULL;
913 ec46ccd7 2020-01-15 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_COMMIT_ID]))
914 ec46ccd7 2020-01-15 tracey if ((asprintf(&gw_trans->commit, "%s",
915 ec46ccd7 2020-01-15 tracey p->parsed.s)) == -1)
916 ec46ccd7 2020-01-15 tracey return got_error_from_errno("asprintf");
918 2c251c14 2020-01-15 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_FILE]))
919 2c251c14 2020-01-15 tracey if ((asprintf(&gw_trans->repo_file, "%s",
920 8087c3c5 2020-01-15 tracey p->parsed.s)) == -1)
921 8087c3c5 2020-01-15 tracey return got_error_from_errno("asprintf");
923 ec46ccd7 2020-01-15 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_FOLDER]))
924 ec46ccd7 2020-01-15 tracey if ((asprintf(&gw_trans->repo_folder, "%s",
925 ec46ccd7 2020-01-15 tracey p->parsed.s)) == -1)
926 ec46ccd7 2020-01-15 tracey return got_error_from_errno("asprintf");
928 8087c3c5 2020-01-15 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_HEADREF]))
929 8087c3c5 2020-01-15 tracey if ((asprintf(&gw_trans->headref, "%s",
930 2c251c14 2020-01-15 tracey p->parsed.s)) == -1)
931 2c251c14 2020-01-15 tracey return got_error_from_errno("asprintf");
933 2c251c14 2020-01-15 tracey if (action == NULL) {
934 2c251c14 2020-01-15 tracey error = got_error_from_errno("invalid action");
935 2c251c14 2020-01-15 tracey return error;
937 46b9c89b 2020-01-15 tracey if ((gw_trans->gw_dir =
938 46b9c89b 2020-01-15 tracey gw_init_gw_dir(gw_trans->repo_name)) == NULL)
939 46b9c89b 2020-01-15 tracey return got_error_from_errno("gw_dir malloc");
941 46b9c89b 2020-01-15 tracey error = gw_load_got_path(gw_trans, gw_trans->gw_dir);
942 46b9c89b 2020-01-15 tracey if (error)
943 46b9c89b 2020-01-15 tracey return error;
945 2c251c14 2020-01-15 tracey gw_trans->action = GW_INDEX;
947 2c251c14 2020-01-15 tracey if ((p = gw_trans->gw_req->fieldmap[KEY_PAGE]))
948 2c251c14 2020-01-15 tracey gw_trans->page = p->parsed.i;
950 2c251c14 2020-01-15 tracey if (gw_trans->action == GW_RAW)
951 387a29ba 2020-01-15 tracey gw_trans->mime = KMIME_TEXT_PLAIN;
953 2c251c14 2020-01-15 tracey return error;
956 2c251c14 2020-01-15 tracey static struct gw_dir *
957 2c251c14 2020-01-15 tracey gw_init_gw_dir(char *dir)
959 2c251c14 2020-01-15 tracey struct gw_dir *gw_dir;
961 2c251c14 2020-01-15 tracey if ((gw_dir = malloc(sizeof(*gw_dir))) == NULL)
962 2c251c14 2020-01-15 tracey return NULL;
964 2c251c14 2020-01-15 tracey if ((asprintf(&gw_dir->name, "%s", dir)) == -1)
965 2c251c14 2020-01-15 tracey return NULL;
967 2c251c14 2020-01-15 tracey return gw_dir;
970 474370cb 2020-01-15 tracey static const struct got_error*
971 f2915494 2020-01-15 tracey gw_match_logmsg(int *have_match, struct got_object_id *id,
972 474370cb 2020-01-15 tracey struct got_commit_object *commit, regex_t *regex)
974 474370cb 2020-01-15 tracey const struct got_error *err = NULL;
975 474370cb 2020-01-15 tracey regmatch_t regmatch;
976 474370cb 2020-01-15 tracey char *id_str = NULL, *logmsg = NULL;
978 474370cb 2020-01-15 tracey *have_match = 0;
980 474370cb 2020-01-15 tracey err = got_object_id_str(&id_str, id);
982 474370cb 2020-01-15 tracey return err;
984 474370cb 2020-01-15 tracey err = got_object_commit_get_logmsg(&logmsg, commit);
986 474370cb 2020-01-15 tracey goto done;
988 474370cb 2020-01-15 tracey if (regexec(regex, logmsg, 1, ®match, 0) == 0)
989 474370cb 2020-01-15 tracey *have_match = 1;
991 474370cb 2020-01-15 tracey free(id_str);
992 474370cb 2020-01-15 tracey free(logmsg);
993 474370cb 2020-01-15 tracey return err;
996 2c251c14 2020-01-15 tracey static void
997 54415d85 2020-01-15 tracey gw_display_open(struct gw_trans *gw_trans, enum khttp code, enum kmime mime)
999 2c251c14 2020-01-15 tracey khttp_head(gw_trans->gw_req, kresps[KRESP_ALLOW], "GET");
1000 2c251c14 2020-01-15 tracey khttp_head(gw_trans->gw_req, kresps[KRESP_STATUS], "%s",
1001 2c251c14 2020-01-15 tracey khttps[code]);
1002 387a29ba 2020-01-15 tracey khttp_head(gw_trans->gw_req, kresps[KRESP_CONTENT_TYPE], "%s",
1003 2c251c14 2020-01-15 tracey kmimetypes[mime]);
1004 2c251c14 2020-01-15 tracey khttp_head(gw_trans->gw_req, "X-Content-Type-Options", "nosniff");
1005 2c251c14 2020-01-15 tracey khttp_head(gw_trans->gw_req, "X-Frame-Options", "DENY");
1006 2c251c14 2020-01-15 tracey khttp_head(gw_trans->gw_req, "X-XSS-Protection", "1; mode=block");
1007 2c251c14 2020-01-15 tracey khttp_body(gw_trans->gw_req);
1010 2c251c14 2020-01-15 tracey static void
1011 54415d85 2020-01-15 tracey gw_display_index(struct gw_trans *gw_trans, const struct got_error *err)
1013 2c251c14 2020-01-15 tracey gw_display_open(gw_trans, KHTTP_200, gw_trans->mime);
1014 2c251c14 2020-01-15 tracey khtml_open(gw_trans->gw_html_req, gw_trans->gw_req, 0);
1016 2c251c14 2020-01-15 tracey if (err)
1017 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, err->msg);
1019 2c251c14 2020-01-15 tracey khttp_template(gw_trans->gw_req, gw_trans->gw_tmpl,
1020 2c251c14 2020-01-15 tracey gw_query_funcs[gw_trans->action].template);
1022 2c251c14 2020-01-15 tracey khtml_close(gw_trans->gw_html_req);
1025 2c251c14 2020-01-15 tracey static int
1026 2c251c14 2020-01-15 tracey gw_template(size_t key, void *arg)
1028 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
1029 54415d85 2020-01-15 tracey struct gw_trans *gw_trans = arg;
1030 2c251c14 2020-01-15 tracey char *gw_got_link, *gw_site_link;
1031 2c251c14 2020-01-15 tracey char *site_owner_name, *site_owner_name_h;
1033 2c251c14 2020-01-15 tracey switch (key) {
1034 2c251c14 2020-01-15 tracey case (TEMPL_HEAD):
1035 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, head);
1037 2c251c14 2020-01-15 tracey case(TEMPL_HEADER):
1038 2c251c14 2020-01-15 tracey gw_got_link = gw_get_got_link(gw_trans);
1039 2c251c14 2020-01-15 tracey if (gw_got_link != NULL)
1040 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, gw_got_link);
1042 2c251c14 2020-01-15 tracey free(gw_got_link);
1044 2c251c14 2020-01-15 tracey case (TEMPL_SITEPATH):
1045 2c251c14 2020-01-15 tracey gw_site_link = gw_get_site_link(gw_trans);
1046 2c251c14 2020-01-15 tracey if (gw_site_link != NULL)
1047 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, gw_site_link);
1049 2c251c14 2020-01-15 tracey free(gw_site_link);
1051 2c251c14 2020-01-15 tracey case(TEMPL_TITLE):
1052 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_site_name != NULL)
1053 2c251c14 2020-01-15 tracey khtml_puts(gw_trans->gw_html_req,
1054 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_site_name);
1057 2c251c14 2020-01-15 tracey case (TEMPL_SEARCH):
1058 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, search);
1060 2c251c14 2020-01-15 tracey case(TEMPL_SITEOWNER):
1061 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_site_owner != NULL &&
1062 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_show_site_owner) {
1063 2c251c14 2020-01-15 tracey site_owner_name =
1064 2c251c14 2020-01-15 tracey gw_html_escape(gw_trans->gw_conf->got_site_owner);
1065 2c251c14 2020-01-15 tracey if ((asprintf(&site_owner_name_h, site_owner,
1066 2c251c14 2020-01-15 tracey site_owner_name))
1068 2c251c14 2020-01-15 tracey return 0;
1070 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, site_owner_name_h);
1071 2c251c14 2020-01-15 tracey free(site_owner_name);
1072 2c251c14 2020-01-15 tracey free(site_owner_name_h);
1075 2c251c14 2020-01-15 tracey case(TEMPL_CONTENT):
1076 2c251c14 2020-01-15 tracey error = gw_query_funcs[gw_trans->action].func_main(gw_trans);
1077 2c251c14 2020-01-15 tracey if (error)
1078 2c251c14 2020-01-15 tracey khttp_puts(gw_trans->gw_req, error->msg);
1081 2c251c14 2020-01-15 tracey default:
1082 2c251c14 2020-01-15 tracey return 0;
1085 2c251c14 2020-01-15 tracey return 1;
1088 2c251c14 2020-01-15 tracey static char *
1089 54415d85 2020-01-15 tracey gw_get_repo_description(struct gw_trans *gw_trans, char *dir)
1091 2c251c14 2020-01-15 tracey FILE *f;
1092 2c251c14 2020-01-15 tracey char *description = NULL, *d_file = NULL;
1093 2c251c14 2020-01-15 tracey unsigned int len;
1095 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_show_repo_description == false)
1096 2c251c14 2020-01-15 tracey goto err;
1098 2c251c14 2020-01-15 tracey if ((asprintf(&d_file, "%s/description", dir)) == -1)
1099 2c251c14 2020-01-15 tracey goto err;
1101 2c251c14 2020-01-15 tracey if ((f = fopen(d_file, "r")) == NULL)
1102 2c251c14 2020-01-15 tracey goto err;
1104 2c251c14 2020-01-15 tracey fseek(f, 0, SEEK_END);
1105 2c251c14 2020-01-15 tracey len = ftell(f) + 1;
1106 2c251c14 2020-01-15 tracey fseek(f, 0, SEEK_SET);
1107 2c251c14 2020-01-15 tracey if ((description = calloc(len, sizeof(char *))) == NULL)
1108 2c251c14 2020-01-15 tracey goto err;
1110 2c251c14 2020-01-15 tracey fread(description, 1, len, f);
1111 2c251c14 2020-01-15 tracey fclose(f);
1112 2c251c14 2020-01-15 tracey free(d_file);
1113 2c251c14 2020-01-15 tracey return description;
1115 2c251c14 2020-01-15 tracey if ((asprintf(&description, "%s", "")) == -1)
1116 2c251c14 2020-01-15 tracey return NULL;
1118 2c251c14 2020-01-15 tracey return description;
1121 2c251c14 2020-01-15 tracey static char *
1122 474370cb 2020-01-15 tracey gw_get_time_str(time_t committer_time, int ref_tm)
1124 474370cb 2020-01-15 tracey struct tm tm;
1125 474370cb 2020-01-15 tracey time_t diff_time;
1126 474370cb 2020-01-15 tracey char *years = "years ago", *months = "months ago";
1127 474370cb 2020-01-15 tracey char *weeks = "weeks ago", *days = "days ago", *hours = "hours ago";
1128 474370cb 2020-01-15 tracey char *minutes = "minutes ago", *seconds = "seconds ago";
1129 474370cb 2020-01-15 tracey char *now = "right now";
1130 474370cb 2020-01-15 tracey char *repo_age, *s;
1131 6c6c85af 2020-01-15 tracey char datebuf[29];
1133 474370cb 2020-01-15 tracey switch (ref_tm) {
1134 474370cb 2020-01-15 tracey case TM_DIFF:
1135 474370cb 2020-01-15 tracey diff_time = time(NULL) - committer_time;
1136 474370cb 2020-01-15 tracey if (diff_time > 60 * 60 * 24 * 365 * 2) {
1137 474370cb 2020-01-15 tracey if ((asprintf(&repo_age, "%lld %s",
1138 474370cb 2020-01-15 tracey (diff_time / 60 / 60 / 24 / 365), years)) == -1)
1139 474370cb 2020-01-15 tracey return NULL;
1140 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 60 * 24 * (365 / 12) * 2) {
1141 474370cb 2020-01-15 tracey if ((asprintf(&repo_age, "%lld %s",
1142 474370cb 2020-01-15 tracey (diff_time / 60 / 60 / 24 / (365 / 12)),
1143 474370cb 2020-01-15 tracey months)) == -1)
1144 474370cb 2020-01-15 tracey return NULL;
1145 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 60 * 24 * 7 * 2) {
1146 474370cb 2020-01-15 tracey if ((asprintf(&repo_age, "%lld %s",
1147 474370cb 2020-01-15 tracey (diff_time / 60 / 60 / 24 / 7), weeks)) == -1)
1148 474370cb 2020-01-15 tracey return NULL;
1149 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 60 * 24 * 2) {
1150 474370cb 2020-01-15 tracey if ((asprintf(&repo_age, "%lld %s",
1151 474370cb 2020-01-15 tracey (diff_time / 60 / 60 / 24), days)) == -1)
1152 474370cb 2020-01-15 tracey return NULL;
1153 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 60 * 2) {
1154 474370cb 2020-01-15 tracey if ((asprintf(&repo_age, "%lld %s",
1155 474370cb 2020-01-15 tracey (diff_time / 60 / 60), hours)) == -1)
1156 474370cb 2020-01-15 tracey return NULL;
1157 474370cb 2020-01-15 tracey } else if (diff_time > 60 * 2) {
1158 474370cb 2020-01-15 tracey if ((asprintf(&repo_age, "%lld %s", (diff_time / 60),
1159 474370cb 2020-01-15 tracey minutes)) == -1)
1160 474370cb 2020-01-15 tracey return NULL;
1161 474370cb 2020-01-15 tracey } else if (diff_time > 2) {
1162 474370cb 2020-01-15 tracey if ((asprintf(&repo_age, "%lld %s", diff_time,
1163 474370cb 2020-01-15 tracey seconds)) == -1)
1164 474370cb 2020-01-15 tracey return NULL;
1165 474370cb 2020-01-15 tracey } else {
1166 474370cb 2020-01-15 tracey if ((asprintf(&repo_age, "%s", now)) == -1)
1167 474370cb 2020-01-15 tracey return NULL;
1170 474370cb 2020-01-15 tracey case TM_LONG:
1171 474370cb 2020-01-15 tracey if (gmtime_r(&committer_time, &tm) == NULL)
1172 474370cb 2020-01-15 tracey return NULL;
1174 474370cb 2020-01-15 tracey s = asctime_r(&tm, datebuf);
1175 474370cb 2020-01-15 tracey if (s == NULL)
1176 474370cb 2020-01-15 tracey return NULL;
1178 474370cb 2020-01-15 tracey if ((asprintf(&repo_age, "%s UTC", datebuf)) == -1)
1179 474370cb 2020-01-15 tracey return NULL;
1182 474370cb 2020-01-15 tracey return repo_age;
1185 474370cb 2020-01-15 tracey static char *
1186 d0ea9c5b 2020-01-15 tracey gw_get_repo_age(struct gw_trans *gw_trans, char *dir, char *repo_ref,
1187 d0ea9c5b 2020-01-15 tracey int ref_tm)
1189 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
1190 2c251c14 2020-01-15 tracey struct got_object_id *id = NULL;
1191 2c251c14 2020-01-15 tracey struct got_repository *repo = NULL;
1192 2c251c14 2020-01-15 tracey struct got_commit_object *commit = NULL;
1193 2c251c14 2020-01-15 tracey struct got_reflist_head refs;
1194 2c251c14 2020-01-15 tracey struct got_reflist_entry *re;
1195 2c251c14 2020-01-15 tracey struct got_reference *head_ref;
1196 87f9ebf5 2020-01-15 tracey int is_head = 0;
1197 474370cb 2020-01-15 tracey time_t committer_time = 0, cmp_time = 0;
1198 87f9ebf5 2020-01-15 tracey const char *refname;
1199 474370cb 2020-01-15 tracey char *repo_age = NULL;
1201 387a29ba 2020-01-15 tracey if (repo_ref == NULL)
1202 387a29ba 2020-01-15 tracey return NULL;
1204 87f9ebf5 2020-01-15 tracey if (strncmp(repo_ref, "refs/heads/", 11) == 0)
1205 87f9ebf5 2020-01-15 tracey is_head = 1;
1207 2c251c14 2020-01-15 tracey SIMPLEQ_INIT(&refs);
1208 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_show_repo_age == false) {
1209 8087c3c5 2020-01-15 tracey if ((asprintf(&repo_age, "")) == -1)
1210 8087c3c5 2020-01-15 tracey return NULL;
1211 2c251c14 2020-01-15 tracey return repo_age;
1214 2c251c14 2020-01-15 tracey error = got_repo_open(&repo, dir, NULL);
1215 ec46ccd7 2020-01-15 tracey if (error)
1216 2c251c14 2020-01-15 tracey goto err;
1218 87f9ebf5 2020-01-15 tracey if (is_head)
1219 87f9ebf5 2020-01-15 tracey error = got_ref_list(&refs, repo, "refs/heads",
1220 87f9ebf5 2020-01-15 tracey got_ref_cmp_by_name, NULL);
1222 87f9ebf5 2020-01-15 tracey error = got_ref_list(&refs, repo, repo_ref,
1223 87f9ebf5 2020-01-15 tracey got_ref_cmp_by_name, NULL);
1224 ec46ccd7 2020-01-15 tracey if (error)
1225 2c251c14 2020-01-15 tracey goto err;
1227 2c251c14 2020-01-15 tracey SIMPLEQ_FOREACH(re, &refs, entry) {
1228 87f9ebf5 2020-01-15 tracey if (is_head)
1229 87f9ebf5 2020-01-15 tracey refname = strdup(repo_ref);
1231 87f9ebf5 2020-01-15 tracey refname = got_ref_get_name(re->ref);
1232 2c251c14 2020-01-15 tracey error = got_ref_open(&head_ref, repo, refname, 0);
1233 ec46ccd7 2020-01-15 tracey if (error)
1234 2c251c14 2020-01-15 tracey goto err;
1236 2c251c14 2020-01-15 tracey error = got_ref_resolve(&id, repo, head_ref);
1237 2c251c14 2020-01-15 tracey got_ref_close(head_ref);
1238 ec46ccd7 2020-01-15 tracey if (error)
1239 2c251c14 2020-01-15 tracey goto err;
1241 2c251c14 2020-01-15 tracey error = got_object_open_as_commit(&commit, repo, id);
1242 ec46ccd7 2020-01-15 tracey if (error)
1243 2c251c14 2020-01-15 tracey goto err;
1245 2c251c14 2020-01-15 tracey committer_time =
1246 2c251c14 2020-01-15 tracey got_object_commit_get_committer_time(commit);
1248 387a29ba 2020-01-15 tracey if (cmp_time < committer_time)
1249 2c251c14 2020-01-15 tracey cmp_time = committer_time;
1252 474370cb 2020-01-15 tracey if (cmp_time != 0) {
1253 2c251c14 2020-01-15 tracey committer_time = cmp_time;
1254 474370cb 2020-01-15 tracey repo_age = gw_get_time_str(committer_time, ref_tm);
1256 474370cb 2020-01-15 tracey if ((asprintf(&repo_age, "")) == -1)
1257 474370cb 2020-01-15 tracey return NULL;
1258 2c251c14 2020-01-15 tracey got_ref_list_free(&refs);
1259 2c251c14 2020-01-15 tracey free(id);
1260 2c251c14 2020-01-15 tracey return repo_age;
1262 2c251c14 2020-01-15 tracey if ((asprintf(&repo_age, "%s", error->msg)) == -1)
1263 2c251c14 2020-01-15 tracey return NULL;
1265 2c251c14 2020-01-15 tracey return repo_age;
1268 ec46ccd7 2020-01-15 tracey static char *
1269 54415d85 2020-01-15 tracey gw_get_repo_diff(struct gw_trans *gw_trans, char *id_str1, char *id_str2)
1271 ec46ccd7 2020-01-15 tracey const struct got_error *error;
1272 ec46ccd7 2020-01-15 tracey FILE *f = NULL;
1273 ec46ccd7 2020-01-15 tracey struct got_object_id *id1 = NULL, *id2 = NULL;
1274 ec46ccd7 2020-01-15 tracey struct got_repository *repo = NULL;
1275 ec46ccd7 2020-01-15 tracey struct buf *diffbuf = NULL;
1276 ec46ccd7 2020-01-15 tracey char *label1 = NULL, *label2 = NULL, *diff_html = NULL, *buf = NULL,
1277 ec46ccd7 2020-01-15 tracey *buf_color = NULL;
1278 ec46ccd7 2020-01-15 tracey int type1, type2;
1279 ec46ccd7 2020-01-15 tracey size_t newsize;
1281 ec46ccd7 2020-01-15 tracey f = got_opentemp();
1282 ec46ccd7 2020-01-15 tracey if (f == NULL)
1283 ec46ccd7 2020-01-15 tracey return NULL;
1285 ec46ccd7 2020-01-15 tracey error = buf_alloc(&diffbuf, 0);
1286 ec46ccd7 2020-01-15 tracey if (error)
1287 ec46ccd7 2020-01-15 tracey return NULL;
1289 ec46ccd7 2020-01-15 tracey error = got_repo_open(&repo, gw_trans->repo_path, NULL);
1290 ec46ccd7 2020-01-15 tracey if (error)
1291 ec46ccd7 2020-01-15 tracey goto done;
1293 147269d5 2020-01-15 tracey error = got_repo_match_object_id(&id1, &label1, id_str1,
1294 147269d5 2020-01-15 tracey GOT_OBJ_TYPE_ANY, 1, repo);
1295 ec46ccd7 2020-01-15 tracey if (error)
1296 ec46ccd7 2020-01-15 tracey goto done;
1298 ec46ccd7 2020-01-15 tracey if (id_str2) {
1299 147269d5 2020-01-15 tracey error = got_repo_match_object_id(&id2, &label2, id_str2,
1300 ec46ccd7 2020-01-15 tracey GOT_OBJ_TYPE_ANY, 1, repo);
1301 ec46ccd7 2020-01-15 tracey if (error)
1302 ec46ccd7 2020-01-15 tracey goto done;
1304 ec46ccd7 2020-01-15 tracey error = got_object_get_type(&type2, repo, id2);
1305 ec46ccd7 2020-01-15 tracey if (error)
1306 ec46ccd7 2020-01-15 tracey goto done;
1309 ec46ccd7 2020-01-15 tracey error = got_object_get_type(&type1, repo, id1);
1310 ec46ccd7 2020-01-15 tracey if (error)
1311 ec46ccd7 2020-01-15 tracey goto done;
1313 ec46ccd7 2020-01-15 tracey if (id_str2 && type1 != type2) {
1314 ec46ccd7 2020-01-15 tracey error = got_error(GOT_ERR_OBJ_TYPE);
1315 ec46ccd7 2020-01-15 tracey goto done;
1318 ec46ccd7 2020-01-15 tracey switch (type1) {
1319 ec46ccd7 2020-01-15 tracey case GOT_OBJ_TYPE_BLOB:
1320 ec46ccd7 2020-01-15 tracey error = got_diff_objects_as_blobs(id2, id1, NULL, NULL, 3, 0,
1321 ec46ccd7 2020-01-15 tracey repo, f);
1323 ec46ccd7 2020-01-15 tracey case GOT_OBJ_TYPE_TREE:
1324 ec46ccd7 2020-01-15 tracey error = got_diff_objects_as_trees(id2, id1, "", "", 3, 0, repo,
1327 ec46ccd7 2020-01-15 tracey case GOT_OBJ_TYPE_COMMIT:
1328 ec46ccd7 2020-01-15 tracey error = got_diff_objects_as_commits(id2, id1, 3, 0, repo, f);
1330 ec46ccd7 2020-01-15 tracey default:
1331 ec46ccd7 2020-01-15 tracey error = got_error(GOT_ERR_OBJ_TYPE);
1334 ec46ccd7 2020-01-15 tracey if ((buf = calloc(128, sizeof(char *))) == NULL)
1335 ec46ccd7 2020-01-15 tracey goto done;
1337 ec46ccd7 2020-01-15 tracey fseek(f, 0, SEEK_SET);
1339 ec46ccd7 2020-01-15 tracey while ((fgets(buf, 128, f)) != NULL) {
1340 d0ea9c5b 2020-01-15 tracey buf_color = gw_colordiff_line(buf);
1341 ec46ccd7 2020-01-15 tracey error = buf_puts(&newsize, diffbuf, buf_color);
1342 ec46ccd7 2020-01-15 tracey if (error)
1343 ec46ccd7 2020-01-15 tracey return NULL;
1345 ec46ccd7 2020-01-15 tracey error = buf_puts(&newsize, diffbuf, div_end);
1346 ec46ccd7 2020-01-15 tracey if (error)
1347 ec46ccd7 2020-01-15 tracey return NULL;
1350 ec46ccd7 2020-01-15 tracey if (buf_len(diffbuf) > 0) {
1351 ec46ccd7 2020-01-15 tracey error = buf_putc(diffbuf, '\0');
1352 ec46ccd7 2020-01-15 tracey diff_html = strdup(buf_get(diffbuf));
1355 ec46ccd7 2020-01-15 tracey fclose(f);
1356 ec46ccd7 2020-01-15 tracey free(buf_color);
1357 ec46ccd7 2020-01-15 tracey free(buf);
1358 ec46ccd7 2020-01-15 tracey free(diffbuf);
1359 ec46ccd7 2020-01-15 tracey free(label1);
1360 ec46ccd7 2020-01-15 tracey free(label2);
1361 ec46ccd7 2020-01-15 tracey free(id1);
1362 ec46ccd7 2020-01-15 tracey free(id2);
1363 ec46ccd7 2020-01-15 tracey if (repo)
1364 ec46ccd7 2020-01-15 tracey got_repo_close(repo);
1366 ec46ccd7 2020-01-15 tracey if (error)
1367 ec46ccd7 2020-01-15 tracey return NULL;
1369 ec46ccd7 2020-01-15 tracey return diff_html;
1372 2c251c14 2020-01-15 tracey static char *
1373 54415d85 2020-01-15 tracey gw_get_repo_owner(struct gw_trans *gw_trans, char *dir)
1375 2c251c14 2020-01-15 tracey FILE *f;
1376 2c251c14 2020-01-15 tracey char *owner = NULL, *d_file = NULL;
1377 2c251c14 2020-01-15 tracey char *gotweb = "[gotweb]", *gitweb = "[gitweb]", *gw_owner = "owner";
1378 2c251c14 2020-01-15 tracey char *comp, *pos, *buf;
1379 2c251c14 2020-01-15 tracey unsigned int i;
1381 2c251c14 2020-01-15 tracey if (gw_trans->gw_conf->got_show_repo_owner == false)
1382 2c251c14 2020-01-15 tracey goto err;
1384 2c251c14 2020-01-15 tracey if ((asprintf(&d_file, "%s/config", dir)) == -1)
1385 2c251c14 2020-01-15 tracey goto err;
1387 2c251c14 2020-01-15 tracey if ((f = fopen(d_file, "r")) == NULL)
1388 2c251c14 2020-01-15 tracey goto err;
1390 6c6c85af 2020-01-15 tracey if ((buf = calloc(128, sizeof(char *))) == NULL)
1391 2c251c14 2020-01-15 tracey goto err;
1393 6c6c85af 2020-01-15 tracey while ((fgets(buf, 128, f)) != NULL) {
1394 2c251c14 2020-01-15 tracey if ((pos = strstr(buf, gotweb)) != NULL)
1397 2c251c14 2020-01-15 tracey if ((pos = strstr(buf, gitweb)) != NULL)
1401 2c251c14 2020-01-15 tracey if (pos == NULL)
1402 2c251c14 2020-01-15 tracey goto err;
1405 6c6c85af 2020-01-15 tracey fgets(buf, 128, f);
1406 2c251c14 2020-01-15 tracey } while ((comp = strcasestr(buf, gw_owner)) == NULL);
1408 2c251c14 2020-01-15 tracey if (comp == NULL)
1409 2c251c14 2020-01-15 tracey goto err;
1411 2c251c14 2020-01-15 tracey if (strncmp(gw_owner, comp, strlen(gw_owner)) != 0)
1412 2c251c14 2020-01-15 tracey goto err;
1414 2c251c14 2020-01-15 tracey for (i = 0; i < 2; i++) {
1415 2c251c14 2020-01-15 tracey owner = strsep(&buf, "\"");
1418 2c251c14 2020-01-15 tracey if (owner == NULL)
1419 2c251c14 2020-01-15 tracey goto err;
1421 2c251c14 2020-01-15 tracey fclose(f);
1422 2c251c14 2020-01-15 tracey free(d_file);
1423 2c251c14 2020-01-15 tracey return owner;
1425 2c251c14 2020-01-15 tracey if ((asprintf(&owner, "%s", "")) == -1)
1426 2c251c14 2020-01-15 tracey return NULL;
1428 2c251c14 2020-01-15 tracey return owner;
1431 2c251c14 2020-01-15 tracey static char *
1432 54415d85 2020-01-15 tracey gw_get_clone_url(struct gw_trans *gw_trans, char *dir)
1434 2c251c14 2020-01-15 tracey FILE *f;
1435 2c251c14 2020-01-15 tracey char *url = NULL, *d_file = NULL;
1436 2c251c14 2020-01-15 tracey unsigned int len;
1438 2c251c14 2020-01-15 tracey if ((asprintf(&d_file, "%s/cloneurl", dir)) == -1)
1439 2c251c14 2020-01-15 tracey return NULL;
1441 2c251c14 2020-01-15 tracey if ((f = fopen(d_file, "r")) == NULL)
1442 2c251c14 2020-01-15 tracey return NULL;
1444 2c251c14 2020-01-15 tracey fseek(f, 0, SEEK_END);
1445 2c251c14 2020-01-15 tracey len = ftell(f) + 1;
1446 2c251c14 2020-01-15 tracey fseek(f, 0, SEEK_SET);
1448 2c251c14 2020-01-15 tracey if ((url = calloc(len, sizeof(char *))) == NULL)
1449 2c251c14 2020-01-15 tracey return NULL;
1451 2c251c14 2020-01-15 tracey fread(url, 1, len, f);
1452 2c251c14 2020-01-15 tracey fclose(f);
1453 2c251c14 2020-01-15 tracey free(d_file);
1454 2c251c14 2020-01-15 tracey return url;
1457 8d4d2453 2020-01-15 tracey static char *
1458 54415d85 2020-01-15 tracey gw_get_repo_log(struct gw_trans *gw_trans, const char *search_pattern,
1459 8087c3c5 2020-01-15 tracey char *start_commit, int limit, int log_type)
1461 c6b62706 2020-01-15 tracey const struct got_error *error;
1462 c6b62706 2020-01-15 tracey struct got_repository *repo = NULL;
1463 c6b62706 2020-01-15 tracey struct got_reflist_head refs;
1464 474370cb 2020-01-15 tracey struct got_reflist_entry *re;
1465 c6b62706 2020-01-15 tracey struct got_commit_object *commit = NULL;
1466 8087c3c5 2020-01-15 tracey struct got_object_id *id1 = NULL, *id2 = NULL;
1467 8087c3c5 2020-01-15 tracey struct got_object_qid *parent_id;
1468 474370cb 2020-01-15 tracey struct got_commit_graph *graph = NULL;
1469 87f9ebf5 2020-01-15 tracey char *logs = NULL, *id_str1 = NULL, *id_str2 = NULL, *path = NULL,
1470 87f9ebf5 2020-01-15 tracey *in_repo_path = NULL, *refs_str = NULL, *refs_str_disp = NULL,
1471 87f9ebf5 2020-01-15 tracey *treeid = NULL, *commit_row = NULL, *commit_commit = NULL,
1472 87f9ebf5 2020-01-15 tracey *commit_commit_disp = NULL, *commit_age_diff = NULL,
1473 87f9ebf5 2020-01-15 tracey *commit_age_diff_disp = NULL, *commit_age_long = NULL,
1474 87f9ebf5 2020-01-15 tracey *commit_age_long_disp = NULL, *commit_author = NULL,
1475 87f9ebf5 2020-01-15 tracey *commit_author_disp = NULL, *commit_committer = NULL,
1476 87f9ebf5 2020-01-15 tracey *commit_committer_disp = NULL, *commit_log = NULL,
1477 87f9ebf5 2020-01-15 tracey *commit_log_disp = NULL, *commit_parent = NULL,
1478 87f9ebf5 2020-01-15 tracey *commit_diff_disp = NULL, *logbriefs_navs_html = NULL,
1479 87f9ebf5 2020-01-15 tracey *log_tree_html = NULL, *log_commit_html = NULL,
1480 87f9ebf5 2020-01-15 tracey *log_diff_html = NULL, *commit_tree = NULL,
1481 ec46ccd7 2020-01-15 tracey *commit_tree_disp = NULL, *log_tag_html = NULL,
1482 ec46ccd7 2020-01-15 tracey *log_blame_html = NULL;
1483 87f9ebf5 2020-01-15 tracey char *commit_log0, *newline;
1484 474370cb 2020-01-15 tracey regex_t regex;
1485 ec46ccd7 2020-01-15 tracey int have_match, log_count = 0, has_parent = 1;
1486 474370cb 2020-01-15 tracey size_t newsize;
1487 8087c3c5 2020-01-15 tracey struct buf *diffbuf = NULL;
1488 474370cb 2020-01-15 tracey time_t committer_time;
1490 65b95fb2 2020-01-15 tracey if (gw_trans->action == GW_LOG || gw_trans->action == GW_LOGBRIEFS)
1491 65b95fb2 2020-01-15 tracey log_count = gw_get_repo_log_count(gw_trans, start_commit);
1493 6c6c85af 2020-01-15 tracey error = buf_alloc(&diffbuf, 0);
1494 ec46ccd7 2020-01-15 tracey if (error)
1495 6c6c85af 2020-01-15 tracey return NULL;
1497 474370cb 2020-01-15 tracey if (search_pattern &&
1498 474370cb 2020-01-15 tracey regcomp(®ex, search_pattern, REG_EXTENDED | REG_NOSUB |
1499 474370cb 2020-01-15 tracey REG_NEWLINE))
1500 474370cb 2020-01-15 tracey return NULL;
1502 c6b62706 2020-01-15 tracey error = got_repo_open(&repo, gw_trans->repo_path, NULL);
1503 ec46ccd7 2020-01-15 tracey if (error)
1504 6c6c85af 2020-01-15 tracey return NULL;
1506 6c6c85af 2020-01-15 tracey SIMPLEQ_INIT(&refs);
1508 c6b62706 2020-01-15 tracey if (start_commit == NULL) {
1509 c6b62706 2020-01-15 tracey struct got_reference *head_ref;
1510 8087c3c5 2020-01-15 tracey error = got_ref_open(&head_ref, repo, gw_trans->headref, 0);
1511 ec46ccd7 2020-01-15 tracey if (error)
1512 8087c3c5 2020-01-15 tracey goto done;
1514 8087c3c5 2020-01-15 tracey error = got_ref_resolve(&id1, repo, head_ref);
1515 c6b62706 2020-01-15 tracey got_ref_close(head_ref);
1516 ec46ccd7 2020-01-15 tracey if (error)
1517 8087c3c5 2020-01-15 tracey goto done;
1519 8087c3c5 2020-01-15 tracey error = got_object_open_as_commit(&commit, repo, id1);
1520 c6b62706 2020-01-15 tracey } else {
1521 c6b62706 2020-01-15 tracey struct got_reference *ref;
1522 c6b62706 2020-01-15 tracey error = got_ref_open(&ref, repo, start_commit, 0);
1523 c6b62706 2020-01-15 tracey if (error == NULL) {
1524 c6b62706 2020-01-15 tracey int obj_type;
1525 8087c3c5 2020-01-15 tracey error = got_ref_resolve(&id1, repo, ref);
1526 c6b62706 2020-01-15 tracey got_ref_close(ref);
1527 ec46ccd7 2020-01-15 tracey if (error)
1528 c6b62706 2020-01-15 tracey goto done;
1529 8087c3c5 2020-01-15 tracey error = got_object_get_type(&obj_type, repo, id1);
1530 ec46ccd7 2020-01-15 tracey if (error)
1531 c6b62706 2020-01-15 tracey goto done;
1532 c6b62706 2020-01-15 tracey if (obj_type == GOT_OBJ_TYPE_TAG) {
1533 c6b62706 2020-01-15 tracey struct got_tag_object *tag;
1534 8087c3c5 2020-01-15 tracey error = got_object_open_as_tag(&tag, repo, id1);
1535 ec46ccd7 2020-01-15 tracey if (error)
1536 c6b62706 2020-01-15 tracey goto done;
1537 c6b62706 2020-01-15 tracey if (got_object_tag_get_object_type(tag) !=
1538 c6b62706 2020-01-15 tracey GOT_OBJ_TYPE_COMMIT) {
1539 c6b62706 2020-01-15 tracey got_object_tag_close(tag);
1540 c6b62706 2020-01-15 tracey error = got_error(GOT_ERR_OBJ_TYPE);
1541 c6b62706 2020-01-15 tracey goto done;
1543 8087c3c5 2020-01-15 tracey free(id1);
1544 8087c3c5 2020-01-15 tracey id1 = got_object_id_dup(
1545 c6b62706 2020-01-15 tracey got_object_tag_get_object_id(tag));
1546 8087c3c5 2020-01-15 tracey if (id1 == NULL)
1547 c6b62706 2020-01-15 tracey error = got_error_from_errno(
1548 c6b62706 2020-01-15 tracey "got_object_id_dup");
1549 c6b62706 2020-01-15 tracey got_object_tag_close(tag);
1550 c6b62706 2020-01-15 tracey if (error)
1551 c6b62706 2020-01-15 tracey goto done;
1552 c6b62706 2020-01-15 tracey } else if (obj_type != GOT_OBJ_TYPE_COMMIT) {
1553 c6b62706 2020-01-15 tracey error = got_error(GOT_ERR_OBJ_TYPE);
1554 c6b62706 2020-01-15 tracey goto done;
1556 8087c3c5 2020-01-15 tracey error = got_object_open_as_commit(&commit, repo, id1);
1557 ec46ccd7 2020-01-15 tracey if (error)
1558 c6b62706 2020-01-15 tracey goto done;
1560 c6b62706 2020-01-15 tracey if (commit == NULL) {
1561 8087c3c5 2020-01-15 tracey error = got_repo_match_object_id_prefix(&id1,
1562 c6b62706 2020-01-15 tracey start_commit, GOT_OBJ_TYPE_COMMIT, repo);
1563 ec46ccd7 2020-01-15 tracey if (error)
1564 8087c3c5 2020-01-15 tracey goto done;
1566 8087c3c5 2020-01-15 tracey error = got_repo_match_object_id_prefix(&id1,
1567 8087c3c5 2020-01-15 tracey start_commit, GOT_OBJ_TYPE_COMMIT, repo);
1570 ec46ccd7 2020-01-15 tracey if (error)
1571 c6b62706 2020-01-15 tracey goto done;
1573 474370cb 2020-01-15 tracey error = got_repo_map_path(&in_repo_path, repo, gw_trans->repo_path, 1);
1574 ec46ccd7 2020-01-15 tracey if (error)
1575 474370cb 2020-01-15 tracey goto done;
1577 474370cb 2020-01-15 tracey if (in_repo_path) {
1578 474370cb 2020-01-15 tracey free(path);
1579 474370cb 2020-01-15 tracey path = in_repo_path;
1582 c6b62706 2020-01-15 tracey error = got_ref_list(&refs, repo, NULL, got_ref_cmp_by_name, NULL);
1583 c6b62706 2020-01-15 tracey if (error)
1584 c6b62706 2020-01-15 tracey goto done;
1586 65b95fb2 2020-01-15 tracey error = got_commit_graph_open(&graph, path, 0);
1587 474370cb 2020-01-15 tracey if (error)
1588 474370cb 2020-01-15 tracey goto done;
1590 8087c3c5 2020-01-15 tracey error = got_commit_graph_iter_start(graph, id1, repo, NULL, NULL);
1591 474370cb 2020-01-15 tracey if (error)
1592 474370cb 2020-01-15 tracey goto done;
1594 474370cb 2020-01-15 tracey for (;;) {
1595 65b95fb2 2020-01-15 tracey error = got_commit_graph_iter_next(&id1, graph, repo, NULL,
1597 474370cb 2020-01-15 tracey if (error) {
1598 65b95fb2 2020-01-15 tracey if (error->code == GOT_ERR_ITER_COMPLETED)
1599 474370cb 2020-01-15 tracey error = NULL;
1602 8087c3c5 2020-01-15 tracey if (id1 == NULL)
1605 8087c3c5 2020-01-15 tracey error = got_object_open_as_commit(&commit, repo, id1);
1606 474370cb 2020-01-15 tracey if (error)
1609 474370cb 2020-01-15 tracey if (search_pattern) {
1610 f2915494 2020-01-15 tracey error = gw_match_logmsg(&have_match, id1, commit,
1611 474370cb 2020-01-15 tracey ®ex);
1612 474370cb 2020-01-15 tracey if (error) {
1613 8087c3c5 2020-01-15 tracey got_object_commit_close(commit);
1616 474370cb 2020-01-15 tracey if (have_match == 0) {
1617 8087c3c5 2020-01-15 tracey got_object_commit_close(commit);
1618 474370cb 2020-01-15 tracey continue;
1622 474370cb 2020-01-15 tracey SIMPLEQ_FOREACH(re, &refs, entry) {
1623 8087c3c5 2020-01-15 tracey char *s;
1624 474370cb 2020-01-15 tracey const char *name;
1625 474370cb 2020-01-15 tracey struct got_tag_object *tag = NULL;
1626 474370cb 2020-01-15 tracey int cmp;
1628 474370cb 2020-01-15 tracey name = got_ref_get_name(re->ref);
1629 474370cb 2020-01-15 tracey if (strcmp(name, GOT_REF_HEAD) == 0)
1630 474370cb 2020-01-15 tracey continue;
1631 474370cb 2020-01-15 tracey if (strncmp(name, "refs/", 5) == 0)
1632 474370cb 2020-01-15 tracey name += 5;
1633 474370cb 2020-01-15 tracey if (strncmp(name, "got/", 4) == 0)
1634 474370cb 2020-01-15 tracey continue;
1635 474370cb 2020-01-15 tracey if (strncmp(name, "heads/", 6) == 0)
1636 474370cb 2020-01-15 tracey name += 6;
1637 474370cb 2020-01-15 tracey if (strncmp(name, "remotes/", 8) == 0)
1638 474370cb 2020-01-15 tracey name += 8;
1639 474370cb 2020-01-15 tracey if (strncmp(name, "tags/", 5) == 0) {
1640 474370cb 2020-01-15 tracey error = got_object_open_as_tag(&tag, repo,
1641 474370cb 2020-01-15 tracey re->id);
1642 474370cb 2020-01-15 tracey if (error) {
1643 474370cb 2020-01-15 tracey if (error->code != GOT_ERR_OBJ_TYPE)
1644 474370cb 2020-01-15 tracey continue;
1646 474370cb 2020-01-15 tracey * Ref points at something other
1647 474370cb 2020-01-15 tracey * than a tag.
1649 474370cb 2020-01-15 tracey error = NULL;
1650 474370cb 2020-01-15 tracey tag = NULL;
1653 474370cb 2020-01-15 tracey cmp = got_object_id_cmp(tag ?
1654 8087c3c5 2020-01-15 tracey got_object_tag_get_object_id(tag) : re->id, id1);
1655 474370cb 2020-01-15 tracey if (tag)
1656 474370cb 2020-01-15 tracey got_object_tag_close(tag);
1657 474370cb 2020-01-15 tracey if (cmp != 0)
1658 474370cb 2020-01-15 tracey continue;
1659 8087c3c5 2020-01-15 tracey s = refs_str;
1660 8087c3c5 2020-01-15 tracey if ((asprintf(&refs_str, "%s%s%s", s ? s : "",
1661 8087c3c5 2020-01-15 tracey s ? ", " : "", name)) == -1) {
1662 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1663 8087c3c5 2020-01-15 tracey free(s);
1664 8087c3c5 2020-01-15 tracey goto done;
1666 8087c3c5 2020-01-15 tracey free(s);
1669 8087c3c5 2020-01-15 tracey if (refs_str == NULL)
1670 8087c3c5 2020-01-15 tracey refs_str_disp = strdup("");
1672 8087c3c5 2020-01-15 tracey if ((asprintf(&refs_str_disp, "(%s)",
1673 8087c3c5 2020-01-15 tracey refs_str)) == -1) {
1674 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1675 8087c3c5 2020-01-15 tracey free(refs_str);
1676 8087c3c5 2020-01-15 tracey goto done;
1680 8087c3c5 2020-01-15 tracey error = got_object_id_str(&id_str1, id1);
1681 474370cb 2020-01-15 tracey if (error)
1682 8087c3c5 2020-01-15 tracey goto done;
1684 87f9ebf5 2020-01-15 tracey error = got_object_id_str(&treeid,
1685 87f9ebf5 2020-01-15 tracey got_object_commit_get_tree_id(commit));
1686 87f9ebf5 2020-01-15 tracey if (error)
1687 87f9ebf5 2020-01-15 tracey goto done;
1689 87f9ebf5 2020-01-15 tracey if (gw_trans->action == GW_COMMIT ||
1690 87f9ebf5 2020-01-15 tracey gw_trans->action == GW_COMMITDIFF) {
1691 8087c3c5 2020-01-15 tracey parent_id =
1692 8087c3c5 2020-01-15 tracey SIMPLEQ_FIRST(
1693 8087c3c5 2020-01-15 tracey got_object_commit_get_parent_ids(commit));
1694 8087c3c5 2020-01-15 tracey if (parent_id != NULL) {
1695 8087c3c5 2020-01-15 tracey id2 = got_object_id_dup(parent_id->id);
1696 8087c3c5 2020-01-15 tracey free (parent_id);
1697 8087c3c5 2020-01-15 tracey error = got_object_id_str(&id_str2, id2);
1698 8087c3c5 2020-01-15 tracey if (error)
1699 8087c3c5 2020-01-15 tracey goto done;
1700 87f9ebf5 2020-01-15 tracey free(id2);
1701 ec46ccd7 2020-01-15 tracey } else {
1702 ec46ccd7 2020-01-15 tracey has_parent = 0;
1703 8087c3c5 2020-01-15 tracey id_str2 = strdup("/dev/null");
1707 474370cb 2020-01-15 tracey committer_time =
1708 8087c3c5 2020-01-15 tracey got_object_commit_get_committer_time(commit);
1710 8087c3c5 2020-01-15 tracey if ((asprintf(&commit_parent, "%s", id_str2)) == -1) {
1711 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1712 8087c3c5 2020-01-15 tracey goto done;
1715 87f9ebf5 2020-01-15 tracey if ((asprintf(&commit_tree, "%s", treeid)) == -1) {
1716 87f9ebf5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1717 87f9ebf5 2020-01-15 tracey goto done;
1720 87f9ebf5 2020-01-15 tracey if ((asprintf(&commit_tree_disp, commit_tree_html,
1721 87f9ebf5 2020-01-15 tracey treeid)) == -1) {
1722 87f9ebf5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1723 87f9ebf5 2020-01-15 tracey goto done;
1726 8087c3c5 2020-01-15 tracey if ((asprintf(&commit_diff_disp, commit_diff_html, id_str2,
1727 8087c3c5 2020-01-15 tracey id_str1)) == -1) {
1728 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1729 8087c3c5 2020-01-15 tracey goto done;
1732 8087c3c5 2020-01-15 tracey if ((asprintf(&commit_commit, "%s", id_str1)) == -1) {
1733 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1734 8087c3c5 2020-01-15 tracey goto done;
1737 8087c3c5 2020-01-15 tracey if ((asprintf(&commit_commit_disp, commit_commit_html,
1738 8087c3c5 2020-01-15 tracey commit_commit, refs_str_disp)) == -1) {
1739 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1740 8087c3c5 2020-01-15 tracey goto done;
1743 8087c3c5 2020-01-15 tracey if ((asprintf(&commit_age_long, "%s",
1744 8087c3c5 2020-01-15 tracey gw_get_time_str(committer_time, TM_LONG))) == -1) {
1745 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1746 8087c3c5 2020-01-15 tracey goto done;
1749 8087c3c5 2020-01-15 tracey if ((asprintf(&commit_age_long_disp, commit_age_html,
1750 8087c3c5 2020-01-15 tracey commit_age_long)) == -1) {
1751 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1752 8087c3c5 2020-01-15 tracey goto done;
1755 8087c3c5 2020-01-15 tracey if ((asprintf(&commit_age_diff, "%s",
1756 8087c3c5 2020-01-15 tracey gw_get_time_str(committer_time, TM_DIFF))) == -1) {
1757 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1758 8087c3c5 2020-01-15 tracey goto done;
1761 8087c3c5 2020-01-15 tracey if ((asprintf(&commit_age_diff_disp, commit_age_html,
1762 8087c3c5 2020-01-15 tracey commit_age_diff)) == -1) {
1763 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1764 8087c3c5 2020-01-15 tracey goto done;
1767 8087c3c5 2020-01-15 tracey if ((asprintf(&commit_author, "%s",
1768 8087c3c5 2020-01-15 tracey got_object_commit_get_author(commit))) == -1) {
1769 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1770 8087c3c5 2020-01-15 tracey goto done;
1773 8087c3c5 2020-01-15 tracey if ((asprintf(&commit_author_disp, commit_author_html,
1774 8087c3c5 2020-01-15 tracey gw_html_escape(commit_author))) == -1) {
1775 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1776 8087c3c5 2020-01-15 tracey goto done;
1779 8087c3c5 2020-01-15 tracey if ((asprintf(&commit_committer, "%s",
1780 8087c3c5 2020-01-15 tracey got_object_commit_get_committer(commit))) == -1) {
1781 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1782 8087c3c5 2020-01-15 tracey goto done;
1785 8087c3c5 2020-01-15 tracey if ((asprintf(&commit_committer_disp, commit_committer_html,
1786 8087c3c5 2020-01-15 tracey gw_html_escape(commit_committer))) == -1) {
1787 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1788 8087c3c5 2020-01-15 tracey goto done;
1791 8087c3c5 2020-01-15 tracey if (strcmp(commit_author, commit_committer) == 0) {
1792 8087c3c5 2020-01-15 tracey free(commit_committer_disp);
1793 8087c3c5 2020-01-15 tracey commit_committer_disp = strdup("");
1796 8087c3c5 2020-01-15 tracey error = got_object_commit_get_logmsg(&commit_log0, commit);
1797 8087c3c5 2020-01-15 tracey if (error)
1798 8087c3c5 2020-01-15 tracey goto done;
1800 87f9ebf5 2020-01-15 tracey commit_log = commit_log0;
1801 87f9ebf5 2020-01-15 tracey while (*commit_log == '\n')
1802 87f9ebf5 2020-01-15 tracey commit_log++;
1804 8087c3c5 2020-01-15 tracey switch(log_type) {
1805 8087c3c5 2020-01-15 tracey case (LOGBRIEF):
1806 8087c3c5 2020-01-15 tracey newline = strchr(commit_log, '\n');
1807 8087c3c5 2020-01-15 tracey if (newline)
1808 8087c3c5 2020-01-15 tracey *newline = '\0';
1810 8087c3c5 2020-01-15 tracey if ((asprintf(&logbriefs_navs_html, logbriefs_navs,
1811 8087c3c5 2020-01-15 tracey gw_trans->repo_name, id_str1, gw_trans->repo_name,
1812 8087c3c5 2020-01-15 tracey id_str1, gw_trans->repo_name, id_str1,
1813 8087c3c5 2020-01-15 tracey gw_trans->repo_name, id_str1)) == -1) {
1814 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1815 8087c3c5 2020-01-15 tracey goto done;
1818 8087c3c5 2020-01-15 tracey if ((asprintf(&commit_row, logbriefs_row,
1819 8087c3c5 2020-01-15 tracey commit_age_diff, commit_author, commit_log,
1820 8087c3c5 2020-01-15 tracey logbriefs_navs_html)) == -1) {
1821 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1822 8087c3c5 2020-01-15 tracey goto done;
1825 8087c3c5 2020-01-15 tracey free(logbriefs_navs_html);
1826 8087c3c5 2020-01-15 tracey logbriefs_navs_html = NULL;
1828 8087c3c5 2020-01-15 tracey case (LOGFULL):
1829 8087c3c5 2020-01-15 tracey if ((asprintf(&logbriefs_navs_html, logbriefs_navs,
1830 8087c3c5 2020-01-15 tracey gw_trans->repo_name, id_str1, gw_trans->repo_name,
1831 8087c3c5 2020-01-15 tracey id_str1, gw_trans->repo_name, id_str1,
1832 8087c3c5 2020-01-15 tracey gw_trans->repo_name, id_str1)) == -1) {
1833 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1834 8087c3c5 2020-01-15 tracey goto done;
1837 8087c3c5 2020-01-15 tracey if ((asprintf(&commit_row, logs_row, commit_commit_disp,
1838 8087c3c5 2020-01-15 tracey commit_author_disp, commit_committer_disp,
1839 8087c3c5 2020-01-15 tracey commit_age_long_disp, gw_html_escape(commit_log),
1840 8087c3c5 2020-01-15 tracey logbriefs_navs_html)) == -1) {
1841 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1842 8087c3c5 2020-01-15 tracey goto done;
1845 8087c3c5 2020-01-15 tracey free(logbriefs_navs_html);
1846 8087c3c5 2020-01-15 tracey logbriefs_navs_html = NULL;
1848 b772de24 2020-01-15 tracey case (LOGTAG):
1849 077f6c5a 2020-01-15 tracey log_tag_html = strdup("tag log here");
1851 077f6c5a 2020-01-15 tracey if ((asprintf(&commit_row, log_tag_row,
1852 077f6c5a 2020-01-15 tracey gw_html_escape(commit_log), log_tag_html)) == -1) {
1853 b772de24 2020-01-15 tracey error = got_error_from_errno("asprintf");
1854 b772de24 2020-01-15 tracey goto done;
1857 077f6c5a 2020-01-15 tracey free(log_tag_html);
1859 ec46ccd7 2020-01-15 tracey case (LOGBLAME):
1860 ec46ccd7 2020-01-15 tracey log_blame_html = gw_get_file_blame(gw_trans,
1861 ec46ccd7 2020-01-15 tracey start_commit);
1863 ec46ccd7 2020-01-15 tracey if ((asprintf(&commit_row, log_blame_row,
1864 ec46ccd7 2020-01-15 tracey gw_html_escape(commit_log), log_blame_html)) == -1) {
1865 ec46ccd7 2020-01-15 tracey error = got_error_from_errno("asprintf");
1866 ec46ccd7 2020-01-15 tracey goto done;
1869 ec46ccd7 2020-01-15 tracey free(log_blame_html);
1871 8087c3c5 2020-01-15 tracey case (LOGTREE):
1872 bcbc97d8 2020-01-15 tracey log_tree_html = gw_get_repo_tree(gw_trans,
1873 bcbc97d8 2020-01-15 tracey start_commit);
1875 87f9ebf5 2020-01-15 tracey if ((asprintf(&commit_row, log_tree_row,
1876 87f9ebf5 2020-01-15 tracey gw_html_escape(commit_log), log_tree_html)) == -1) {
1877 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1878 8087c3c5 2020-01-15 tracey goto done;
1881 8087c3c5 2020-01-15 tracey free(log_tree_html);
1883 8087c3c5 2020-01-15 tracey case (LOGCOMMIT):
1884 8087c3c5 2020-01-15 tracey if ((asprintf(&commit_log_disp, commit_log_html,
1885 8087c3c5 2020-01-15 tracey gw_html_escape(commit_log))) == -1) {
1886 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1887 8087c3c5 2020-01-15 tracey goto done;
1890 8087c3c5 2020-01-15 tracey log_commit_html = strdup("commit here");
1892 8087c3c5 2020-01-15 tracey if ((asprintf(&commit_row, log_commit_row,
1893 8087c3c5 2020-01-15 tracey commit_diff_disp, commit_commit_disp,
1894 87f9ebf5 2020-01-15 tracey commit_tree_disp, commit_author_disp,
1895 87f9ebf5 2020-01-15 tracey commit_committer_disp, commit_age_long_disp,
1896 87f9ebf5 2020-01-15 tracey commit_log_disp, log_commit_html)) == -1) {
1897 8087c3c5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1898 8087c3c5 2020-01-15 tracey goto done;
1900 8087c3c5 2020-01-15 tracey free(commit_log_disp);
1901 8087c3c5 2020-01-15 tracey free(log_commit_html);
1904 87f9ebf5 2020-01-15 tracey case (LOGDIFF):
1905 87f9ebf5 2020-01-15 tracey if ((asprintf(&commit_log_disp, commit_log_html,
1906 87f9ebf5 2020-01-15 tracey gw_html_escape(commit_log))) == -1) {
1907 87f9ebf5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1908 87f9ebf5 2020-01-15 tracey goto done;
1911 ec46ccd7 2020-01-15 tracey if (has_parent)
1912 ec46ccd7 2020-01-15 tracey log_diff_html = gw_get_repo_diff(gw_trans,
1913 ec46ccd7 2020-01-15 tracey commit_commit, commit_parent);
1915 ec46ccd7 2020-01-15 tracey log_diff_html = gw_get_repo_diff(gw_trans,
1916 ec46ccd7 2020-01-15 tracey commit_commit, NULL);
1918 87f9ebf5 2020-01-15 tracey if ((asprintf(&commit_row, log_diff_row,
1919 87f9ebf5 2020-01-15 tracey commit_diff_disp, commit_commit_disp,
1920 87f9ebf5 2020-01-15 tracey commit_tree_disp, commit_author_disp,
1921 87f9ebf5 2020-01-15 tracey commit_committer_disp, commit_age_long_disp,
1922 87f9ebf5 2020-01-15 tracey commit_log_disp, log_diff_html)) == -1) {
1923 87f9ebf5 2020-01-15 tracey error = got_error_from_errno("asprintf");
1924 87f9ebf5 2020-01-15 tracey goto done;
1926 87f9ebf5 2020-01-15 tracey free(commit_log_disp);
1927 87f9ebf5 2020-01-15 tracey free(log_diff_html);
1930 8087c3c5 2020-01-15 tracey default:
1931 8087c3c5 2020-01-15 tracey return NULL;
1934 6c6c85af 2020-01-15 tracey error = buf_puts(&newsize, diffbuf, commit_row);
1936 8087c3c5 2020-01-15 tracey free(commit_parent);
1937 8087c3c5 2020-01-15 tracey free(commit_diff_disp);
1938 87f9ebf5 2020-01-15 tracey free(commit_tree_disp);
1939 8087c3c5 2020-01-15 tracey free(commit_age_diff);
1940 8087c3c5 2020-01-15 tracey free(commit_age_diff_disp);
1941 8087c3c5 2020-01-15 tracey free(commit_age_long);
1942 8087c3c5 2020-01-15 tracey free(commit_age_long_disp);
1943 474370cb 2020-01-15 tracey free(commit_author);
1944 8087c3c5 2020-01-15 tracey free(commit_author_disp);
1945 8087c3c5 2020-01-15 tracey free(commit_committer);
1946 8087c3c5 2020-01-15 tracey free(commit_committer_disp);
1947 9d84e7dd 2020-01-15 tracey free(commit_log0);
1948 474370cb 2020-01-15 tracey free(commit_row);
1949 8087c3c5 2020-01-15 tracey free(refs_str_disp);
1950 8087c3c5 2020-01-15 tracey free(refs_str);
1951 8087c3c5 2020-01-15 tracey refs_str = NULL;
1952 8087c3c5 2020-01-15 tracey free(id_str1);
1953 8087c3c5 2020-01-15 tracey id_str1 = NULL;
1954 8087c3c5 2020-01-15 tracey free(id_str2);
1955 8087c3c5 2020-01-15 tracey id_str2 = NULL;
1957 474370cb 2020-01-15 tracey if (error || (limit && --limit == 0))
1961 8087c3c5 2020-01-15 tracey if (error)
1962 8087c3c5 2020-01-15 tracey goto done;
1964 6c6c85af 2020-01-15 tracey if (buf_len(diffbuf) > 0) {
1965 6c6c85af 2020-01-15 tracey error = buf_putc(diffbuf, '\0');
1966 6c6c85af 2020-01-15 tracey logs = strdup(buf_get(diffbuf));
1969 8087c3c5 2020-01-15 tracey buf_free(diffbuf);
1970 2e676fc5 2020-01-15 tracey free(in_repo_path);
1971 8087c3c5 2020-01-15 tracey if (commit != NULL)
1972 8087c3c5 2020-01-15 tracey got_object_commit_close(commit);
1973 8087c3c5 2020-01-15 tracey if (search_pattern)
1974 8087c3c5 2020-01-15 tracey regfree(®ex);
1975 8087c3c5 2020-01-15 tracey if (graph)
1976 8087c3c5 2020-01-15 tracey got_commit_graph_close(graph);
1977 474370cb 2020-01-15 tracey if (repo) {
1978 474370cb 2020-01-15 tracey error = got_repo_close(repo);
1979 ec46ccd7 2020-01-15 tracey if (error)
1980 474370cb 2020-01-15 tracey return NULL;
1982 8087c3c5 2020-01-15 tracey if (error) {
1983 8087c3c5 2020-01-15 tracey khttp_puts(gw_trans->gw_req, "Error: ");
1984 8087c3c5 2020-01-15 tracey khttp_puts(gw_trans->gw_req, error->msg);
1985 8087c3c5 2020-01-15 tracey return NULL;
1987 8087c3c5 2020-01-15 tracey return logs;
1990 2c251c14 2020-01-15 tracey static char *
1991 54415d85 2020-01-15 tracey gw_get_repo_tags(struct gw_trans *gw_trans, int limit, int tag_type)
1993 87f9ebf5 2020-01-15 tracey const struct got_error *error = NULL;
1994 87f9ebf5 2020-01-15 tracey struct got_repository *repo = NULL;
1995 87f9ebf5 2020-01-15 tracey struct got_reflist_head refs;
1996 87f9ebf5 2020-01-15 tracey struct got_reflist_entry *re;
1997 87f9ebf5 2020-01-15 tracey char *tags = NULL, *tag_row = NULL, *tags_navs_disp = NULL,
1998 87f9ebf5 2020-01-15 tracey *age = NULL;
1999 87f9ebf5 2020-01-15 tracey char *newline;
2000 87f9ebf5 2020-01-15 tracey struct buf *diffbuf = NULL;
2001 87f9ebf5 2020-01-15 tracey size_t newsize;
2003 6c6c85af 2020-01-15 tracey error = buf_alloc(&diffbuf, 0);
2004 ec46ccd7 2020-01-15 tracey if (error)
2005 6c6c85af 2020-01-15 tracey return NULL;
2006 6c6c85af 2020-01-15 tracey SIMPLEQ_INIT(&refs);
2008 87f9ebf5 2020-01-15 tracey error = got_repo_open(&repo, gw_trans->repo_path, NULL);
2009 ec46ccd7 2020-01-15 tracey if (error)
2010 87f9ebf5 2020-01-15 tracey goto done;
2012 3468a5fa 2020-01-15 tracey error = got_ref_list(&refs, repo, "refs/tags", got_repo_cmp_tags, repo);
2013 87f9ebf5 2020-01-15 tracey if (error)
2014 87f9ebf5 2020-01-15 tracey goto done;
2016 87f9ebf5 2020-01-15 tracey SIMPLEQ_FOREACH(re, &refs, entry) {
2017 87f9ebf5 2020-01-15 tracey const char *refname;
2018 87f9ebf5 2020-01-15 tracey char *refstr, *tag_log0, *tag_log, *id_str;
2019 87f9ebf5 2020-01-15 tracey time_t tagger_time;
2020 87f9ebf5 2020-01-15 tracey struct got_object_id *id;
2021 87f9ebf5 2020-01-15 tracey struct got_tag_object *tag;
2023 87f9ebf5 2020-01-15 tracey refname = got_ref_get_name(re->ref);
2024 87f9ebf5 2020-01-15 tracey if (strncmp(refname, "refs/tags/", 10) != 0)
2025 87f9ebf5 2020-01-15 tracey continue;
2026 87f9ebf5 2020-01-15 tracey refname += 10;
2027 87f9ebf5 2020-01-15 tracey refstr = got_ref_to_str(re->ref);
2028 87f9ebf5 2020-01-15 tracey if (refstr == NULL) {
2029 87f9ebf5 2020-01-15 tracey error = got_error_from_errno("got_ref_to_str");
2030 87f9ebf5 2020-01-15 tracey goto done;
2033 87f9ebf5 2020-01-15 tracey error = got_ref_resolve(&id, repo, re->ref);
2034 87f9ebf5 2020-01-15 tracey if (error)
2035 87f9ebf5 2020-01-15 tracey goto done;
2036 87f9ebf5 2020-01-15 tracey error = got_object_open_as_tag(&tag, repo, id);
2037 87f9ebf5 2020-01-15 tracey free(id);
2038 87f9ebf5 2020-01-15 tracey if (error)
2039 87f9ebf5 2020-01-15 tracey goto done;
2041 87f9ebf5 2020-01-15 tracey tagger_time = got_object_tag_get_tagger_time(tag);
2043 87f9ebf5 2020-01-15 tracey error = got_object_id_str(&id_str,
2044 87f9ebf5 2020-01-15 tracey got_object_tag_get_object_id(tag));
2045 87f9ebf5 2020-01-15 tracey if (error)
2046 87f9ebf5 2020-01-15 tracey goto done;
2048 87f9ebf5 2020-01-15 tracey tag_log0 = strdup(got_object_tag_get_message(tag));
2050 87f9ebf5 2020-01-15 tracey if (tag_log0 == NULL) {
2051 87f9ebf5 2020-01-15 tracey error = got_error_from_errno("strdup");
2052 87f9ebf5 2020-01-15 tracey goto done;
2055 87f9ebf5 2020-01-15 tracey tag_log = tag_log0;
2056 87f9ebf5 2020-01-15 tracey while (*tag_log == '\n')
2057 87f9ebf5 2020-01-15 tracey tag_log++;
2059 87f9ebf5 2020-01-15 tracey switch (tag_type) {
2060 87f9ebf5 2020-01-15 tracey case TAGBRIEF:
2061 87f9ebf5 2020-01-15 tracey newline = strchr(tag_log, '\n');
2062 87f9ebf5 2020-01-15 tracey if (newline)
2063 87f9ebf5 2020-01-15 tracey *newline = '\0';
2065 87f9ebf5 2020-01-15 tracey if ((asprintf(&age, "%s", gw_get_time_str(tagger_time,
2066 87f9ebf5 2020-01-15 tracey TM_DIFF))) == -1) {
2067 87f9ebf5 2020-01-15 tracey error = got_error_from_errno("asprintf");
2068 87f9ebf5 2020-01-15 tracey goto done;
2071 87f9ebf5 2020-01-15 tracey if ((asprintf(&tags_navs_disp, tags_navs,
2072 87f9ebf5 2020-01-15 tracey gw_trans->repo_name, id_str, gw_trans->repo_name,
2073 87f9ebf5 2020-01-15 tracey id_str, gw_trans->repo_name, id_str,
2074 87f9ebf5 2020-01-15 tracey gw_trans->repo_name, id_str)) == -1) {
2075 87f9ebf5 2020-01-15 tracey error = got_error_from_errno("asprintf");
2076 87f9ebf5 2020-01-15 tracey goto done;
2079 87f9ebf5 2020-01-15 tracey if ((asprintf(&tag_row, tags_row, age, refname, tag_log,
2080 87f9ebf5 2020-01-15 tracey tags_navs_disp)) == -1) {
2081 87f9ebf5 2020-01-15 tracey error = got_error_from_errno("asprintf");
2082 87f9ebf5 2020-01-15 tracey goto done;
2085 87f9ebf5 2020-01-15 tracey free(tags_navs_disp);
2087 87f9ebf5 2020-01-15 tracey case TAGFULL:
2089 87f9ebf5 2020-01-15 tracey default:
2093 6c6c85af 2020-01-15 tracey got_object_tag_close(tag);
2095 6c6c85af 2020-01-15 tracey error = buf_puts(&newsize, diffbuf, tag_row);
2097 6c6c85af 2020-01-15 tracey free(id_str);
2098 6c6c85af 2020-01-15 tracey free(refstr);
2099 6c6c85af 2020-01-15 tracey free(age);
2100 87f9ebf5 2020-01-15 tracey free(tag_log0);
2101 87f9ebf5 2020-01-15 tracey free(tag_row);
2103 87f9ebf5 2020-01-15 tracey if (error || (limit && --limit == 0))
2107 6c6c85af 2020-01-15 tracey if (buf_len(diffbuf) > 0) {
2108 6c6c85af 2020-01-15 tracey error = buf_putc(diffbuf, '\0');
2109 6c6c85af 2020-01-15 tracey tags = strdup(buf_get(diffbuf));
2112 87f9ebf5 2020-01-15 tracey buf_free(diffbuf);
2113 87f9ebf5 2020-01-15 tracey got_ref_list_free(&refs);
2114 87f9ebf5 2020-01-15 tracey if (repo)
2115 87f9ebf5 2020-01-15 tracey got_repo_close(repo);
2116 87f9ebf5 2020-01-15 tracey if (error)
2117 87f9ebf5 2020-01-15 tracey return NULL;
2119 87f9ebf5 2020-01-15 tracey return tags;
2122 ec46ccd7 2020-01-15 tracey struct blame_line {
2123 ec46ccd7 2020-01-15 tracey int annotated;
2124 ec46ccd7 2020-01-15 tracey char *id_str;
2125 ec46ccd7 2020-01-15 tracey char *committer;
2126 ec46ccd7 2020-01-15 tracey char datebuf[11]; /* YYYY-MM-DD + NUL */
2129 147269d5 2020-01-15 tracey struct gw_blame_cb_args {
2130 ec46ccd7 2020-01-15 tracey struct blame_line *lines;
2131 ec46ccd7 2020-01-15 tracey int nlines;
2132 ec46ccd7 2020-01-15 tracey int nlines_prec;
2133 ec46ccd7 2020-01-15 tracey int lineno_cur;
2134 ec46ccd7 2020-01-15 tracey off_t *line_offsets;
2135 ec46ccd7 2020-01-15 tracey FILE *f;
2136 ec46ccd7 2020-01-15 tracey struct got_repository *repo;
2137 54415d85 2020-01-15 tracey struct gw_trans *gw_trans;
2138 2e676fc5 2020-01-15 tracey struct buf *blamebuf;
2141 ec46ccd7 2020-01-15 tracey static const struct got_error *
2142 147269d5 2020-01-15 tracey gw_blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
2144 ec46ccd7 2020-01-15 tracey const struct got_error *err = NULL;
2145 147269d5 2020-01-15 tracey struct gw_blame_cb_args *a = arg;
2146 ec46ccd7 2020-01-15 tracey struct blame_line *bline;
2147 ec46ccd7 2020-01-15 tracey char *line = NULL;
2148 2e676fc5 2020-01-15 tracey size_t linesize = 0, newsize;
2149 ec46ccd7 2020-01-15 tracey struct got_commit_object *commit = NULL;
2150 ec46ccd7 2020-01-15 tracey off_t offset;
2151 ec46ccd7 2020-01-15 tracey struct tm tm;
2152 ec46ccd7 2020-01-15 tracey time_t committer_time;
2154 ec46ccd7 2020-01-15 tracey if (nlines != a->nlines ||
2155 ec46ccd7 2020-01-15 tracey (lineno != -1 && lineno < 1) || lineno > a->nlines)
2156 ec46ccd7 2020-01-15 tracey return got_error(GOT_ERR_RANGE);
2158 ec46ccd7 2020-01-15 tracey if (lineno == -1)
2159 ec46ccd7 2020-01-15 tracey return NULL; /* no change in this commit */
2161 ec46ccd7 2020-01-15 tracey /* Annotate this line. */
2162 ec46ccd7 2020-01-15 tracey bline = &a->lines[lineno - 1];
2163 ec46ccd7 2020-01-15 tracey if (bline->annotated)
2164 ec46ccd7 2020-01-15 tracey return NULL;
2165 ec46ccd7 2020-01-15 tracey err = got_object_id_str(&bline->id_str, id);
2166 ec46ccd7 2020-01-15 tracey if (err)
2167 ec46ccd7 2020-01-15 tracey return err;
2169 ec46ccd7 2020-01-15 tracey err = got_object_open_as_commit(&commit, a->repo, id);
2170 ec46ccd7 2020-01-15 tracey if (err)
2171 ec46ccd7 2020-01-15 tracey goto done;
2173 ec46ccd7 2020-01-15 tracey bline->committer = strdup(got_object_commit_get_committer(commit));
2174 ec46ccd7 2020-01-15 tracey if (bline->committer == NULL) {
2175 ec46ccd7 2020-01-15 tracey err = got_error_from_errno("strdup");
2176 ec46ccd7 2020-01-15 tracey goto done;
2179 ec46ccd7 2020-01-15 tracey committer_time = got_object_commit_get_committer_time(commit);
2180 ec46ccd7 2020-01-15 tracey if (localtime_r(&committer_time, &tm) == NULL)
2181 ec46ccd7 2020-01-15 tracey return got_error_from_errno("localtime_r");
2182 ec46ccd7 2020-01-15 tracey if (strftime(bline->datebuf, sizeof(bline->datebuf), "%G-%m-%d",
2183 ec46ccd7 2020-01-15 tracey &tm) >= sizeof(bline->datebuf)) {
2184 ec46ccd7 2020-01-15 tracey err = got_error(GOT_ERR_NO_SPACE);
2185 ec46ccd7 2020-01-15 tracey goto done;
2187 ec46ccd7 2020-01-15 tracey bline->annotated = 1;
2189 ec46ccd7 2020-01-15 tracey /* Print lines annotated so far. */
2190 ec46ccd7 2020-01-15 tracey bline = &a->lines[a->lineno_cur - 1];
2191 ec46ccd7 2020-01-15 tracey if (!bline->annotated)
2192 ec46ccd7 2020-01-15 tracey goto done;
2194 ec46ccd7 2020-01-15 tracey offset = a->line_offsets[a->lineno_cur - 1];
2195 ec46ccd7 2020-01-15 tracey if (fseeko(a->f, offset, SEEK_SET) == -1) {
2196 ec46ccd7 2020-01-15 tracey err = got_error_from_errno("fseeko");
2197 ec46ccd7 2020-01-15 tracey goto done;
2200 ec46ccd7 2020-01-15 tracey while (bline->annotated) {
2201 0311ce2d 2020-01-15 tracey char *smallerthan, *at, *nl, *committer, *blame_row = NULL,
2202 0311ce2d 2020-01-15 tracey *line_escape = NULL;
2203 ec46ccd7 2020-01-15 tracey size_t len;
2205 ec46ccd7 2020-01-15 tracey if (getline(&line, &linesize, a->f) == -1) {
2206 ec46ccd7 2020-01-15 tracey if (ferror(a->f))
2207 ec46ccd7 2020-01-15 tracey err = got_error_from_errno("getline");
2211 ec46ccd7 2020-01-15 tracey committer = bline->committer;
2212 ec46ccd7 2020-01-15 tracey smallerthan = strchr(committer, '<');
2213 ec46ccd7 2020-01-15 tracey if (smallerthan && smallerthan[1] != '\0')
2214 ec46ccd7 2020-01-15 tracey committer = smallerthan + 1;
2215 ec46ccd7 2020-01-15 tracey at = strchr(committer, '@');
2217 ec46ccd7 2020-01-15 tracey *at = '\0';
2218 ec46ccd7 2020-01-15 tracey len = strlen(committer);
2219 ec46ccd7 2020-01-15 tracey if (len >= 9)
2220 ec46ccd7 2020-01-15 tracey committer[8] = '\0';
2222 ec46ccd7 2020-01-15 tracey nl = strchr(line, '\n');
2224 ec46ccd7 2020-01-15 tracey *nl = '\0';
2226 0311ce2d 2020-01-15 tracey if (strcmp(line, "") != 0)
2227 0311ce2d 2020-01-15 tracey line_escape = strdup(gw_html_escape(line));
2229 0311ce2d 2020-01-15 tracey line_escape = strdup("");
2231 2e676fc5 2020-01-15 tracey asprintf(&blame_row, log_blame_line, a->nlines_prec,
2232 2e676fc5 2020-01-15 tracey a->lineno_cur, bline->id_str, bline->datebuf, committer,
2233 0311ce2d 2020-01-15 tracey line_escape);
2234 ec46ccd7 2020-01-15 tracey a->lineno_cur++;
2235 2e676fc5 2020-01-15 tracey err = buf_puts(&newsize, a->blamebuf, blame_row);
2236 2e676fc5 2020-01-15 tracey if (err)
2237 2e676fc5 2020-01-15 tracey return err;
2239 ec46ccd7 2020-01-15 tracey bline = &a->lines[a->lineno_cur - 1];
2240 0311ce2d 2020-01-15 tracey free(line_escape);
2241 2e676fc5 2020-01-15 tracey free(blame_row);
2244 ec46ccd7 2020-01-15 tracey if (commit)
2245 ec46ccd7 2020-01-15 tracey got_object_commit_close(commit);
2246 ec46ccd7 2020-01-15 tracey free(line);
2247 ec46ccd7 2020-01-15 tracey return err;
2250 bcbc97d8 2020-01-15 tracey static char*
2251 54415d85 2020-01-15 tracey gw_get_file_blame(struct gw_trans *gw_trans, char *commit_str)
2253 bcbc97d8 2020-01-15 tracey const struct got_error *error = NULL;
2254 bcbc97d8 2020-01-15 tracey struct got_repository *repo = NULL;
2255 ec46ccd7 2020-01-15 tracey struct got_object_id *obj_id = NULL;
2256 ec46ccd7 2020-01-15 tracey struct got_object_id *commit_id = NULL;
2257 ec46ccd7 2020-01-15 tracey struct got_blob_object *blob = NULL;
2258 2e676fc5 2020-01-15 tracey char *blame_html = NULL, *path = NULL, *in_repo_path = NULL,
2259 119bf4ed 2020-01-15 tracey *folder = NULL;
2260 147269d5 2020-01-15 tracey struct gw_blame_cb_args bca;
2261 119bf4ed 2020-01-15 tracey int i, obj_type;
2262 ec46ccd7 2020-01-15 tracey size_t filesize;
2264 ec46ccd7 2020-01-15 tracey error = got_repo_open(&repo, gw_trans->repo_path, NULL);
2265 ec46ccd7 2020-01-15 tracey if (error)
2266 ec46ccd7 2020-01-15 tracey goto done;
2268 2e676fc5 2020-01-15 tracey if (gw_trans->repo_folder != NULL) {
2269 2e676fc5 2020-01-15 tracey if ((asprintf(&folder, "%s/", gw_trans->repo_folder)) == -1) {
2270 2e676fc5 2020-01-15 tracey error = got_error_from_errno("asprintf");
2271 2e676fc5 2020-01-15 tracey goto done;
2274 2e676fc5 2020-01-15 tracey folder = strdup("");
2276 2e676fc5 2020-01-15 tracey if ((asprintf(&path, "%s%s", folder, gw_trans->repo_file)) == -1) {
2277 2e676fc5 2020-01-15 tracey error = got_error_from_errno("asprintf");
2278 2e676fc5 2020-01-15 tracey goto done;
2280 2e676fc5 2020-01-15 tracey free(folder);
2282 2e676fc5 2020-01-15 tracey error = got_repo_map_path(&in_repo_path, repo, path, 1);
2283 ec46ccd7 2020-01-15 tracey if (error)
2284 ec46ccd7 2020-01-15 tracey goto done;
2286 147269d5 2020-01-15 tracey error = got_repo_match_object_id(&commit_id, NULL, commit_str,
2287 147269d5 2020-01-15 tracey GOT_OBJ_TYPE_COMMIT, 1, repo);
2288 ec46ccd7 2020-01-15 tracey if (error)
2289 ec46ccd7 2020-01-15 tracey goto done;
2291 ec46ccd7 2020-01-15 tracey error = got_object_id_by_path(&obj_id, repo, commit_id, in_repo_path);
2292 ec46ccd7 2020-01-15 tracey if (error)
2293 ec46ccd7 2020-01-15 tracey goto done;
2295 ec46ccd7 2020-01-15 tracey if (obj_id == NULL) {
2296 ec46ccd7 2020-01-15 tracey error = got_error(GOT_ERR_NO_OBJ);
2297 ec46ccd7 2020-01-15 tracey goto done;
2300 ec46ccd7 2020-01-15 tracey error = got_object_get_type(&obj_type, repo, obj_id);
2301 ec46ccd7 2020-01-15 tracey if (error)
2302 ec46ccd7 2020-01-15 tracey goto done;
2304 ec46ccd7 2020-01-15 tracey if (obj_type != GOT_OBJ_TYPE_BLOB) {
2305 ec46ccd7 2020-01-15 tracey error = got_error(GOT_ERR_OBJ_TYPE);
2306 ec46ccd7 2020-01-15 tracey goto done;
2309 ec46ccd7 2020-01-15 tracey error = got_object_open_as_blob(&blob, repo, obj_id, 8192);
2310 ec46ccd7 2020-01-15 tracey if (error)
2311 ec46ccd7 2020-01-15 tracey goto done;
2313 2e676fc5 2020-01-15 tracey error = buf_alloc(&bca.blamebuf, 0);
2314 2e676fc5 2020-01-15 tracey if (error)
2315 2e676fc5 2020-01-15 tracey goto done;
2317 ec46ccd7 2020-01-15 tracey bca.f = got_opentemp();
2318 ec46ccd7 2020-01-15 tracey if (bca.f == NULL) {
2319 ec46ccd7 2020-01-15 tracey error = got_error_from_errno("got_opentemp");
2320 ec46ccd7 2020-01-15 tracey goto done;
2322 ec46ccd7 2020-01-15 tracey error = got_object_blob_dump_to_file(&filesize, &bca.nlines,
2323 ec46ccd7 2020-01-15 tracey &bca.line_offsets, bca.f, blob);
2324 ec46ccd7 2020-01-15 tracey if (error || bca.nlines == 0)
2325 ec46ccd7 2020-01-15 tracey goto done;
2327 ec46ccd7 2020-01-15 tracey /* Don't include \n at EOF in the blame line count. */
2328 ec46ccd7 2020-01-15 tracey if (bca.line_offsets[bca.nlines - 1] == filesize)
2329 ec46ccd7 2020-01-15 tracey bca.nlines--;
2331 ec46ccd7 2020-01-15 tracey bca.lines = calloc(bca.nlines, sizeof(*bca.lines));
2332 ec46ccd7 2020-01-15 tracey if (bca.lines == NULL) {
2333 ec46ccd7 2020-01-15 tracey error = got_error_from_errno("calloc");
2334 ec46ccd7 2020-01-15 tracey goto done;
2336 ec46ccd7 2020-01-15 tracey bca.lineno_cur = 1;
2337 ec46ccd7 2020-01-15 tracey bca.nlines_prec = 0;
2338 ec46ccd7 2020-01-15 tracey i = bca.nlines;
2339 ec46ccd7 2020-01-15 tracey while (i > 0) {
2340 ec46ccd7 2020-01-15 tracey i /= 10;
2341 ec46ccd7 2020-01-15 tracey bca.nlines_prec++;
2343 ec46ccd7 2020-01-15 tracey bca.repo = repo;
2344 2e676fc5 2020-01-15 tracey bca.gw_trans = gw_trans;
2346 147269d5 2020-01-15 tracey error = got_blame(in_repo_path, commit_id, repo, gw_blame_cb, &bca,
2347 147269d5 2020-01-15 tracey NULL, NULL);
2348 2e676fc5 2020-01-15 tracey if (buf_len(bca.blamebuf) > 0) {
2349 2e676fc5 2020-01-15 tracey error = buf_putc(bca.blamebuf, '\0');
2350 2e676fc5 2020-01-15 tracey blame_html = strdup(buf_get(bca.blamebuf));
2353 2e676fc5 2020-01-15 tracey free(bca.blamebuf);
2354 2e676fc5 2020-01-15 tracey free(in_repo_path);
2355 2e676fc5 2020-01-15 tracey free(commit_id);
2356 2e676fc5 2020-01-15 tracey free(obj_id);
2357 2e676fc5 2020-01-15 tracey free(path);
2359 2e676fc5 2020-01-15 tracey if (blob)
2360 2e676fc5 2020-01-15 tracey error = got_object_blob_close(blob);
2361 2e676fc5 2020-01-15 tracey if (repo)
2362 2e676fc5 2020-01-15 tracey error = got_repo_close(repo);
2363 ec46ccd7 2020-01-15 tracey if (error)
2364 ec46ccd7 2020-01-15 tracey return NULL;
2365 2e676fc5 2020-01-15 tracey if (bca.lines) {
2366 2e676fc5 2020-01-15 tracey for (i = 0; i < bca.nlines; i++) {
2367 2e676fc5 2020-01-15 tracey struct blame_line *bline = &bca.lines[i];
2368 2e676fc5 2020-01-15 tracey free(bline->id_str);
2369 2e676fc5 2020-01-15 tracey free(bline->committer);
2371 2e676fc5 2020-01-15 tracey free(bca.lines);
2373 2e676fc5 2020-01-15 tracey free(bca.line_offsets);
2374 2e676fc5 2020-01-15 tracey if (bca.f && fclose(bca.f) == EOF && error == NULL)
2375 2e676fc5 2020-01-15 tracey error = got_error_from_errno("fclose");
2376 2e676fc5 2020-01-15 tracey if (error)
2377 2e676fc5 2020-01-15 tracey return NULL;
2379 ec46ccd7 2020-01-15 tracey return blame_html;
2382 ec46ccd7 2020-01-15 tracey static char*
2383 54415d85 2020-01-15 tracey gw_get_repo_tree(struct gw_trans *gw_trans, char *commit_str)
2385 ec46ccd7 2020-01-15 tracey const struct got_error *error = NULL;
2386 ec46ccd7 2020-01-15 tracey struct got_repository *repo = NULL;
2387 bcbc97d8 2020-01-15 tracey struct got_object_id *tree_id = NULL, *commit_id = NULL;
2388 bcbc97d8 2020-01-15 tracey struct got_tree_object *tree = NULL;
2389 bcbc97d8 2020-01-15 tracey struct buf *diffbuf = NULL;
2390 bcbc97d8 2020-01-15 tracey size_t newsize;
2391 bcbc97d8 2020-01-15 tracey char *tree_html = NULL, *path = NULL, *in_repo_path = NULL,
2392 bcbc97d8 2020-01-15 tracey *tree_row = NULL, *id_str;
2393 bcbc97d8 2020-01-15 tracey int nentries, i;
2395 bcbc97d8 2020-01-15 tracey error = buf_alloc(&diffbuf, 0);
2396 ec46ccd7 2020-01-15 tracey if (error)
2397 bcbc97d8 2020-01-15 tracey return NULL;
2399 bcbc97d8 2020-01-15 tracey error = got_repo_open(&repo, gw_trans->repo_path, NULL);
2400 ec46ccd7 2020-01-15 tracey if (error)
2401 bcbc97d8 2020-01-15 tracey goto done;
2403 bcbc97d8 2020-01-15 tracey error = got_repo_map_path(&in_repo_path, repo, gw_trans->repo_path, 1);
2404 ec46ccd7 2020-01-15 tracey if (error)
2405 bcbc97d8 2020-01-15 tracey goto done;
2407 ec46ccd7 2020-01-15 tracey if (gw_trans->repo_folder != NULL)
2408 ec46ccd7 2020-01-15 tracey path = strdup(gw_trans->repo_folder);
2409 ec46ccd7 2020-01-15 tracey else if (in_repo_path) {
2410 bcbc97d8 2020-01-15 tracey free(path);
2411 bcbc97d8 2020-01-15 tracey path = in_repo_path;
2414 ec46ccd7 2020-01-15 tracey if (commit_str == NULL) {
2415 ec46ccd7 2020-01-15 tracey struct got_reference *head_ref;
2416 ec46ccd7 2020-01-15 tracey error = got_ref_open(&head_ref, repo, gw_trans->headref, 0);
2417 ec46ccd7 2020-01-15 tracey if (error)
2418 ec46ccd7 2020-01-15 tracey goto done;
2420 ec46ccd7 2020-01-15 tracey error = got_ref_resolve(&commit_id, repo, head_ref);
2421 ec46ccd7 2020-01-15 tracey got_ref_close(head_ref);
2424 147269d5 2020-01-15 tracey error = got_repo_match_object_id(&commit_id, NULL, commit_str,
2425 147269d5 2020-01-15 tracey GOT_OBJ_TYPE_COMMIT, 1, repo);
2426 bcbc97d8 2020-01-15 tracey if (error)
2427 bcbc97d8 2020-01-15 tracey goto done;
2429 ec46ccd7 2020-01-15 tracey error = got_object_id_by_path(&tree_id, repo, commit_id, path);
2430 bcbc97d8 2020-01-15 tracey if (error)
2431 bcbc97d8 2020-01-15 tracey goto done;
2433 bcbc97d8 2020-01-15 tracey error = got_object_open_as_tree(&tree, repo, tree_id);
2434 bcbc97d8 2020-01-15 tracey if (error)
2435 bcbc97d8 2020-01-15 tracey goto done;
2437 bcbc97d8 2020-01-15 tracey nentries = got_object_tree_get_nentries(tree);
2439 bcbc97d8 2020-01-15 tracey for (i = 0; i < nentries; i++) {
2440 bcbc97d8 2020-01-15 tracey struct got_tree_entry *te;
2441 ec46ccd7 2020-01-15 tracey const char *modestr = "";
2442 ec46ccd7 2020-01-15 tracey char *id = NULL, *url_html = NULL;
2444 bcbc97d8 2020-01-15 tracey te = got_object_tree_get_entry(tree, i);
2446 bcbc97d8 2020-01-15 tracey error = got_object_id_str(&id_str, got_tree_entry_get_id(te));
2447 bcbc97d8 2020-01-15 tracey if (error)
2448 bcbc97d8 2020-01-15 tracey goto done;
2450 ec46ccd7 2020-01-15 tracey if ((asprintf(&id, "%s", id_str)) == -1) {
2451 bcbc97d8 2020-01-15 tracey error = got_error_from_errno("asprintf");
2452 bcbc97d8 2020-01-15 tracey free(id_str);
2453 bcbc97d8 2020-01-15 tracey goto done;
2456 bcbc97d8 2020-01-15 tracey mode_t mode = got_tree_entry_get_mode(te);
2458 bcbc97d8 2020-01-15 tracey if (got_object_tree_entry_is_submodule(te))
2459 bcbc97d8 2020-01-15 tracey modestr = "$";
2460 bcbc97d8 2020-01-15 tracey else if (S_ISLNK(mode))
2461 bcbc97d8 2020-01-15 tracey modestr = "@";
2462 bcbc97d8 2020-01-15 tracey else if (S_ISDIR(mode))
2463 bcbc97d8 2020-01-15 tracey modestr = "/";
2464 bcbc97d8 2020-01-15 tracey else if (mode & S_IXUSR)
2465 bcbc97d8 2020-01-15 tracey modestr = "*";
2467 ec46ccd7 2020-01-15 tracey char *build_folder = NULL;
2468 ec46ccd7 2020-01-15 tracey if (S_ISDIR(got_tree_entry_get_mode(te))) {
2469 ec46ccd7 2020-01-15 tracey if (gw_trans->repo_folder != NULL) {
2470 ec46ccd7 2020-01-15 tracey if ((asprintf(&build_folder, "%s/%s",
2471 ec46ccd7 2020-01-15 tracey gw_trans->repo_folder,
2472 ec46ccd7 2020-01-15 tracey got_tree_entry_get_name(te))) == -1) {
2474 ec46ccd7 2020-01-15 tracey got_error_from_errno("asprintf");
2475 ec46ccd7 2020-01-15 tracey goto done;
2477 ec46ccd7 2020-01-15 tracey } else {
2478 ec46ccd7 2020-01-15 tracey if (asprintf(&build_folder, "%s",
2479 ec46ccd7 2020-01-15 tracey got_tree_entry_get_name(te)) == -1)
2480 ec46ccd7 2020-01-15 tracey goto done;
2483 ec46ccd7 2020-01-15 tracey if ((asprintf(&url_html, folder_html,
2484 ec46ccd7 2020-01-15 tracey gw_trans->repo_name, gw_trans->action_name,
2485 ec46ccd7 2020-01-15 tracey gw_trans->commit, build_folder,
2486 ec46ccd7 2020-01-15 tracey got_tree_entry_get_name(te), modestr)) == -1) {
2487 ec46ccd7 2020-01-15 tracey error = got_error_from_errno("asprintf");
2488 ec46ccd7 2020-01-15 tracey goto done;
2490 ec46ccd7 2020-01-15 tracey } else {
2491 ec46ccd7 2020-01-15 tracey if (gw_trans->repo_folder != NULL) {
2492 ec46ccd7 2020-01-15 tracey if ((asprintf(&build_folder, "%s",
2493 ec46ccd7 2020-01-15 tracey gw_trans->repo_folder)) == -1) {
2495 ec46ccd7 2020-01-15 tracey got_error_from_errno("asprintf");
2496 ec46ccd7 2020-01-15 tracey goto done;
2499 ec46ccd7 2020-01-15 tracey build_folder = strdup("");
2501 ec46ccd7 2020-01-15 tracey if ((asprintf(&url_html, file_html, gw_trans->repo_name,
2502 ec46ccd7 2020-01-15 tracey "blame", gw_trans->commit,
2503 ec46ccd7 2020-01-15 tracey got_tree_entry_get_name(te), build_folder,
2504 ec46ccd7 2020-01-15 tracey got_tree_entry_get_name(te), modestr)) == -1) {
2505 ec46ccd7 2020-01-15 tracey error = got_error_from_errno("asprintf");
2506 ec46ccd7 2020-01-15 tracey goto done;
2509 ec46ccd7 2020-01-15 tracey free(build_folder);
2511 ec46ccd7 2020-01-15 tracey if (error)
2512 ec46ccd7 2020-01-15 tracey goto done;
2514 ec46ccd7 2020-01-15 tracey if ((asprintf(&tree_row, trees_row, "", url_html)) == -1) {
2515 bcbc97d8 2020-01-15 tracey error = got_error_from_errno("asprintf");
2516 bcbc97d8 2020-01-15 tracey goto done;
2518 bcbc97d8 2020-01-15 tracey error = buf_puts(&newsize, diffbuf, tree_row);
2519 ec46ccd7 2020-01-15 tracey if (error)
2520 ec46ccd7 2020-01-15 tracey goto done;
2522 bcbc97d8 2020-01-15 tracey free(id);
2523 bcbc97d8 2020-01-15 tracey free(id_str);
2524 ec46ccd7 2020-01-15 tracey free(url_html);
2525 ec46ccd7 2020-01-15 tracey free(tree_row);
2528 bcbc97d8 2020-01-15 tracey if (buf_len(diffbuf) > 0) {
2529 bcbc97d8 2020-01-15 tracey error = buf_putc(diffbuf, '\0');
2530 bcbc97d8 2020-01-15 tracey tree_html = strdup(buf_get(diffbuf));
2533 bcbc97d8 2020-01-15 tracey if (tree)
2534 bcbc97d8 2020-01-15 tracey got_object_tree_close(tree);
2535 2e676fc5 2020-01-15 tracey if (repo)
2536 2e676fc5 2020-01-15 tracey got_repo_close(repo);
2538 2e676fc5 2020-01-15 tracey free(in_repo_path);
2539 bcbc97d8 2020-01-15 tracey free(tree_id);
2540 bcbc97d8 2020-01-15 tracey free(diffbuf);
2541 bcbc97d8 2020-01-15 tracey if (error)
2542 bcbc97d8 2020-01-15 tracey return NULL;
2544 bcbc97d8 2020-01-15 tracey return tree_html;
2547 8d4d2453 2020-01-15 tracey static char *
2548 54415d85 2020-01-15 tracey gw_get_repo_heads(struct gw_trans *gw_trans)
2550 87f9ebf5 2020-01-15 tracey const struct got_error *error = NULL;
2551 87f9ebf5 2020-01-15 tracey struct got_repository *repo = NULL;
2552 87f9ebf5 2020-01-15 tracey struct got_reflist_head refs;
2553 87f9ebf5 2020-01-15 tracey struct got_reflist_entry *re;
2554 87f9ebf5 2020-01-15 tracey char *heads, *head_row = NULL, *head_navs_disp = NULL, *age = NULL;
2555 87f9ebf5 2020-01-15 tracey struct buf *diffbuf = NULL;
2556 87f9ebf5 2020-01-15 tracey size_t newsize;
2558 6c6c85af 2020-01-15 tracey error = buf_alloc(&diffbuf, 0);
2559 ec46ccd7 2020-01-15 tracey if (error)
2560 6c6c85af 2020-01-15 tracey return NULL;
2562 87f9ebf5 2020-01-15 tracey error = got_repo_open(&repo, gw_trans->repo_path, NULL);
2563 ec46ccd7 2020-01-15 tracey if (error)
2564 87f9ebf5 2020-01-15 tracey goto done;
2566 87f9ebf5 2020-01-15 tracey SIMPLEQ_INIT(&refs);
2567 87f9ebf5 2020-01-15 tracey error = got_ref_list(&refs, repo, "refs/heads", got_ref_cmp_by_name,
2569 87f9ebf5 2020-01-15 tracey if (error)
2570 87f9ebf5 2020-01-15 tracey goto done;
2572 87f9ebf5 2020-01-15 tracey SIMPLEQ_FOREACH(re, &refs, entry) {
2573 87f9ebf5 2020-01-15 tracey char *refname;
2575 87f9ebf5 2020-01-15 tracey refname = strdup(got_ref_get_name(re->ref));
2576 87f9ebf5 2020-01-15 tracey if (refname == NULL) {
2577 87f9ebf5 2020-01-15 tracey error = got_error_from_errno("got_ref_to_str");
2578 87f9ebf5 2020-01-15 tracey goto done;
2581 87f9ebf5 2020-01-15 tracey if (strncmp(refname, "refs/heads/", 11) != 0) {
2582 87f9ebf5 2020-01-15 tracey free(refname);
2583 87f9ebf5 2020-01-15 tracey continue;
2586 87f9ebf5 2020-01-15 tracey age = gw_get_repo_age(gw_trans, gw_trans->gw_dir->path, refname,
2587 87f9ebf5 2020-01-15 tracey TM_DIFF);
2589 87f9ebf5 2020-01-15 tracey if ((asprintf(&head_navs_disp, heads_navs, gw_trans->repo_name,
2590 87f9ebf5 2020-01-15 tracey refname, gw_trans->repo_name, refname,
2591 87f9ebf5 2020-01-15 tracey gw_trans->repo_name, refname, gw_trans->repo_name,
2592 87f9ebf5 2020-01-15 tracey refname)) == -1) {
2593 87f9ebf5 2020-01-15 tracey error = got_error_from_errno("asprintf");
2594 87f9ebf5 2020-01-15 tracey goto done;
2597 87f9ebf5 2020-01-15 tracey if (strncmp(refname, "refs/heads/", 11) == 0)
2598 87f9ebf5 2020-01-15 tracey refname += 11;
2600 87f9ebf5 2020-01-15 tracey if ((asprintf(&head_row, heads_row, age, refname,
2601 87f9ebf5 2020-01-15 tracey head_navs_disp)) == -1) {
2602 87f9ebf5 2020-01-15 tracey error = got_error_from_errno("asprintf");
2603 87f9ebf5 2020-01-15 tracey goto done;
2606 6c6c85af 2020-01-15 tracey error = buf_puts(&newsize, diffbuf, head_row);
2608 87f9ebf5 2020-01-15 tracey free(head_navs_disp);
2609 87f9ebf5 2020-01-15 tracey free(head_row);
2612 6c6c85af 2020-01-15 tracey if (buf_len(diffbuf) > 0) {
2613 6c6c85af 2020-01-15 tracey error = buf_putc(diffbuf, '\0');
2614 6c6c85af 2020-01-15 tracey heads = strdup(buf_get(diffbuf));
2617 87f9ebf5 2020-01-15 tracey buf_free(diffbuf);
2618 87f9ebf5 2020-01-15 tracey got_ref_list_free(&refs);
2619 87f9ebf5 2020-01-15 tracey if (repo)
2620 87f9ebf5 2020-01-15 tracey got_repo_close(repo);
2621 87f9ebf5 2020-01-15 tracey if (error)
2622 87f9ebf5 2020-01-15 tracey return NULL;
2624 87f9ebf5 2020-01-15 tracey return heads;
2627 8d4d2453 2020-01-15 tracey static char *
2628 54415d85 2020-01-15 tracey gw_get_got_link(struct gw_trans *gw_trans)
2630 2c251c14 2020-01-15 tracey char *link;
2632 2c251c14 2020-01-15 tracey if ((asprintf(&link, got_link, gw_trans->gw_conf->got_logo_url,
2633 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_logo)) == -1)
2634 2c251c14 2020-01-15 tracey return NULL;
2636 2c251c14 2020-01-15 tracey return link;
2639 2c251c14 2020-01-15 tracey static char *
2640 54415d85 2020-01-15 tracey gw_get_site_link(struct gw_trans *gw_trans)
2642 2c251c14 2020-01-15 tracey char *link, *repo = "", *action = "";
2644 2c251c14 2020-01-15 tracey if (gw_trans->repo_name != NULL)
2645 2c251c14 2020-01-15 tracey if ((asprintf(&repo, " / <a href='?path=%s&action=summary'>%s" \
2646 2c251c14 2020-01-15 tracey "</a>", gw_trans->repo_name, gw_trans->repo_name)) == -1)
2647 2c251c14 2020-01-15 tracey return NULL;
2649 2c251c14 2020-01-15 tracey if (gw_trans->action_name != NULL)
2650 2c251c14 2020-01-15 tracey if ((asprintf(&action, " / %s", gw_trans->action_name)) == -1)
2651 2c251c14 2020-01-15 tracey return NULL;
2653 2c251c14 2020-01-15 tracey if ((asprintf(&link, site_link, GOTWEB,
2654 2c251c14 2020-01-15 tracey gw_trans->gw_conf->got_site_link, repo, action)) == -1)
2655 2c251c14 2020-01-15 tracey return NULL;
2657 2c251c14 2020-01-15 tracey return link;
2660 2c251c14 2020-01-15 tracey static char *
2661 d0ea9c5b 2020-01-15 tracey gw_colordiff_line(char *buf)
2663 ec46ccd7 2020-01-15 tracey const struct got_error *error = NULL;
2664 ec46ccd7 2020-01-15 tracey char *colorized_line = NULL, *div_diff_line_div = NULL, *color = NULL;
2665 ec46ccd7 2020-01-15 tracey struct buf *diffbuf = NULL;
2666 ec46ccd7 2020-01-15 tracey size_t newsize;
2668 ec46ccd7 2020-01-15 tracey error = buf_alloc(&diffbuf, 0);
2669 ec46ccd7 2020-01-15 tracey if (error)
2670 ec46ccd7 2020-01-15 tracey return NULL;
2672 ec46ccd7 2020-01-15 tracey if (strncmp(buf, "-", 1) == 0)
2673 ec46ccd7 2020-01-15 tracey color = "diff_minus";
2674 ec46ccd7 2020-01-15 tracey if (strncmp(buf, "+", 1) == 0)
2675 ec46ccd7 2020-01-15 tracey color = "diff_plus";
2676 ec46ccd7 2020-01-15 tracey if (strncmp(buf, "@@", 2) == 0)
2677 ec46ccd7 2020-01-15 tracey color = "diff_chunk_header";
2678 ec46ccd7 2020-01-15 tracey if (strncmp(buf, "@@", 2) == 0)
2679 ec46ccd7 2020-01-15 tracey color = "diff_chunk_header";
2680 ec46ccd7 2020-01-15 tracey if (strncmp(buf, "commit +", 8) == 0)
2681 ec46ccd7 2020-01-15 tracey color = "diff_meta";
2682 ec46ccd7 2020-01-15 tracey if (strncmp(buf, "commit -", 8) == 0)
2683 ec46ccd7 2020-01-15 tracey color = "diff_meta";
2684 ec46ccd7 2020-01-15 tracey if (strncmp(buf, "blob +", 6) == 0)
2685 ec46ccd7 2020-01-15 tracey color = "diff_meta";
2686 ec46ccd7 2020-01-15 tracey if (strncmp(buf, "blob -", 6) == 0)
2687 ec46ccd7 2020-01-15 tracey color = "diff_meta";
2688 ec46ccd7 2020-01-15 tracey if (strncmp(buf, "file +", 6) == 0)
2689 ec46ccd7 2020-01-15 tracey color = "diff_meta";
2690 ec46ccd7 2020-01-15 tracey if (strncmp(buf, "file -", 6) == 0)
2691 ec46ccd7 2020-01-15 tracey color = "diff_meta";
2692 ec46ccd7 2020-01-15 tracey if (strncmp(buf, "from:", 5) == 0)
2693 ec46ccd7 2020-01-15 tracey color = "diff_author";
2694 ec46ccd7 2020-01-15 tracey if (strncmp(buf, "via:", 4) == 0)
2695 ec46ccd7 2020-01-15 tracey color = "diff_author";
2696 ec46ccd7 2020-01-15 tracey if (strncmp(buf, "date:", 5) == 0)
2697 ec46ccd7 2020-01-15 tracey color = "diff_date";
2699 ec46ccd7 2020-01-15 tracey if ((asprintf(&div_diff_line_div, div_diff_line, color)) == -1)
2700 ec46ccd7 2020-01-15 tracey return NULL;
2702 ec46ccd7 2020-01-15 tracey error = buf_puts(&newsize, diffbuf, div_diff_line_div);
2703 ec46ccd7 2020-01-15 tracey if (error)
2704 ec46ccd7 2020-01-15 tracey return NULL;
2706 ec46ccd7 2020-01-15 tracey error = buf_puts(&newsize, diffbuf, buf);
2707 ec46ccd7 2020-01-15 tracey if (error)
2708 ec46ccd7 2020-01-15 tracey return NULL;
2710 ec46ccd7 2020-01-15 tracey if (buf_len(diffbuf) > 0) {
2711 ec46ccd7 2020-01-15 tracey error = buf_putc(diffbuf, '\0');
2712 ec46ccd7 2020-01-15 tracey colorized_line = strdup(buf_get(diffbuf));
2715 ec46ccd7 2020-01-15 tracey free(diffbuf);
2716 ec46ccd7 2020-01-15 tracey free(div_diff_line_div);
2717 ec46ccd7 2020-01-15 tracey return colorized_line;
2720 ec46ccd7 2020-01-15 tracey static char *
2721 2c251c14 2020-01-15 tracey gw_html_escape(const char *html)
2723 2c251c14 2020-01-15 tracey char *escaped_str = NULL, *buf;
2724 2c251c14 2020-01-15 tracey char c[1];
2725 6c6c85af 2020-01-15 tracey size_t sz, i, buff_sz = 2048;
2727 6c6c85af 2020-01-15 tracey if ((buf = calloc(buff_sz, sizeof(char *))) == NULL)
2728 2c251c14 2020-01-15 tracey return NULL;
2730 2c251c14 2020-01-15 tracey if (html == NULL)
2731 2c251c14 2020-01-15 tracey return NULL;
2733 2c251c14 2020-01-15 tracey if ((sz = strlen(html)) == 0)
2734 2c251c14 2020-01-15 tracey return NULL;
2736 6c6c85af 2020-01-15 tracey /* only work with buff_sz */
2737 6c6c85af 2020-01-15 tracey if (buff_sz < sz)
2738 6c6c85af 2020-01-15 tracey sz = buff_sz;
2740 2c251c14 2020-01-15 tracey for (i = 0; i < sz; i++) {
2741 2c251c14 2020-01-15 tracey c[0] = html[i];
2742 2c251c14 2020-01-15 tracey switch (c[0]) {
2743 2c251c14 2020-01-15 tracey case ('>'):
2744 2c251c14 2020-01-15 tracey strcat(buf, ">");
2746 2c251c14 2020-01-15 tracey case ('&'):
2747 2c251c14 2020-01-15 tracey strcat(buf, "&");
2749 2c251c14 2020-01-15 tracey case ('<'):
2750 2c251c14 2020-01-15 tracey strcat(buf, "<");
2752 2c251c14 2020-01-15 tracey case ('"'):
2753 2c251c14 2020-01-15 tracey strcat(buf, """);
2755 2c251c14 2020-01-15 tracey case ('\''):
2756 2c251c14 2020-01-15 tracey strcat(buf, "'");
2758 2c251c14 2020-01-15 tracey case ('\n'):
2759 2c251c14 2020-01-15 tracey strcat(buf, "<br />");
2760 2c251c14 2020-01-15 tracey default:
2761 2c251c14 2020-01-15 tracey strcat(buf, &c[0]);
2765 2c251c14 2020-01-15 tracey asprintf(&escaped_str, "%s", buf);
2766 2c251c14 2020-01-15 tracey free(buf);
2767 2c251c14 2020-01-15 tracey return escaped_str;
2773 2c251c14 2020-01-15 tracey const struct got_error *error = NULL;
2774 54415d85 2020-01-15 tracey struct gw_trans *gw_trans;
2775 2c251c14 2020-01-15 tracey struct gw_dir *dir = NULL, *tdir;
2776 2c251c14 2020-01-15 tracey const char *page = "index";
2777 4ceb8155 2020-01-15 tracey int gw_malloc = 1;
2779 54415d85 2020-01-15 tracey if ((gw_trans = malloc(sizeof(struct gw_trans))) == NULL)
2780 2c251c14 2020-01-15 tracey errx(1, "malloc");
2782 2c251c14 2020-01-15 tracey if ((gw_trans->gw_req = malloc(sizeof(struct kreq))) == NULL)
2783 2c251c14 2020-01-15 tracey errx(1, "malloc");
2785 2c251c14 2020-01-15 tracey if ((gw_trans->gw_html_req = malloc(sizeof(struct khtmlreq))) == NULL)
2786 2c251c14 2020-01-15 tracey errx(1, "malloc");
2788 2c251c14 2020-01-15 tracey if ((gw_trans->gw_tmpl = malloc(sizeof(struct ktemplate))) == NULL)
2789 2c251c14 2020-01-15 tracey errx(1, "malloc");
2791 ec46ccd7 2020-01-15 tracey if (KCGI_OK != khttp_parse(gw_trans->gw_req, gw_keys, KEY__ZMAX,
2792 2c251c14 2020-01-15 tracey &page, 1, 0))
2793 2c251c14 2020-01-15 tracey errx(1, "khttp_parse");
2795 2c251c14 2020-01-15 tracey if ((gw_trans->gw_conf =
2796 2c251c14 2020-01-15 tracey malloc(sizeof(struct gotweb_conf))) == NULL) {
2797 4ceb8155 2020-01-15 tracey gw_malloc = 0;
2798 387a29ba 2020-01-15 tracey error = got_error_from_errno("malloc");
2799 2c251c14 2020-01-15 tracey goto err;
2802 ec46ccd7 2020-01-15 tracey if (pledge("stdio rpath wpath cpath proc exec sendfd unveil",
2803 ec46ccd7 2020-01-15 tracey NULL) == -1) {
2804 46b9c89b 2020-01-15 tracey error = got_error_from_errno("pledge");
2805 46b9c89b 2020-01-15 tracey goto err;
2808 2c251c14 2020-01-15 tracey TAILQ_INIT(&gw_trans->gw_dirs);
2810 2c251c14 2020-01-15 tracey gw_trans->page = 0;
2811 2c251c14 2020-01-15 tracey gw_trans->repos_total = 0;
2812 2c251c14 2020-01-15 tracey gw_trans->repo_path = NULL;
2813 2c251c14 2020-01-15 tracey gw_trans->commit = NULL;
2814 8087c3c5 2020-01-15 tracey gw_trans->headref = strdup(GOT_REF_HEAD);
2815 2c251c14 2020-01-15 tracey gw_trans->mime = KMIME_TEXT_HTML;
2816 54415d85 2020-01-15 tracey gw_trans->gw_tmpl->key = gw_templs;
2817 2c251c14 2020-01-15 tracey gw_trans->gw_tmpl->keysz = TEMPL__MAX;
2818 2c251c14 2020-01-15 tracey gw_trans->gw_tmpl->arg = gw_trans;
2819 2c251c14 2020-01-15 tracey gw_trans->gw_tmpl->cb = gw_template;
2820 2c251c14 2020-01-15 tracey error = parse_conf(GOTWEB_CONF, gw_trans->gw_conf);
2823 2c251c14 2020-01-15 tracey if (error) {
2824 2c251c14 2020-01-15 tracey gw_trans->mime = KMIME_TEXT_PLAIN;
2825 2c251c14 2020-01-15 tracey gw_trans->action = GW_ERR;
2826 2c251c14 2020-01-15 tracey gw_display_index(gw_trans, error);
2827 2c251c14 2020-01-15 tracey goto done;
2830 2c251c14 2020-01-15 tracey error = gw_parse_querystring(gw_trans);
2831 2c251c14 2020-01-15 tracey if (error)
2832 2c251c14 2020-01-15 tracey goto err;
2834 2c251c14 2020-01-15 tracey gw_display_index(gw_trans, error);
2837 2c251c14 2020-01-15 tracey if (gw_malloc) {
2838 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_repos_path);
2839 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_www_path);
2840 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_site_name);
2841 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_site_owner);
2842 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_site_link);
2843 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_logo);
2844 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf->got_logo_url);
2845 2c251c14 2020-01-15 tracey free(gw_trans->gw_conf);
2846 2c251c14 2020-01-15 tracey free(gw_trans->commit);
2847 2c251c14 2020-01-15 tracey free(gw_trans->repo_path);
2848 2c251c14 2020-01-15 tracey free(gw_trans->repo_name);
2849 2c251c14 2020-01-15 tracey free(gw_trans->repo_file);
2850 2c251c14 2020-01-15 tracey free(gw_trans->action_name);
2851 8087c3c5 2020-01-15 tracey free(gw_trans->headref);
2853 2c251c14 2020-01-15 tracey TAILQ_FOREACH_SAFE(dir, &gw_trans->gw_dirs, entry, tdir) {
2854 2c251c14 2020-01-15 tracey free(dir->name);
2855 2c251c14 2020-01-15 tracey free(dir->description);
2856 2c251c14 2020-01-15 tracey free(dir->age);
2857 2c251c14 2020-01-15 tracey free(dir->url);
2858 2c251c14 2020-01-15 tracey free(dir->path);
2859 2c251c14 2020-01-15 tracey free(dir);
2864 2c251c14 2020-01-15 tracey khttp_free(gw_trans->gw_req);
2865 2c251c14 2020-01-15 tracey return EXIT_SUCCESS;