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>
This commit is contained in:
Jeff King 2017-09-05 08:14:36 -04:00 коммит произвёл Junio C Hamano
Родитель 83a3069a38
Коммит e6fc267314
1 изменённых файлов: 8 добавлений и 8 удалений

Просмотреть файл

@ -95,7 +95,7 @@ static void prepare_tempfile_object(struct tempfile *tempfile)
atexit(remove_tempfiles_on_exit); atexit(remove_tempfiles_on_exit);
} }
if (tempfile->active) if (is_tempfile_active(tempfile))
die("BUG: prepare_tempfile_object called for active object"); die("BUG: prepare_tempfile_object called for active object");
if (!tempfile->on_list) { if (!tempfile->on_list) {
/* Initialize *tempfile and add it to tempfile_list: */ /* Initialize *tempfile and add it to tempfile_list: */
@ -204,7 +204,7 @@ int xmks_tempfile_m(struct tempfile *tempfile, const char *template, int mode)
FILE *fdopen_tempfile(struct tempfile *tempfile, const char *mode) FILE *fdopen_tempfile(struct tempfile *tempfile, const char *mode)
{ {
if (!tempfile->active) if (!is_tempfile_active(tempfile))
die("BUG: fdopen_tempfile() called for inactive object"); die("BUG: fdopen_tempfile() called for inactive object");
if (tempfile->fp) if (tempfile->fp)
die("BUG: fdopen_tempfile() called for open object"); die("BUG: fdopen_tempfile() called for open object");
@ -215,21 +215,21 @@ FILE *fdopen_tempfile(struct tempfile *tempfile, const char *mode)
const char *get_tempfile_path(struct tempfile *tempfile) const char *get_tempfile_path(struct tempfile *tempfile)
{ {
if (!tempfile->active) if (!is_tempfile_active(tempfile))
die("BUG: get_tempfile_path() called for inactive object"); die("BUG: get_tempfile_path() called for inactive object");
return tempfile->filename.buf; return tempfile->filename.buf;
} }
int get_tempfile_fd(struct tempfile *tempfile) int get_tempfile_fd(struct tempfile *tempfile)
{ {
if (!tempfile->active) if (!is_tempfile_active(tempfile))
die("BUG: get_tempfile_fd() called for inactive object"); die("BUG: get_tempfile_fd() called for inactive object");
return tempfile->fd; return tempfile->fd;
} }
FILE *get_tempfile_fp(struct tempfile *tempfile) FILE *get_tempfile_fp(struct tempfile *tempfile)
{ {
if (!tempfile->active) if (!is_tempfile_active(tempfile))
die("BUG: get_tempfile_fp() called for inactive object"); die("BUG: get_tempfile_fp() called for inactive object");
return tempfile->fp; return tempfile->fp;
} }
@ -264,7 +264,7 @@ int reopen_tempfile(struct tempfile *tempfile)
{ {
if (0 <= tempfile->fd) if (0 <= tempfile->fd)
die("BUG: reopen_tempfile called for an open object"); die("BUG: reopen_tempfile called for an open object");
if (!tempfile->active) if (!is_tempfile_active(tempfile))
die("BUG: reopen_tempfile called for an inactive object"); die("BUG: reopen_tempfile called for an inactive object");
tempfile->fd = open(tempfile->filename.buf, O_WRONLY); tempfile->fd = open(tempfile->filename.buf, O_WRONLY);
return tempfile->fd; return tempfile->fd;
@ -272,7 +272,7 @@ int reopen_tempfile(struct tempfile *tempfile)
int rename_tempfile(struct tempfile *tempfile, const char *path) int rename_tempfile(struct tempfile *tempfile, const char *path)
{ {
if (!tempfile->active) if (!is_tempfile_active(tempfile))
die("BUG: rename_tempfile called for inactive object"); die("BUG: rename_tempfile called for inactive object");
if (close_tempfile_gently(tempfile)) { if (close_tempfile_gently(tempfile)) {
@ -294,7 +294,7 @@ int rename_tempfile(struct tempfile *tempfile, const char *path)
void delete_tempfile(struct tempfile *tempfile) void delete_tempfile(struct tempfile *tempfile)
{ {
if (!tempfile->active) if (!is_tempfile_active(tempfile))
return; return;
close_tempfile_gently(tempfile); close_tempfile_gently(tempfile);