commit 00a8878e94dced1dd4053bf9b61e8b8c16f59629 from: Tracey Emery via: Thomas Adam date: Fri Jul 01 21:13:24 2022 UTC move got_opentempfd out of blame_open ok stsp@ jrick@ commit - acb9e3ea2ed831226f75eb7606ecd06a0711b131 commit + 00a8878e94dced1dd4053bf9b61e8b8c16f59629 blob - 34ab6c7e364259d06257ce50a763bb09dfacd8cf blob + 83319ccfd87fbd08828db2f66adade1bd1d1e584 --- got/got.c +++ got/got.c @@ -5315,7 +5315,7 @@ cmd_blame(int argc, char *argv[]) struct got_blob_object *blob = NULL; char *commit_id_str = NULL; struct blame_cb_args bca; - int ch, obj_type, i, fd = -1; + int ch, obj_type, i, fd = -1, fd1 = -1; off_t filesize; int *pack_fds = NULL; @@ -5504,8 +5504,13 @@ cmd_blame(int argc, char *argv[]) } bca.repo = repo; + fd1 = got_opentempfd(); + if (fd1 == -1) { + error = got_error_from_errno("got_opentempfd"); + goto done; + } error = got_blame(link_target ? link_target : in_repo_path, commit_id, - repo, blame_cb, &bca, check_cancelled, NULL); + repo, blame_cb, &bca, check_cancelled, NULL, fd1); done: free(in_repo_path); free(link_target); @@ -5517,6 +5522,8 @@ done: got_object_commit_close(commit); if (fd != -1 && close(fd) == -1 && error == NULL) error = got_error_from_errno("close"); + if (fd1 != -1 && close(fd1) == -1 && error == NULL) + error = got_error_from_errno("close"); if (blob) got_object_blob_close(blob); if (worktree) blob - 613f534afc172336d81db615fa60e942b4f1734f blob + c9aa6f98c2355fecdde6e491c3d80916f5897fc9 --- gotweb/gotweb.c +++ gotweb/gotweb.c @@ -4063,7 +4063,7 @@ gw_output_file_blame(struct gw_trans *gw_trans, struct struct got_blob_object *blob = NULL; char *path = NULL, *in_repo_path = NULL; struct gw_blame_cb_args bca; - int i, obj_type, fd = -1; + int i, obj_type, fd = -1, fd1 = -1; off_t filesize; fd = got_opentempfd(); @@ -4146,8 +4146,14 @@ gw_output_file_blame(struct gw_trans *gw_trans, struct bca.repo = gw_trans->repo; bca.gw_trans = gw_trans; + fd1 = got_opentempfd(); + if (fd1 == -1) { + error = got_error_from_errno("got_opentempfd"); + goto done; + } + error = got_blame(in_repo_path, commit_id, gw_trans->repo, gw_blame_cb, - &bca, NULL, NULL); + &bca, NULL, NULL, fd1); done: free(in_repo_path); free(commit_id); @@ -4156,6 +4162,9 @@ done: if (fd != -1 && close(fd) == -1 && error == NULL) error = got_error_from_errno("close"); + if (fd1 != -1 && close(fd1) == -1 && error == NULL) + error = got_error_from_errno("close"); + if (blob) { free(bca.line_offsets); for (i = 0; i < bca.nlines; i++) { blob - e360955ca287d181a8ff24dbf66100470e96de18 blob + 56e2d804dc17e77e5b5660bcd248453a942fcbb4 --- include/got_blame.h +++ include/got_blame.h @@ -36,4 +36,4 @@ typedef const struct got_error *(*got_blame_cb)(void * */ const struct got_error *got_blame(const char *, struct got_object_id *, struct got_repository *, - got_blame_cb, void *, got_cancel_cb, void *); + got_blame_cb, void *, got_cancel_cb, void *, int); blob - c95dcf7b940e7c0d35bb98e78c05847c04390c98 blob + eb13ac75e0c336bec54b71046ba2a3d166afff3c --- lib/blame.c +++ lib/blame.c @@ -507,7 +507,8 @@ close_file2_and_reuse_file1(struct got_blame *blame) static const struct got_error * blame_open(struct got_blame **blamep, const char *path, struct got_object_id *start_commit_id, struct got_repository *repo, - got_blame_cb cb, void *arg, got_cancel_cb cancel_cb, void *cancel_arg) + got_blame_cb cb, void *arg, got_cancel_cb cancel_cb, void *cancel_arg, + int fd) { const struct got_error *err = NULL; struct got_commit_object *start_commit = NULL, *last_commit = NULL; @@ -515,13 +516,9 @@ blame_open(struct got_blame **blamep, const char *path struct got_blob_object *blob = NULL; struct got_blame *blame = NULL; struct got_object_id *id = NULL; - int lineno, fd = -1; + int lineno; struct got_commit_graph *graph = NULL; - fd = got_opentempfd(); - if (fd == -1) - return got_error_from_errno("got_opentempfd"); - *blamep = NULL; err = got_object_open_as_commit(&start_commit, repo, start_commit_id); @@ -644,8 +641,6 @@ done: if (graph) got_commit_graph_close(graph); free(obj_id); - if (fd != -1 && close(fd) == -1 && err == NULL) - err = got_error_from_errno("close"); if (blob) got_object_blob_close(blob); if (start_commit) @@ -664,7 +659,7 @@ done: const struct got_error * got_blame(const char *path, struct got_object_id *commit_id, struct got_repository *repo, got_blame_cb cb, void *arg, - got_cancel_cb cancel_cb, void* cancel_arg) + got_cancel_cb cancel_cb, void* cancel_arg, int fd) { const struct got_error *err = NULL, *close_err = NULL; struct got_blame *blame; @@ -674,7 +669,7 @@ got_blame(const char *path, struct got_object_id *comm return got_error_from_errno2("asprintf", path); err = blame_open(&blame, abspath, commit_id, repo, cb, arg, - cancel_cb, cancel_arg); + cancel_cb, cancel_arg, fd); free(abspath); if (blame) close_err = blame_close(blame); blob - d4eb22343e8c4a8e2363f38b1954b530f978b2fb blob + d64012417f253911bc36a073d92ed6e833b4b98b --- tog/tog.c +++ tog/tog.c @@ -4666,14 +4666,18 @@ blame_thread(void *arg) const struct got_error *err, *close_err; struct tog_blame_thread_args *ta = arg; struct tog_blame_cb_args *a = ta->cb_args; - int errcode; + int errcode, fd = -1; + + fd = got_opentempfd(); + if (fd == -1) + return (void *)got_error_from_errno("got_opentempfd"); err = block_signals_used_by_main_thread(); if (err) return (void *)err; err = got_blame(ta->path, a->commit_id, ta->repo, - blame_cb, ta->cb_args, ta->cancel_cb, ta->cancel_arg); + blame_cb, ta->cb_args, ta->cancel_cb, ta->cancel_arg, fd); if (err && err->code == GOT_ERR_CANCELLED) err = NULL; @@ -4692,6 +4696,9 @@ blame_thread(void *arg) if (errcode && err == NULL) err = got_error_set_errno(errcode, "pthread_mutex_unlock"); + if (fd != -1 && close(fd) == -1 && err == NULL) + err = got_error_from_errno("close"); + return (void *)err; }