From 96f36c64de3ee80a64fcd13eb66b1d487375c983 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Fri, 5 Mar 2021 11:21:33 -0800 Subject: [PATCH] making relevant repository explicit for a few functions Signed-off-by: Elijah Newren --- builtin/hash-object.c | 5 ++-- merge-ort.c | 24 +++++++++++-------- object-file.c | 54 +++++++++++++++++++++---------------------- object-store-ll.h | 33 ++++++++++++++++++-------- 4 files changed, 67 insertions(+), 49 deletions(-) diff --git a/builtin/hash-object.c b/builtin/hash-object.c index c767414a0cc6ca..b80926b81f6ebc 100644 --- a/builtin/hash-object.c +++ b/builtin/hash-object.c @@ -31,8 +31,9 @@ static int hash_literally(struct object_id *oid, int fd, const char *type, unsig if (strbuf_read(&buf, fd, 4096) < 0) ret = -1; else - ret = write_object_file_literally(buf.buf, buf.len, type, oid, - flags); + ret = repo_write_object_file_literally(the_repository, buf.buf, + buf.len, type, oid, + flags); close(fd); strbuf_release(&buf); return ret; diff --git a/merge-ort.c b/merge-ort.c index eaede6cead9442..cd25c557a51a03 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -2177,8 +2177,9 @@ static int handle_content_merge(struct merge_options *opt, ret = error(_("failed to execute internal merge")); if (!ret && - write_object_file(result_buf.ptr, result_buf.size, - OBJ_BLOB, &result->oid)) + repo_write_object_file(opt->repo, + result_buf.ptr, result_buf.size, + OBJ_BLOB, &result->oid)) ret = error(_("unable to add %s to database"), path); free(result_buf.ptr); @@ -3557,13 +3558,14 @@ static int sort_dirs_next_to_their_children(const char *one, const char *two) return c1 - c2; } -static int read_oid_strbuf(const struct object_id *oid, +static int read_oid_strbuf(struct repository *r, + const struct object_id *oid, struct strbuf *dst) { void *buf; enum object_type type; unsigned long size; - buf = repo_read_object_file(the_repository, oid, &type, &size); + buf = repo_read_object_file(r, oid, &type, &size); if (!buf) return error(_("cannot read object %s"), oid_to_hex(oid)); if (type != OBJ_BLOB) { @@ -3592,8 +3594,8 @@ static int blob_unchanged(struct merge_options *opt, if (oideq(&base->oid, &side->oid)) return 1; - if (read_oid_strbuf(&base->oid, &basebuf) || - read_oid_strbuf(&side->oid, &sidebuf)) + if (read_oid_strbuf(opt->repo, &base->oid, &basebuf) || + read_oid_strbuf(opt->repo, &side->oid, &sidebuf)) goto error_return; /* * Note: binary | is used so that both renormalizations are @@ -3665,7 +3667,8 @@ static int tree_entry_order(const void *a_, const void *b_) b->string, strlen(b->string), bmi->result.mode); } -static int write_tree(struct object_id *result_oid, +static int write_tree(struct repository *repo, + struct object_id *result_oid, struct string_list *versions, unsigned int offset, size_t hash_size) @@ -3699,7 +3702,7 @@ static int write_tree(struct object_id *result_oid, } /* Write this object file out, and record in result_oid */ - if (write_object_file(buf.buf, buf.len, OBJ_TREE, result_oid)) + if (repo_write_object_file(repo, buf.buf, buf.len, OBJ_TREE, result_oid)) ret = -1; strbuf_release(&buf); return ret; @@ -3865,7 +3868,8 @@ static int write_completed_directory(struct merge_options *opt, */ dir_info->is_null = 0; dir_info->result.mode = S_IFDIR; - if (write_tree(&dir_info->result.oid, &info->versions, offset, + if (write_tree(opt->repo, + &dir_info->result.oid, &info->versions, offset, opt->repo->hash_algo->rawsz) < 0) ret = -1; } @@ -4400,7 +4404,7 @@ static int process_entries(struct merge_options *opt, fflush(stdout); BUG("dir_metadata accounting completely off; shouldn't happen"); } - if (write_tree(result_oid, &dir_metadata.versions, 0, + if (write_tree(opt->repo, result_oid, &dir_metadata.versions, 0, opt->repo->hash_algo->rawsz) < 0) ret = -1; cleanup: diff --git a/object-file.c b/object-file.c index d3cf4b8b2ead25..af8241d504e58d 100644 --- a/object-file.c +++ b/object-file.c @@ -1955,9 +1955,9 @@ static void hash_object_file_literally(const struct git_hash_algo *algo, write_object_file_prepare_literally(algo, buf, len, type, oid, hdr, &hdrlen); } -void hash_object_file(const struct git_hash_algo *algo, const void *buf, - unsigned long len, enum object_type type, - struct object_id *oid) +void hash_object_file(const struct git_hash_algo *algo, + const void *buf, unsigned long len, + enum object_type type, struct object_id *oid) { hash_object_file_literally(algo, buf, len, type_name(type), oid); } @@ -2134,7 +2134,8 @@ static int end_loose_object_common(git_hash_ctx *c, git_hash_ctx *compat_c, return Z_OK; } -static int write_loose_object(const struct object_id *oid, char *hdr, +static int write_loose_object(struct repository *repo, + const struct object_id *oid, char *hdr, int hdrlen, const void *buf, unsigned long len, time_t mtime, unsigned flags) { @@ -2149,7 +2150,7 @@ static int write_loose_object(const struct object_id *oid, char *hdr, if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT)) prepare_loose_object_bulk_checkin(); - loose_object_path(the_repository, &filename, oid); + loose_object_path(repo, &filename, oid); fd = start_loose_object_common(&tmp_file, filename.buf, flags, &stream, compressed, sizeof(compressed), @@ -2320,13 +2321,13 @@ int stream_loose_object(struct input_stream *in_stream, size_t len, return err; } -int write_object_file_flags(const void *buf, unsigned long len, - enum object_type type, struct object_id *oid, - struct object_id *compat_oid_in, unsigned flags) +int repo_write_object_file_flags(struct repository *r, const void *buf, + unsigned long len, enum object_type type, + struct object_id *oid, + struct object_id *compat_oid_in, unsigned flags) { - struct repository *repo = the_repository; - const struct git_hash_algo *algo = repo->hash_algo; - const struct git_hash_algo *compat = repo->compat_hash_algo; + const struct git_hash_algo *algo = r->hash_algo; + const struct git_hash_algo *compat = r->compat_hash_algo; struct object_id compat_oid; char hdr[MAX_HEADER_LEN]; int hdrlen = sizeof(hdr); @@ -2353,21 +2354,20 @@ int write_object_file_flags(const void *buf, unsigned long len, write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen); if (freshen_packed_object(oid) || freshen_loose_object(oid)) return 0; - if (write_loose_object(oid, hdr, hdrlen, buf, len, 0, flags)) + if (write_loose_object(r, oid, hdr, hdrlen, buf, len, 0, flags)) return -1; if (compat) - return repo_add_loose_object_map(repo, oid, &compat_oid); + return repo_add_loose_object_map(r, oid, &compat_oid); return 0; } -int write_object_file_literally(const void *buf, unsigned long len, - const char *type, struct object_id *oid, - unsigned flags) +int repo_write_object_file_literally(struct repository *r, const void *buf, + unsigned long len, const char *type, + struct object_id *oid, unsigned flags) { char *header; - struct repository *repo = the_repository; - const struct git_hash_algo *algo = repo->hash_algo; - const struct git_hash_algo *compat = repo->compat_hash_algo; + const struct git_hash_algo *algo = r->hash_algo; + const struct git_hash_algo *compat = r->compat_hash_algo; struct object_id compat_oid; int hdrlen, status = 0; int compat_type = -1; @@ -2397,19 +2397,19 @@ int write_object_file_literally(const void *buf, unsigned long len, goto cleanup; if (freshen_packed_object(oid) || freshen_loose_object(oid)) goto cleanup; - status = write_loose_object(oid, header, hdrlen, buf, len, 0, 0); + status = write_loose_object(r, oid, header, hdrlen, buf, len, 0, 0); if (compat_type != -1) - return repo_add_loose_object_map(repo, oid, &compat_oid); + return repo_add_loose_object_map(r, oid, &compat_oid); cleanup: free(header); return status; } -int force_object_loose(const struct object_id *oid, time_t mtime) +int repo_force_object_loose(struct repository *r, + const struct object_id *oid, time_t mtime) { - struct repository *repo = the_repository; - const struct git_hash_algo *compat = repo->compat_hash_algo; + const struct git_hash_algo *compat = r->compat_hash_algo; void *buf; unsigned long len; struct object_info oi = OBJECT_INFO_INIT; @@ -2427,14 +2427,14 @@ int force_object_loose(const struct object_id *oid, time_t mtime) if (oid_object_info_extended(the_repository, oid, &oi, 0)) return error(_("cannot read object for %s"), oid_to_hex(oid)); if (compat) { - if (repo_oid_to_algop(repo, oid, compat, &compat_oid)) + if (repo_oid_to_algop(r, oid, compat, &compat_oid)) return error(_("cannot map object %s to %s"), oid_to_hex(oid), compat->name); } hdrlen = format_object_header(hdr, sizeof(hdr), type, len); - ret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime, 0); + ret = write_loose_object(r, oid, hdr, hdrlen, buf, len, mtime, 0); if (!ret && compat) - ret = repo_add_loose_object_map(the_repository, oid, &compat_oid); + ret = repo_add_loose_object_map(r, oid, &compat_oid); free(buf); return ret; diff --git a/object-store-ll.h b/object-store-ll.h index c5f2bb2fc2fe6e..852c39a9370b0f 100644 --- a/object-store-ll.h +++ b/object-store-ll.h @@ -253,21 +253,30 @@ void hash_object_file(const struct git_hash_algo *algo, const void *buf, unsigned long len, enum object_type type, struct object_id *oid); -int write_object_file_flags(const void *buf, unsigned long len, - enum object_type type, struct object_id *oid, - struct object_id *comapt_oid_in, unsigned flags); -static inline int write_object_file(const void *buf, unsigned long len, - enum object_type type, struct object_id *oid) +int repo_write_object_file_flags(struct repository *r, const void *buf, + unsigned long len, enum object_type type, + struct object_id *oid, + struct object_id *comapt_oid_in, + unsigned flags); +static inline int repo_write_object_file(struct repository *r, const void *buf, + unsigned long len, + enum object_type type, + struct object_id *oid) { - return write_object_file_flags(buf, len, type, oid, NULL, 0); + return repo_write_object_file_flags(r, buf, len, type, oid, NULL, 0); } -int write_object_file_literally(const void *buf, unsigned long len, - const char *type, struct object_id *oid, - unsigned flags); +int repo_write_object_file_literally(struct repository *r, const void *buf, + unsigned long len, const char *type, + struct object_id *oid, unsigned flags); int stream_loose_object(struct input_stream *in_stream, size_t len, struct object_id *oid); +#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS +#define write_object_file_flags(buf, len, type, oid, compat_oid_in, flags) repo_write_object_file_flags(the_repository, buf, len, type, oid, compat_oid_in, flags) +#define write_object_file(buf, len, type, oid) repo_write_object_file(the_repository, buf, len, type, oid) +#endif + /* * Add an object file to the in-memory object store, without writing it * to disk. @@ -279,7 +288,11 @@ int stream_loose_object(struct input_stream *in_stream, size_t len, int pretend_object_file(void *, unsigned long, enum object_type, struct object_id *oid); -int force_object_loose(const struct object_id *oid, time_t mtime); +int repo_force_object_loose(struct repository *r, + const struct object_id *oid, time_t mtime); +#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS +#define force_object_loose(oid, mtime) repo_force_object_loose(the_repository, oid, mtime) +#endif struct object_info { /* Request */