tempfile: prefer is_tempfile_active to bare access
The tempfile code keeps an "active" flag, and we have a number of assertions to make sure that the objects are being used in the right order. Most of these directly check "active" rather than using the is_tempfile_active() accessor. Let's prefer using the accessor, in preparation for it growing more complicated logic (like checking for NULL). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Sep 5, 2017 at 08:14 UTC
e6fc267314d24fe9a81875b85b28a4b5d0fb78b1
1 file changed
+8
-8
tempfile.c
+8
-8
@@ -95,7 +95,7 @@ static void prepare_tempfile_object(struct tempfile *tempfile)
95
atexit(remove_tempfiles_on_exit);
96
}
97
98
- if (tempfile->active)
98
+ if (is_tempfile_active(tempfile))
99
die("BUG: prepare_tempfile_object called for active object");
100
if (!tempfile->on_list) {
101
/* Initialize *tempfile and add it to tempfile_list: */
@@ -204,7 +204,7 @@ int xmks_tempfile_m(struct tempfile *tempfile, const char *template, int mode)
204
205
FILE *fdopen_tempfile(struct tempfile *tempfile, const char *mode)
206
{
207
- if (!tempfile->active)
207
+ if (!is_tempfile_active(tempfile))
208
die("BUG: fdopen_tempfile() called for inactive object");
209
if (tempfile->fp)
210
die("BUG: fdopen_tempfile() called for open object");
@@ -215,21 +215,21 @@ FILE *fdopen_tempfile(struct tempfile *tempfile, const char *mode)
215
216
const char *get_tempfile_path(struct tempfile *tempfile)
217
{
218
- if (!tempfile->active)
218
+ if (!is_tempfile_active(tempfile))
219
die("BUG: get_tempfile_path() called for inactive object");
220
return tempfile->filename.buf;
221
}
222
223
int get_tempfile_fd(struct tempfile *tempfile)
224
{
225
- if (!tempfile->active)
225
+ if (!is_tempfile_active(tempfile))
226
die("BUG: get_tempfile_fd() called for inactive object");
227
return tempfile->fd;
228
}
229
230
FILE *get_tempfile_fp(struct tempfile *tempfile)
231
{
232
- if (!tempfile->active)
232
+ if (!is_tempfile_active(tempfile))
233
die("BUG: get_tempfile_fp() called for inactive object");
234
return tempfile->fp;
235
}
@@ -264,7 +264,7 @@ int reopen_tempfile(struct tempfile *tempfile)
264
{
265
if (0 <= tempfile->fd)
266
die("BUG: reopen_tempfile called for an open object");
267
- if (!tempfile->active)
267
+ if (!is_tempfile_active(tempfile))
268
die("BUG: reopen_tempfile called for an inactive object");
269
tempfile->fd = open(tempfile->filename.buf, O_WRONLY);
270
return tempfile->fd;
@@ -272,7 +272,7 @@ int reopen_tempfile(struct tempfile *tempfile)
272
273
int rename_tempfile(struct tempfile *tempfile, const char *path)
274
{
275
- if (!tempfile->active)
275
+ if (!is_tempfile_active(tempfile))
276
die("BUG: rename_tempfile called for inactive object");
277
278
if (close_tempfile_gently(tempfile)) {
@@ -294,7 +294,7 @@ int rename_tempfile(struct tempfile *tempfile, const char *path)
294
295
void delete_tempfile(struct tempfile *tempfile)
296
{
297
- if (!tempfile->active)
297
+ if (!is_tempfile_active(tempfile))
298
return;
299
300
close_tempfile_gently(tempfile);