Skip to content

Commit cb5add5

Browse files
committed
sha1_file.c: rename move_temp_to_file() to finalize_object_file()
Since 5a688fe ("core.sharedrepository = 0mode" should set, not loosen, 2009-03-25), we kept reminding ourselves: NEEDSWORK: this should be renamed to finalize_temp_file() as "moving" is only a part of what it does, when no patch between master to pu changes the call sites of this function. without doing anything about it. Let's do so. The purpose of this function was not to move but to finalize. The detail of the primarily implementation of finalizing was to link the temporary file to its final name and then to unlink, which wasn't even "moving". The alternative implementation did "move" by calling rename(2), which is a fun tangent. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 282616c commit cb5add5

File tree

5 files changed

+12
-15
lines changed

5 files changed

+12
-15
lines changed

builtin/index-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
13221322
get_object_directory(), sha1_to_hex(sha1));
13231323
final_pack_name = name;
13241324
}
1325-
if (move_temp_to_file(curr_pack_name, final_pack_name))
1325+
if (finalize_object_file(curr_pack_name, final_pack_name))
13261326
die(_("cannot store pack file"));
13271327
} else if (from_stdin)
13281328
chmod(final_pack_name, 0444);
@@ -1333,7 +1333,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
13331333
get_object_directory(), sha1_to_hex(sha1));
13341334
final_index_name = name;
13351335
}
1336-
if (move_temp_to_file(curr_index_name, final_index_name))
1336+
if (finalize_object_file(curr_index_name, final_index_name))
13371337
die(_("cannot store index file"));
13381338
} else
13391339
chmod(final_index_name, 0444);

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ extern int do_check_packed_object_crc;
865865

866866
extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type);
867867

868-
extern int move_temp_to_file(const char *tmpfile, const char *filename);
868+
extern int finalize_object_file(const char *tmpfile, const char *filename);
869869

870870
extern int has_sha1_pack(const unsigned char *sha1);
871871

fast-import.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,12 +919,12 @@ static char *keep_pack(const char *curr_index_name)
919919

920920
snprintf(name, sizeof(name), "%s/pack/pack-%s.pack",
921921
get_object_directory(), sha1_to_hex(pack_data->sha1));
922-
if (move_temp_to_file(pack_data->pack_name, name))
922+
if (finalize_object_file(pack_data->pack_name, name))
923923
die("cannot store pack file");
924924

925925
snprintf(name, sizeof(name), "%s/pack/pack-%s.idx",
926926
get_object_directory(), sha1_to_hex(pack_data->sha1));
927-
if (move_temp_to_file(curr_index_name, name))
927+
if (finalize_object_file(curr_index_name, name))
928928
die("cannot store index file");
929929
free((void *)curr_index_name);
930930
return name;

http.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ static int http_get_file(const char *url, const char *filename,
10911091
ret = http_request_reauth(url, result, HTTP_REQUEST_FILE, options);
10921092
fclose(result);
10931093

1094-
if (ret == HTTP_OK && move_temp_to_file(tmpfile.buf, filename))
1094+
if (ret == HTTP_OK && finalize_object_file(tmpfile.buf, filename))
10951095
ret = HTTP_ERROR;
10961096
cleanup:
10971097
strbuf_release(&tmpfile);
@@ -1178,7 +1178,7 @@ static int fetch_and_setup_pack_index(struct packed_git **packs_head,
11781178
ret = verify_pack_index(new_pack);
11791179
if (!ret) {
11801180
close_pack_index(new_pack);
1181-
ret = move_temp_to_file(tmp_idx, sha1_pack_index_name(sha1));
1181+
ret = finalize_object_file(tmp_idx, sha1_pack_index_name(sha1));
11821182
}
11831183
free(tmp_idx);
11841184
if (ret)
@@ -1290,8 +1290,8 @@ int finish_http_pack_request(struct http_pack_request *preq)
12901290

12911291
unlink(sha1_pack_index_name(p->sha1));
12921292

1293-
if (move_temp_to_file(preq->tmpfile, sha1_pack_name(p->sha1))
1294-
|| move_temp_to_file(tmp_idx, sha1_pack_index_name(p->sha1))) {
1293+
if (finalize_object_file(preq->tmpfile, sha1_pack_name(p->sha1))
1294+
|| finalize_object_file(tmp_idx, sha1_pack_index_name(p->sha1))) {
12951295
free(tmp_idx);
12961296
return -1;
12971297
}
@@ -1555,7 +1555,7 @@ int finish_http_object_request(struct http_object_request *freq)
15551555
return -1;
15561556
}
15571557
freq->rename =
1558-
move_temp_to_file(freq->tmpfile, sha1_file_name(freq->sha1));
1558+
finalize_object_file(freq->tmpfile, sha1_file_name(freq->sha1));
15591559

15601560
return freq->rename;
15611561
}

sha1_file.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,11 +2784,8 @@ static void write_sha1_file_prepare(const void *buf, unsigned long len,
27842784

27852785
/*
27862786
* Move the just written object into its final resting place.
2787-
* NEEDSWORK: this should be renamed to finalize_temp_file() as
2788-
* "moving" is only a part of what it does, when no patch between
2789-
* master to pu changes the call sites of this function.
27902787
*/
2791-
int move_temp_to_file(const char *tmpfile, const char *filename)
2788+
int finalize_object_file(const char *tmpfile, const char *filename)
27922789
{
27932790
int ret = 0;
27942791

@@ -2962,7 +2959,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
29622959
tmp_file, strerror(errno));
29632960
}
29642961

2965-
return move_temp_to_file(tmp_file, filename);
2962+
return finalize_object_file(tmp_file, filename);
29662963
}
29672964

29682965
int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *returnsha1)

0 commit comments

Comments
 (0)