diff options
author | Jeff King <peff@peff.net> | 2017-09-05 08:14:47 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-09-06 17:19:53 +0900 |
commit | 2933ebbac1967a677eaed1945068941bc3ff7751 (patch) | |
tree | 544fff0a9a756dc62fbd07b515079d26f122bd4a /tempfile.c | |
parent | 9b028aa45a2016ae0dbdfeb85ad9d43f2017db0d (diff) | |
download | git-2933ebbac1967a677eaed1945068941bc3ff7751.tar.gz |
tempfile: factor out activation
There are a few steps required to "activate" a tempfile
struct. Let's pull these out into a function. That saves a
few repeated lines now, but more importantly will make it
easier to change the activation scheme later.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'tempfile.c')
-rw-r--r-- | tempfile.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/tempfile.c b/tempfile.c index 813cf6a81c..0e6c6b9c18 100644 --- a/tempfile.c +++ b/tempfile.c @@ -113,6 +113,12 @@ static void prepare_tempfile_object(struct tempfile *tempfile) } } +static void activate_tempfile(struct tempfile *tempfile) +{ + tempfile->owner = getpid(); + tempfile->active = 1; +} + /* Make sure errno contains a meaningful value on error */ int create_tempfile(struct tempfile *tempfile, const char *path) { @@ -129,8 +135,7 @@ int create_tempfile(struct tempfile *tempfile, const char *path) strbuf_reset(&tempfile->filename); return -1; } - tempfile->owner = getpid(); - tempfile->active = 1; + activate_tempfile(tempfile); if (adjust_shared_perm(tempfile->filename.buf)) { int save_errno = errno; error("cannot fix permission bits on %s", tempfile->filename.buf); @@ -145,8 +150,7 @@ void register_tempfile(struct tempfile *tempfile, const char *path) { prepare_tempfile_object(tempfile); strbuf_add_absolute_path(&tempfile->filename, path); - tempfile->owner = getpid(); - tempfile->active = 1; + activate_tempfile(tempfile); } int mks_tempfile_sm(struct tempfile *tempfile, @@ -160,8 +164,7 @@ int mks_tempfile_sm(struct tempfile *tempfile, strbuf_reset(&tempfile->filename); return -1; } - tempfile->owner = getpid(); - tempfile->active = 1; + activate_tempfile(tempfile); return tempfile->fd; } @@ -182,8 +185,7 @@ int mks_tempfile_tsm(struct tempfile *tempfile, strbuf_reset(&tempfile->filename); return -1; } - tempfile->owner = getpid(); - tempfile->active = 1; + activate_tempfile(tempfile); return tempfile->fd; } |