Skip to content

Commit f034bb1

Browse files
peffgitster
authored andcommitted
diff: drop "name" parameter from prepare_temp_file()
The prepare_temp_file() function takes a diff_filespec as well as a filename. But it is almost certainly an error to pass in a name that isn't the filespec's "path" parameter, since that is the only thing that reliably tells us how to find the content (and indeed, this was the source of a recently-fixed bug). So let's drop the redundant "name" parameter and just use one->path throughout the function. This simplifies the interface a little bit, and makes it impossible for calling code to get it wrong. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent de8f14e commit f034bb1

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

diff.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4213,7 +4213,6 @@ static void prep_temp_blob(struct index_state *istate,
42134213
}
42144214

42154215
static struct diff_tempfile *prepare_temp_file(struct repository *r,
4216-
const char *name,
42174216
struct diff_filespec *one)
42184217
{
42194218
struct diff_tempfile *temp = claim_diff_tempfile();
@@ -4231,18 +4230,18 @@ static struct diff_tempfile *prepare_temp_file(struct repository *r,
42314230

42324231
if (!S_ISGITLINK(one->mode) &&
42334232
(!one->oid_valid ||
4234-
reuse_worktree_file(r->index, name, &one->oid, 1))) {
4233+
reuse_worktree_file(r->index, one->path, &one->oid, 1))) {
42354234
struct stat st;
4236-
if (lstat(name, &st) < 0) {
4235+
if (lstat(one->path, &st) < 0) {
42374236
if (errno == ENOENT)
42384237
goto not_a_valid_file;
4239-
die_errno("stat(%s)", name);
4238+
die_errno("stat(%s)", one->path);
42404239
}
42414240
if (S_ISLNK(st.st_mode)) {
42424241
struct strbuf sb = STRBUF_INIT;
4243-
if (strbuf_readlink(&sb, name, st.st_size) < 0)
4244-
die_errno("readlink(%s)", name);
4245-
prep_temp_blob(r->index, name, temp, sb.buf, sb.len,
4242+
if (strbuf_readlink(&sb, one->path, st.st_size) < 0)
4243+
die_errno("readlink(%s)", one->path);
4244+
prep_temp_blob(r->index, one->path, temp, sb.buf, sb.len,
42464245
(one->oid_valid ?
42474246
&one->oid : null_oid()),
42484247
(one->oid_valid ?
@@ -4251,7 +4250,7 @@ static struct diff_tempfile *prepare_temp_file(struct repository *r,
42514250
}
42524251
else {
42534252
/* we can borrow from the file in the work tree */
4254-
temp->name = name;
4253+
temp->name = one->path;
42554254
if (!one->oid_valid)
42564255
oid_to_hex_r(temp->hex, null_oid());
42574256
else
@@ -4269,7 +4268,7 @@ static struct diff_tempfile *prepare_temp_file(struct repository *r,
42694268
else {
42704269
if (diff_populate_filespec(r, one, NULL))
42714270
die("cannot read data blob for %s", one->path);
4272-
prep_temp_blob(r->index, name, temp,
4271+
prep_temp_blob(r->index, one->path, temp,
42734272
one->data, one->size,
42744273
&one->oid, one->mode);
42754274
}
@@ -4280,7 +4279,7 @@ static void add_external_diff_name(struct repository *r,
42804279
struct strvec *argv,
42814280
struct diff_filespec *df)
42824281
{
4283-
struct diff_tempfile *temp = prepare_temp_file(r, df->path, df);
4282+
struct diff_tempfile *temp = prepare_temp_file(r, df);
42844283
strvec_push(argv, temp->name);
42854284
strvec_push(argv, temp->hex);
42864285
strvec_push(argv, temp->mode);
@@ -7034,7 +7033,7 @@ static char *run_textconv(struct repository *r,
70347033
struct strbuf buf = STRBUF_INIT;
70357034
int err = 0;
70367035

7037-
temp = prepare_temp_file(r, spec->path, spec);
7036+
temp = prepare_temp_file(r, spec);
70387037
strvec_push(&child.args, pgm);
70397038
strvec_push(&child.args, temp->name);
70407039

0 commit comments

Comments
 (0)