Git fork

object-file: get rid of `the_repository` in `finalize_object_file()`

We implicitly depend on `the_repository` when moving an object file into
place in `finalize_object_file()`. Get rid of this global dependency by
passing in a repository.

Note that one might be pressed to inject an object database instead of a
repository. But the function doesn't really care about the ODB at all.
All it does is to move a file into place while checking whether there is
any collision. As such, the functionality it provides is independent of
the object database and only needs the repository as parameter so that
it can adjust permissions of the file we are about to finalize.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
cbb388f3 1efe0aea

+32 -25
+2 -2
builtin/fast-import.c
··· 821 821 die_errno("failed to write keep file"); 822 822 823 823 odb_pack_name(pack_data->repo, &name, pack_data->hash, "pack"); 824 - if (finalize_object_file(pack_data->pack_name, name.buf)) 824 + if (finalize_object_file(pack_data->repo, pack_data->pack_name, name.buf)) 825 825 die("cannot store pack file"); 826 826 827 827 odb_pack_name(pack_data->repo, &name, pack_data->hash, "idx"); 828 - if (finalize_object_file(curr_index_name, name.buf)) 828 + if (finalize_object_file(pack_data->repo, curr_index_name, name.buf)) 829 829 die("cannot store index file"); 830 830 free((void *)curr_index_name); 831 831 return strbuf_detach(&name, NULL);
+1 -1
builtin/index-pack.c
··· 1598 1598 if (!*final_name || strcmp(*final_name, curr_name)) { 1599 1599 if (!*final_name) 1600 1600 *final_name = odb_pack_name(the_repository, name, hash, ext); 1601 - if (finalize_object_file(curr_name, *final_name)) 1601 + if (finalize_object_file(the_repository, curr_name, *final_name)) 1602 1602 die(_("unable to rename temporary '*.%s' file to '%s'"), 1603 1603 ext, *final_name); 1604 1604 } else if (make_read_only_if_same) {
+1 -1
builtin/pack-objects.c
··· 1449 1449 strbuf_setlen(&tmpname, tmpname_len); 1450 1450 } 1451 1451 1452 - rename_tmp_packfile_idx(&tmpname, &idx_tmp_name); 1452 + rename_tmp_packfile_idx(the_repository, &tmpname, &idx_tmp_name); 1453 1453 1454 1454 free(idx_tmp_name); 1455 1455 strbuf_release(&tmpname);
+1 -1
bulk-checkin.c
··· 46 46 stage_tmp_packfiles(the_repository, basename, pack_tmp_name, 47 47 written_list, nr_written, NULL, pack_idx_opts, hash, 48 48 &idx_tmp_name); 49 - rename_tmp_packfile_idx(basename, &idx_tmp_name); 49 + rename_tmp_packfile_idx(the_repository, basename, &idx_tmp_name); 50 50 51 51 free(idx_tmp_name); 52 52 }
+2 -2
http.c
··· 2331 2331 ret = http_request_reauth(url, result, HTTP_REQUEST_FILE, options); 2332 2332 fclose(result); 2333 2333 2334 - if (ret == HTTP_OK && finalize_object_file(tmpfile.buf, filename)) 2334 + if (ret == HTTP_OK && finalize_object_file(the_repository, tmpfile.buf, filename)) 2335 2335 ret = HTTP_ERROR; 2336 2336 cleanup: 2337 2337 strbuf_release(&tmpfile); ··· 2815 2815 return -1; 2816 2816 } 2817 2817 odb_loose_path(the_repository->objects->sources, &filename, &freq->oid); 2818 - freq->rename = finalize_object_file(freq->tmpfile.buf, filename.buf); 2818 + freq->rename = finalize_object_file(the_repository, freq->tmpfile.buf, filename.buf); 2819 2819 strbuf_release(&filename); 2820 2820 2821 2821 return freq->rename;
+1 -1
midx-write.c
··· 667 667 tmp_file = write_rev_file_order(ctx->repo, NULL, ctx->pack_order, 668 668 ctx->entries_nr, midx_hash, WRITE_REV); 669 669 670 - if (finalize_object_file(tmp_file, buf.buf)) 670 + if (finalize_object_file(ctx->repo, tmp_file, buf.buf)) 671 671 die(_("cannot store reverse index file")); 672 672 673 673 strbuf_release(&buf);
+8 -6
object-file.c
··· 584 584 /* 585 585 * Move the just written object into its final resting place. 586 586 */ 587 - int finalize_object_file(const char *tmpfile, const char *filename) 587 + int finalize_object_file(struct repository *repo, 588 + const char *tmpfile, const char *filename) 588 589 { 589 - return finalize_object_file_flags(tmpfile, filename, 0); 590 + return finalize_object_file_flags(repo, tmpfile, filename, 0); 590 591 } 591 592 592 - int finalize_object_file_flags(const char *tmpfile, const char *filename, 593 + int finalize_object_file_flags(struct repository *repo, 594 + const char *tmpfile, const char *filename, 593 595 enum finalize_object_file_flags flags) 594 596 { 595 597 unsigned retries = 0; ··· 649 651 } 650 652 651 653 out: 652 - if (adjust_shared_perm(the_repository, filename)) 654 + if (adjust_shared_perm(repo, filename)) 653 655 return error(_("unable to set permission to '%s'"), filename); 654 656 return 0; 655 657 } ··· 889 891 warning_errno(_("failed utime() on %s"), tmp_file.buf); 890 892 } 891 893 892 - return finalize_object_file_flags(tmp_file.buf, filename.buf, 894 + return finalize_object_file_flags(the_repository, tmp_file.buf, filename.buf, 893 895 FOF_SKIP_COLLISION_CHECK); 894 896 } 895 897 ··· 1020 1022 strbuf_release(&dir); 1021 1023 } 1022 1024 1023 - err = finalize_object_file_flags(tmp_file.buf, filename.buf, 1025 + err = finalize_object_file_flags(the_repository, tmp_file.buf, filename.buf, 1024 1026 FOF_SKIP_COLLISION_CHECK); 1025 1027 if (!err && compat) 1026 1028 err = repo_add_loose_object_map(the_repository, oid, &compat_oid);
+4 -2
object-file.h
··· 218 218 FOF_SKIP_COLLISION_CHECK = 1, 219 219 }; 220 220 221 - int finalize_object_file(const char *tmpfile, const char *filename); 222 - int finalize_object_file_flags(const char *tmpfile, const char *filename, 221 + int finalize_object_file(struct repository *repo, 222 + const char *tmpfile, const char *filename); 223 + int finalize_object_file_flags(struct repository *repo, 224 + const char *tmpfile, const char *filename, 223 225 enum finalize_object_file_flags flags); 224 226 225 227 void hash_object_file(const struct git_hash_algo *algo, const void *buf,
+9 -7
pack-write.c
··· 538 538 return hashfd(repo->hash_algo, fd, *pack_tmp_name); 539 539 } 540 540 541 - static void rename_tmp_packfile(struct strbuf *name_prefix, const char *source, 541 + static void rename_tmp_packfile(struct repository *repo, 542 + struct strbuf *name_prefix, const char *source, 542 543 const char *ext) 543 544 { 544 545 size_t name_prefix_len = name_prefix->len; 545 546 546 547 strbuf_addstr(name_prefix, ext); 547 - if (finalize_object_file(source, name_prefix->buf)) 548 + if (finalize_object_file(repo, source, name_prefix->buf)) 548 549 die("unable to rename temporary file to '%s'", 549 550 name_prefix->buf); 550 551 strbuf_setlen(name_prefix, name_prefix_len); 551 552 } 552 553 553 - void rename_tmp_packfile_idx(struct strbuf *name_buffer, 554 + void rename_tmp_packfile_idx(struct repository *repo, 555 + struct strbuf *name_buffer, 554 556 char **idx_tmp_name) 555 557 { 556 - rename_tmp_packfile(name_buffer, *idx_tmp_name, "idx"); 558 + rename_tmp_packfile(repo, name_buffer, *idx_tmp_name, "idx"); 557 559 } 558 560 559 561 void stage_tmp_packfiles(struct repository *repo, ··· 586 588 hash); 587 589 } 588 590 589 - rename_tmp_packfile(name_buffer, pack_tmp_name, "pack"); 591 + rename_tmp_packfile(repo, name_buffer, pack_tmp_name, "pack"); 590 592 if (rev_tmp_name) 591 - rename_tmp_packfile(name_buffer, rev_tmp_name, "rev"); 593 + rename_tmp_packfile(repo, name_buffer, rev_tmp_name, "rev"); 592 594 if (mtimes_tmp_name) 593 - rename_tmp_packfile(name_buffer, mtimes_tmp_name, "mtimes"); 595 + rename_tmp_packfile(repo, name_buffer, mtimes_tmp_name, "mtimes"); 594 596 595 597 free(rev_tmp_name); 596 598 free(mtimes_tmp_name);
+2 -1
pack.h
··· 145 145 struct pack_idx_option *pack_idx_opts, 146 146 unsigned char hash[], 147 147 char **idx_tmp_name); 148 - void rename_tmp_packfile_idx(struct strbuf *basename, 148 + void rename_tmp_packfile_idx(struct repository *repo, 149 + struct strbuf *basename, 149 150 char **idx_tmp_name); 150 151 151 152 #endif
+1 -1
tmp-objdir.c
··· 227 227 return -1; 228 228 return migrate_paths(t, src, dst, flags); 229 229 } 230 - return finalize_object_file_flags(src->buf, dst->buf, flags); 230 + return finalize_object_file_flags(t->repo, src->buf, dst->buf, flags); 231 231 } 232 232 233 233 static int is_loose_object_shard(const char *name)