Skip to content

Commit

Permalink
making relevant repository explicit for a few functions
Browse files Browse the repository at this point in the history
Signed-off-by: Elijah Newren <[email protected]>
  • Loading branch information
newren committed Jun 28, 2024
1 parent 55d2018 commit 96f36c6
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 49 deletions.
5 changes: 3 additions & 2 deletions builtin/hash-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 14 additions & 10 deletions merge-ort.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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:
Expand Down
54 changes: 27 additions & 27 deletions object-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
{
Expand All @@ -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),
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
33 changes: 23 additions & 10 deletions object-store-ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 */
Expand Down

0 comments on commit 96f36c6

Please sign in to comment.