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>
Jeff King committed
Sep 5, 2017 at 08:14 UTC
2933ebbac1967a677eaed1945068941bc3ff7751
1 file changed
+10
-8
tempfile.c
+10
-8
@@ -113,6 +113,12 @@ static void prepare_tempfile_object(struct tempfile *tempfile)
113
}
114
}
115
116
+static void activate_tempfile(struct tempfile *tempfile)
117
+{
118
+ tempfile->owner = getpid();
119
+ tempfile->active = 1;
120
+}
121
+
122
/* Make sure errno contains a meaningful value on error */
123
int create_tempfile(struct tempfile *tempfile, const char *path)
124
{
@@ -129,8 +135,7 @@ int create_tempfile(struct tempfile *tempfile, const char *path)
135
strbuf_reset(&tempfile->filename);
136
return -1;
137
}
132
- tempfile->owner = getpid();
133
- tempfile->active = 1;
138
+ activate_tempfile(tempfile);
139
if (adjust_shared_perm(tempfile->filename.buf)) {
140
int save_errno = errno;
141
error("cannot fix permission bits on %s", tempfile->filename.buf);
@@ -145,8 +150,7 @@ void register_tempfile(struct tempfile *tempfile, const char *path)
150
{
151
prepare_tempfile_object(tempfile);
152
strbuf_add_absolute_path(&tempfile->filename, path);
148
- tempfile->owner = getpid();
149
- tempfile->active = 1;
153
+ activate_tempfile(tempfile);
154
}
155
156
int mks_tempfile_sm(struct tempfile *tempfile,
@@ -160,8 +164,7 @@ int mks_tempfile_sm(struct tempfile *tempfile,
164
strbuf_reset(&tempfile->filename);
165
return -1;
166
}
163
- tempfile->owner = getpid();
164
- tempfile->active = 1;
167
+ activate_tempfile(tempfile);
168
return tempfile->fd;
169
}
170
@@ -182,8 +185,7 @@ int mks_tempfile_tsm(struct tempfile *tempfile,
185
strbuf_reset(&tempfile->filename);
186
return -1;
187
}
185
- tempfile->owner = getpid();
186
- tempfile->active = 1;
188
+ activate_tempfile(tempfile);
189
return tempfile->fd;
190
}
191