Download raw body.
move got_opentempfd out of blame_open
Here is the diff to move got_opentempfd out of blame_open. Ok? -- Tracey Emery diff /home/tracey/src/got commit - eb81bc23c735e8aa9eaee796a230c7d7c76657ba path + /home/tracey/src/got blob - e4665492a3022c605cf1a1fa244f10c606b8b0b7 file + got/got.c --- got/got.c +++ got/got.c @@ -5316,7 +5316,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; @@ -5505,8 +5505,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); @@ -5518,6 +5523,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 - ffc24fe2d445b82dd5d5ff2616a3ce538f584cb8 file + gotweb/gotweb.c --- gotweb/gotweb.c +++ gotweb/gotweb.c @@ -4064,7 +4064,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(); @@ -4147,8 +4147,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); @@ -4157,6 +4163,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 file + include/got_blame.h --- 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 - ccdc439eeee3aee6cb11526d0cd547f98bb7612c file + lib/blame.c --- lib/blame.c +++ lib/blame.c @@ -508,7 +508,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; @@ -516,13 +517,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); @@ -645,8 +642,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) @@ -665,7 +660,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; @@ -675,7 +670,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 - 02357b5d2aa6509aa4c4c341f9bc46ba93cf213d file + tog/tog.c --- tog/tog.c +++ tog/tog.c @@ -4657,14 +4657,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; @@ -4683,6 +4687,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; }
move got_opentempfd out of blame_open