move got_opentempfd out of blame_open ok stsp@ jrick@
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
diff --git a/got/got.c b/got/got.c
index e466549..69e5ee6 100644
--- a/got/got.c
+++ b/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)
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index ffc24fe..bfc88e3 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -4064,7 +4064,7 @@ gw_output_file_blame(struct gw_trans *gw_trans, struct gw_header *header)
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 gw_header *header)
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++) {
diff --git a/include/got_blame.h b/include/got_blame.h
index e360955..56e2d80 100644
--- a/include/got_blame.h
+++ b/include/got_blame.h
@@ -36,4 +36,4 @@ typedef const struct got_error *(*got_blame_cb)(void *, int, int,
*/
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);
diff --git a/lib/blame.c b/lib/blame.c
index ccdc439..68e7392 100644
--- a/lib/blame.c
+++ b/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 *commit_id,
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);
diff --git a/tog/tog.c b/tog/tog.c
index 02357b5..0b32bf9 100644
--- a/tog/tog.c
+++ b/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;
}