{"thread":{"id":"61864","subject":"[PATCH 0/5] refs: stop using `the_repository`","startedAt":"2024-07-30T05:22:47Z","lastAt":"2024-07-31T05:06:10Z","messageCount":12,"participants":["Patrick Steinhardt","Karthik Nayak","James Liu"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"499555","messageId":"cover.1722316795.git.ps@pks.im","threadId":"61864","inReplyTo":null,"subject":"[PATCH 0/5] refs: stop using `the_repository`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-07-30T05:22:42Z","receivedAt":"2024-07-30T05:22:47Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Hi,\n\nthis patch series removes use of `the_repository` in the refs subsystem\nand drops the `USE_THE_REPOSITORY_VARIABLE` macro define from those\nfiles.\n\nPatrick\n\nPatrick Steinhardt (5):\n  refs: stop using `the_repository`\n  refs/files: stop using `the_repository` in\n    `parse_loose_ref_contents()`\n  refs/files: stop using `the_repository`\n  refs/packed: stop using `the_repository`\n  refs/reftable: stop using `the_repository`\n\n refs.c                  | 16 ++++++-------\n refs/files-backend.c    | 29 ++++++++++++-----------\n refs/packed-backend.c   | 14 +++++------\n refs/refs-internal.h    |  3 ++-\n refs/reftable-backend.c | 51 +++++++++++++++++++++--------------------\n 5 files changed, 56 insertions(+), 57 deletions(-)\n\n-- \n2.46.0.rc1.dirty\n\n"},{"id":"499556","messageId":"482a06560a6e6aa27469b355e8c81034a8867a40.1722316795.git.ps@pks.im","threadId":"61864","inReplyTo":"cover.1722316795.git.ps@pks.im","subject":"[PATCH 1/5] refs: stop using `the_repository`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-07-30T05:22:46Z","receivedAt":"2024-07-30T05:22:50Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Convert \"refs.c\" to stop using `the_repository` in favor of the repo\nthat gets passed in via `struct ref_store`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n refs.c | 12 +++++-------\n 1 file changed, 5 insertions(+), 7 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 915aeb4d1d..94a41934d6 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -2,8 +2,6 @@\n  * The backend-independent part of the reference module.\n  */\n \n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"git-compat-util.h\"\n #include \"advice.h\"\n #include \"config.h\"\n@@ -1838,7 +1836,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,\n \t\t\t    failure_errno != ENOTDIR)\n \t\t\t\treturn NULL;\n \n-\t\t\toidclr(oid, the_repository->hash_algo);\n+\t\t\toidclr(oid, refs->repo->hash_algo);\n \t\t\tif (*flags & REF_BAD_NAME)\n \t\t\t\t*flags |= REF_ISBROKEN;\n \t\t\treturn refname;\n@@ -1848,7 +1846,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,\n \n \t\tif (!(read_flags & REF_ISSYMREF)) {\n \t\t\tif (*flags & REF_BAD_NAME) {\n-\t\t\t\toidclr(oid, the_repository->hash_algo);\n+\t\t\t\toidclr(oid, refs->repo->hash_algo);\n \t\t\t\t*flags |= REF_ISBROKEN;\n \t\t\t}\n \t\t\treturn refname;\n@@ -1856,7 +1854,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,\n \n \t\trefname = sb_refname.buf;\n \t\tif (resolve_flags & RESOLVE_REF_NO_RECURSE) {\n-\t\t\toidclr(oid, the_repository->hash_algo);\n+\t\t\toidclr(oid, refs->repo->hash_algo);\n \t\t\treturn refname;\n \t\t}\n \t\tif (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {\n@@ -2011,7 +2009,7 @@ struct ref_store *repo_get_submodule_ref_store(struct repository *repo,\n \t\tfree(subrepo);\n \t\tgoto done;\n \t}\n-\trefs = ref_store_init(subrepo, the_repository->ref_storage_format,\n+\trefs = ref_store_init(subrepo, repo->ref_storage_format,\n \t\t\t      submodule_sb.buf,\n \t\t\t      REF_STORE_READ | REF_STORE_ODB);\n \tregister_ref_store_map(&repo->submodule_ref_stores, \"submodule\",\n@@ -2045,7 +2043,7 @@ struct ref_store *get_worktree_ref_store(const struct worktree *wt)\n \t\t\t\t      common_path.buf, REF_STORE_ALL_CAPS);\n \t\tstrbuf_release(&common_path);\n \t} else {\n-\t\trefs = ref_store_init(wt->repo, the_repository->ref_storage_format,\n+\t\trefs = ref_store_init(wt->repo, wt->repo->ref_storage_format,\n \t\t\t\t      wt->repo->commondir, REF_STORE_ALL_CAPS);\n \t}\n \n-- \n2.46.0.rc1.dirty\n\n"},{"id":"499557","messageId":"fe0e2c3617c8040c632dbc3de613a1d22e8070f7.1722316795.git.ps@pks.im","threadId":"61864","inReplyTo":"cover.1722316795.git.ps@pks.im","subject":"[PATCH 2/5] refs/files: stop using `the_repository` in `parse_loose_ref_contents()`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-07-30T05:22:51Z","receivedAt":"2024-07-30T05:22:56Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"We implicitly rely on `the_repository` in `parse_loose_ref_contents()`\nby calling `parse_oid_hex()`. Convert the function to instead use\n`parse_oid_hex_algop()` and have callers pass in the hash algorithm to\nuse.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n refs.c               |  4 ++--\n refs/files-backend.c | 21 ++++++++++++---------\n refs/refs-internal.h |  3 ++-\n 3 files changed, 16 insertions(+), 12 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 94a41934d6..e082fc59b0 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1752,8 +1752,8 @@ static int refs_read_special_head(struct ref_store *ref_store,\n \t\tgoto done;\n \t}\n \n-\tresult = parse_loose_ref_contents(content.buf, oid, referent, type,\n-\t\t\t\t\t  failure_errno);\n+\tresult = parse_loose_ref_contents(ref_store->repo->hash_algo, content.buf,\n+\t\t\t\t\t  oid, referent, type, failure_errno);\n \n done:\n \tstrbuf_release(&full_path);\ndiff --git a/refs/files-backend.c b/refs/files-backend.c\nindex aa52d9be7c..3437c79699 100644\n--- a/refs/files-backend.c\n+++ b/refs/files-backend.c\n@@ -552,7 +552,8 @@ static int read_ref_internal(struct ref_store *ref_store, const char *refname,\n \tstrbuf_rtrim(&sb_contents);\n \tbuf = sb_contents.buf;\n \n-\tret = parse_loose_ref_contents(buf, oid, referent, type, &myerr);\n+\tret = parse_loose_ref_contents(ref_store->repo->hash_algo, buf,\n+\t\t\t\t       oid, referent, type, &myerr);\n \n out:\n \tif (ret && !myerr)\n@@ -586,7 +587,8 @@ static int files_read_symbolic_ref(struct ref_store *ref_store, const char *refn\n \treturn !(type & REF_ISSYMREF);\n }\n \n-int parse_loose_ref_contents(const char *buf, struct object_id *oid,\n+int parse_loose_ref_contents(const struct git_hash_algo *algop,\n+\t\t\t     const char *buf, struct object_id *oid,\n \t\t\t     struct strbuf *referent, unsigned int *type,\n \t\t\t     int *failure_errno)\n {\n@@ -604,7 +606,7 @@ int parse_loose_ref_contents(const char *buf, struct object_id *oid,\n \t/*\n \t * FETCH_HEAD has additional data after the sha.\n \t */\n-\tif (parse_oid_hex(buf, oid, &p) ||\n+\tif (parse_oid_hex_algop(buf, oid, &p, algop) ||\n \t    (*p != '\\0' && !isspace(*p))) {\n \t\t*type |= REF_ISBROKEN;\n \t\t*failure_errno = EINVAL;\n@@ -1998,7 +2000,8 @@ static int files_delete_reflog(struct ref_store *ref_store,\n \treturn ret;\n }\n \n-static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *cb_data)\n+static int show_one_reflog_ent(struct files_ref_store *refs, struct strbuf *sb,\n+\t\t\t       each_reflog_ent_fn fn, void *cb_data)\n {\n \tstruct object_id ooid, noid;\n \tchar *email_end, *message;\n@@ -2008,8 +2011,8 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c\n \n \t/* old SP new SP name <email> SP time TAB msg LF */\n \tif (!sb->len || sb->buf[sb->len - 1] != '\\n' ||\n-\t    parse_oid_hex(p, &ooid, &p) || *p++ != ' ' ||\n-\t    parse_oid_hex(p, &noid, &p) || *p++ != ' ' ||\n+\t    parse_oid_hex_algop(p, &ooid, &p, refs->base.repo->hash_algo) || *p++ != ' ' ||\n+\t    parse_oid_hex_algop(p, &noid, &p, refs->base.repo->hash_algo) || *p++ != ' ' ||\n \t    !(email_end = strchr(p, '>')) ||\n \t    email_end[1] != ' ' ||\n \t    !(timestamp = parse_timestamp(email_end + 2, &message, 10)) ||\n@@ -2108,7 +2111,7 @@ static int files_for_each_reflog_ent_reverse(struct ref_store *ref_store,\n \t\t\t\tstrbuf_splice(&sb, 0, 0, bp + 1, endp - (bp + 1));\n \t\t\t\tscanp = bp;\n \t\t\t\tendp = bp + 1;\n-\t\t\t\tret = show_one_reflog_ent(&sb, fn, cb_data);\n+\t\t\t\tret = show_one_reflog_ent(refs, &sb, fn, cb_data);\n \t\t\t\tstrbuf_reset(&sb);\n \t\t\t\tif (ret)\n \t\t\t\t\tbreak;\n@@ -2120,7 +2123,7 @@ static int files_for_each_reflog_ent_reverse(struct ref_store *ref_store,\n \t\t\t\t * Process it, and we can end the loop.\n \t\t\t\t */\n \t\t\t\tstrbuf_splice(&sb, 0, 0, buf, endp - buf);\n-\t\t\t\tret = show_one_reflog_ent(&sb, fn, cb_data);\n+\t\t\t\tret = show_one_reflog_ent(refs, &sb, fn, cb_data);\n \t\t\t\tstrbuf_reset(&sb);\n \t\t\t\tbreak;\n \t\t\t}\n@@ -2170,7 +2173,7 @@ static int files_for_each_reflog_ent(struct ref_store *ref_store,\n \t\treturn -1;\n \n \twhile (!ret && !strbuf_getwholeline(&sb, logfp, '\\n'))\n-\t\tret = show_one_reflog_ent(&sb, fn, cb_data);\n+\t\tret = show_one_reflog_ent(refs, &sb, fn, cb_data);\n \tfclose(logfp);\n \tstrbuf_release(&sb);\n \treturn ret;\ndiff --git a/refs/refs-internal.h b/refs/refs-internal.h\nindex fa975d69aa..309b382284 100644\n--- a/refs/refs-internal.h\n+++ b/refs/refs-internal.h\n@@ -705,7 +705,8 @@ struct ref_store {\n  * Parse contents of a loose ref file. *failure_errno maybe be set to EINVAL for\n  * invalid contents.\n  */\n-int parse_loose_ref_contents(const char *buf, struct object_id *oid,\n+int parse_loose_ref_contents(const struct git_hash_algo *algop,\n+\t\t\t     const char *buf, struct object_id *oid,\n \t\t\t     struct strbuf *referent, unsigned int *type,\n \t\t\t     int *failure_errno);\n \n-- \n2.46.0.rc1.dirty\n\n"},{"id":"499558","messageId":"cd51e9694d20e70b4c95a7ab8aee65e43c69cbe1.1722316795.git.ps@pks.im","threadId":"61864","inReplyTo":"cover.1722316795.git.ps@pks.im","subject":"[PATCH 3/5] refs/files: stop using `the_repository`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-07-30T05:22:56Z","receivedAt":"2024-07-30T05:23:00Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Convert the files ref backend to stop using `the_repository` in favor of\nthe repo that gets passed in via `struct ref_store`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n refs/files-backend.c | 8 +++-----\n 1 file changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/refs/files-backend.c b/refs/files-backend.c\nindex 3437c79699..c73f95ecf2 100644\n--- a/refs/files-backend.c\n+++ b/refs/files-backend.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"../git-compat-util.h\"\n #include \"../copy.h\"\n #include \"../environment.h\"\n@@ -248,7 +246,7 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs,\n \n \tif (!refs_resolve_ref_unsafe(&refs->base, refname, RESOLVE_REF_READING,\n \t\t\t\t     &oid, &flag)) {\n-\t\toidclr(&oid, the_repository->hash_algo);\n+\t\toidclr(&oid, refs->base.repo->hash_algo);\n \t\tflag |= REF_ISBROKEN;\n \t} else if (is_null_oid(&oid)) {\n \t\t/*\n@@ -265,7 +263,7 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs,\n \tif (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {\n \t\tif (!refname_is_safe(refname))\n \t\t\tdie(\"loose refname is dangerous: %s\", refname);\n-\t\toidclr(&oid, the_repository->hash_algo);\n+\t\toidclr(&oid, refs->base.repo->hash_algo);\n \t\tflag |= REF_BAD_NAME | REF_ISBROKEN;\n \t}\n \tadd_entry_to_dir(dir, create_ref_entry(refname, &oid, flag));\n@@ -1154,7 +1152,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,\n \n \tif (!refs_resolve_ref_unsafe(&refs->base, lock->ref_name, 0,\n \t\t\t\t     &lock->old_oid, NULL))\n-\t\toidclr(&lock->old_oid, the_repository->hash_algo);\n+\t\toidclr(&lock->old_oid, refs->base.repo->hash_algo);\n \tgoto out;\n \n  error_return:\n-- \n2.46.0.rc1.dirty\n\n"},{"id":"499559","messageId":"d164cd3aa12b67ba98c9b878543497482441ba2c.1722316795.git.ps@pks.im","threadId":"61864","inReplyTo":"cover.1722316795.git.ps@pks.im","subject":"[PATCH 4/5] refs/packed: stop using `the_repository`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-07-30T05:23:01Z","receivedAt":"2024-07-30T05:23:05Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Convert the packed ref backend to stop using `the_repository` in favor\nof the repo that gets passed in via `struct ref_store`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n refs/packed-backend.c | 14 ++++++--------\n 1 file changed, 6 insertions(+), 8 deletions(-)\n\ndiff --git a/refs/packed-backend.c b/refs/packed-backend.c\nindex a0666407cd..89976aa359 100644\n--- a/refs/packed-backend.c\n+++ b/refs/packed-backend.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"../git-compat-util.h\"\n #include \"../config.h\"\n #include \"../dir.h\"\n@@ -794,7 +792,7 @@ static int packed_read_raw_ref(struct ref_store *ref_store, const char *refname,\n \t\treturn -1;\n \t}\n \n-\tif (get_oid_hex(rec, oid))\n+\tif (get_oid_hex_algop(rec, oid, ref_store->repo->hash_algo))\n \t\tdie_invalid_line(refs->path, rec, snapshot->eof - rec);\n \n \t*type = REF_ISPACKED;\n@@ -879,7 +877,7 @@ static int next_record(struct packed_ref_iterator *iter)\n \tp = iter->pos;\n \n \tif (iter->eof - p < snapshot_hexsz(iter->snapshot) + 2 ||\n-\t    parse_oid_hex(p, &iter->oid, &p) ||\n+\t    parse_oid_hex_algop(p, &iter->oid, &p, iter->repo->hash_algo) ||\n \t    !isspace(*p++))\n \t\tdie_invalid_line(iter->snapshot->refs->path,\n \t\t\t\t iter->pos, iter->eof - iter->pos);\n@@ -896,7 +894,7 @@ static int next_record(struct packed_ref_iterator *iter)\n \t\tif (!refname_is_safe(iter->base.refname))\n \t\t\tdie(\"packed refname is dangerous: %s\",\n \t\t\t    iter->base.refname);\n-\t\toidclr(&iter->oid, the_repository->hash_algo);\n+\t\toidclr(&iter->oid, iter->repo->hash_algo);\n \t\titer->base.flags |= REF_BAD_NAME | REF_ISBROKEN;\n \t}\n \tif (iter->snapshot->peeled == PEELED_FULLY ||\n@@ -909,7 +907,7 @@ static int next_record(struct packed_ref_iterator *iter)\n \tif (iter->pos < iter->eof && *iter->pos == '^') {\n \t\tp = iter->pos + 1;\n \t\tif (iter->eof - p < snapshot_hexsz(iter->snapshot) + 1 ||\n-\t\t    parse_oid_hex(p, &iter->peeled, &p) ||\n+\t\t    parse_oid_hex_algop(p, &iter->peeled, &p, iter->repo->hash_algo) ||\n \t\t    *p++ != '\\n')\n \t\t\tdie_invalid_line(iter->snapshot->refs->path,\n \t\t\t\t\t iter->pos, iter->eof - iter->pos);\n@@ -921,13 +919,13 @@ static int next_record(struct packed_ref_iterator *iter)\n \t\t * we suppress it if the reference is broken:\n \t\t */\n \t\tif ((iter->base.flags & REF_ISBROKEN)) {\n-\t\t\toidclr(&iter->peeled, the_repository->hash_algo);\n+\t\t\toidclr(&iter->peeled, iter->repo->hash_algo);\n \t\t\titer->base.flags &= ~REF_KNOWS_PEELED;\n \t\t} else {\n \t\t\titer->base.flags |= REF_KNOWS_PEELED;\n \t\t}\n \t} else {\n-\t\toidclr(&iter->peeled, the_repository->hash_algo);\n+\t\toidclr(&iter->peeled, iter->repo->hash_algo);\n \t}\n \n \treturn ITER_OK;\n-- \n2.46.0.rc1.dirty\n\n"},{"id":"499560","messageId":"0e440360a83a02afd2d247a5ae9d2a250ff6a10b.1722316795.git.ps@pks.im","threadId":"61864","inReplyTo":"cover.1722316795.git.ps@pks.im","subject":"[PATCH 5/5] refs/reftable: stop using `the_repository`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-07-30T05:23:05Z","receivedAt":"2024-07-30T05:23:09Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Convert the reftable ref backend to stop using `the_repository` in favor\nof the repo that gets passed in via `struct ref_store`.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n refs/reftable-backend.c | 51 +++++++++++++++++++++--------------------\n 1 file changed, 26 insertions(+), 25 deletions(-)\n\ndiff --git a/refs/reftable-backend.c b/refs/reftable-backend.c\nindex fbe74c239d..bf4446afd3 100644\n--- a/refs/reftable-backend.c\n+++ b/refs/reftable-backend.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"../git-compat-util.h\"\n #include \"../abspath.h\"\n #include \"../chdir-notify.h\"\n@@ -201,7 +199,8 @@ static void fill_reftable_log_record(struct reftable_log_record *log, const stru\n \tlog->value.update.tz_offset = sign * atoi(tz_begin);\n }\n \n-static int read_ref_without_reload(struct reftable_stack *stack,\n+static int read_ref_without_reload(struct reftable_ref_store *refs,\n+\t\t\t\t   struct reftable_stack *stack,\n \t\t\t\t   const char *refname,\n \t\t\t\t   struct object_id *oid,\n \t\t\t\t   struct strbuf *referent,\n@@ -220,7 +219,7 @@ static int read_ref_without_reload(struct reftable_stack *stack,\n \t\t*type |= REF_ISSYMREF;\n \t} else if (reftable_ref_record_val1(&ref)) {\n \t\toidread(oid, reftable_ref_record_val1(&ref),\n-\t\t\tthe_repository->hash_algo);\n+\t\t\trefs->base.repo->hash_algo);\n \t} else {\n \t\t/* We got a tombstone, which should not happen. */\n \t\tBUG(\"unhandled reference value type %d\", ref.value_type);\n@@ -487,16 +486,16 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator)\n \t\tswitch (iter->ref.value_type) {\n \t\tcase REFTABLE_REF_VAL1:\n \t\t\toidread(&iter->oid, iter->ref.value.val1,\n-\t\t\t\tthe_repository->hash_algo);\n+\t\t\t\trefs->base.repo->hash_algo);\n \t\t\tbreak;\n \t\tcase REFTABLE_REF_VAL2:\n \t\t\toidread(&iter->oid, iter->ref.value.val2.value,\n-\t\t\t\tthe_repository->hash_algo);\n+\t\t\t\trefs->base.repo->hash_algo);\n \t\t\tbreak;\n \t\tcase REFTABLE_REF_SYMREF:\n \t\t\tif (!refs_resolve_ref_unsafe(&iter->refs->base, iter->ref.refname,\n \t\t\t\t\t\t     RESOLVE_REF_READING, &iter->oid, &flags))\n-\t\t\t\toidclr(&iter->oid, the_repository->hash_algo);\n+\t\t\t\toidclr(&iter->oid, refs->base.repo->hash_algo);\n \t\t\tbreak;\n \t\tdefault:\n \t\t\tBUG(\"unhandled reference value type %d\", iter->ref.value_type);\n@@ -508,7 +507,7 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator)\n \t\tif (check_refname_format(iter->ref.refname, REFNAME_ALLOW_ONELEVEL)) {\n \t\t\tif (!refname_is_safe(iter->ref.refname))\n \t\t\t\tdie(_(\"refname is dangerous: %s\"), iter->ref.refname);\n-\t\t\toidclr(&iter->oid, the_repository->hash_algo);\n+\t\t\toidclr(&iter->oid, refs->base.repo->hash_algo);\n \t\t\tflags |= REF_BAD_NAME | REF_ISBROKEN;\n \t\t}\n \n@@ -551,7 +550,7 @@ static int reftable_ref_iterator_peel(struct ref_iterator *ref_iterator,\n \n \tif (iter->ref.value_type == REFTABLE_REF_VAL2) {\n \t\toidread(peeled, iter->ref.value.val2.target_value,\n-\t\t\tthe_repository->hash_algo);\n+\t\t\titer->refs->base.repo->hash_algo);\n \t\treturn 0;\n \t}\n \n@@ -659,7 +658,7 @@ static int reftable_be_read_raw_ref(struct ref_store *ref_store,\n \tif (ret)\n \t\treturn ret;\n \n-\tret = read_ref_without_reload(stack, refname, oid, referent, type);\n+\tret = read_ref_without_reload(refs, stack, refname, oid, referent, type);\n \tif (ret < 0)\n \t\treturn ret;\n \tif (ret > 0) {\n@@ -868,8 +867,8 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,\n \t\tgoto done;\n \t}\n \n-\tret = read_ref_without_reload(stack_for(refs, \"HEAD\", NULL), \"HEAD\", &head_oid,\n-\t\t\t\t      &head_referent, &head_type);\n+\tret = read_ref_without_reload(refs, stack_for(refs, \"HEAD\", NULL), \"HEAD\",\n+\t\t\t\t      &head_oid, &head_referent, &head_type);\n \tif (ret < 0)\n \t\tgoto done;\n \tret = 0;\n@@ -936,7 +935,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,\n \t\t\tstring_list_insert(&affected_refnames, new_update->refname);\n \t\t}\n \n-\t\tret = read_ref_without_reload(stack, rewritten_ref,\n+\t\tret = read_ref_without_reload(refs, stack, rewritten_ref,\n \t\t\t\t\t      &current_oid, &referent, &u->type);\n \t\tif (ret < 0)\n \t\t\tgoto done;\n@@ -1500,7 +1499,8 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data)\n \t\tmemcpy(logs[logs_nr].value.update.old_hash, old_ref.value.val1, GIT_MAX_RAWSZ);\n \t\tlogs_nr++;\n \n-\t\tret = read_ref_without_reload(arg->stack, \"HEAD\", &head_oid, &head_referent, &head_type);\n+\t\tret = read_ref_without_reload(arg->refs, arg->stack, \"HEAD\", &head_oid,\n+\t\t\t\t\t      &head_referent, &head_type);\n \t\tif (ret < 0)\n \t\t\tgoto done;\n \t\tappend_head_reflog = (head_type & REF_ISSYMREF) && !strcmp(head_referent.buf, arg->oldname);\n@@ -1790,15 +1790,16 @@ static struct ref_iterator *reftable_be_reflog_iterator_begin(struct ref_store *\n \t\t\t\t\tref_iterator_select, NULL);\n }\n \n-static int yield_log_record(struct reftable_log_record *log,\n+static int yield_log_record(struct reftable_ref_store *refs,\n+\t\t\t    struct reftable_log_record *log,\n \t\t\t    each_reflog_ent_fn fn,\n \t\t\t    void *cb_data)\n {\n \tstruct object_id old_oid, new_oid;\n \tconst char *full_committer;\n \n-\toidread(&old_oid, log->value.update.old_hash, the_repository->hash_algo);\n-\toidread(&new_oid, log->value.update.new_hash, the_repository->hash_algo);\n+\toidread(&old_oid, log->value.update.old_hash, refs->base.repo->hash_algo);\n+\toidread(&new_oid, log->value.update.new_hash, refs->base.repo->hash_algo);\n \n \t/*\n \t * When both the old object ID and the new object ID are null\n@@ -1841,7 +1842,7 @@ static int reftable_be_for_each_reflog_ent_reverse(struct ref_store *ref_store,\n \t\t\tbreak;\n \t\t}\n \n-\t\tret = yield_log_record(&log, fn, cb_data);\n+\t\tret = yield_log_record(refs, &log, fn, cb_data);\n \t\tif (ret)\n \t\t\tbreak;\n \t}\n@@ -1886,7 +1887,7 @@ static int reftable_be_for_each_reflog_ent(struct ref_store *ref_store,\n \t}\n \n \tfor (i = logs_nr; i--;) {\n-\t\tret = yield_log_record(&logs[i], fn, cb_data);\n+\t\tret = yield_log_record(refs, &logs[i], fn, cb_data);\n \t\tif (ret)\n \t\t\tgoto done;\n \t}\n@@ -2200,7 +2201,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,\n \t\tgoto done;\n \tif (reftable_ref_record_val1(&ref_record))\n \t\toidread(&oid, reftable_ref_record_val1(&ref_record),\n-\t\t\tthe_repository->hash_algo);\n+\t\t\tref_store->repo->hash_algo);\n \tprepare_fn(refname, &oid, policy_cb_data);\n \n \twhile (1) {\n@@ -2216,9 +2217,9 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,\n \t\t}\n \n \t\toidread(&old_oid, log.value.update.old_hash,\n-\t\t\tthe_repository->hash_algo);\n+\t\t\tref_store->repo->hash_algo);\n \t\toidread(&new_oid, log.value.update.new_hash,\n-\t\t\tthe_repository->hash_algo);\n+\t\t\tref_store->repo->hash_algo);\n \n \t\t/*\n \t\t * Skip over the reflog existence marker. We will add it back\n@@ -2250,9 +2251,9 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,\n \n \t\t*dest = logs[i];\n \t\toidread(&old_oid, logs[i].value.update.old_hash,\n-\t\t\tthe_repository->hash_algo);\n+\t\t\tref_store->repo->hash_algo);\n \t\toidread(&new_oid, logs[i].value.update.new_hash,\n-\t\t\tthe_repository->hash_algo);\n+\t\t\tref_store->repo->hash_algo);\n \n \t\tif (should_prune_fn(&old_oid, &new_oid, logs[i].value.update.email,\n \t\t\t\t    (timestamp_t)logs[i].value.update.time,\n@@ -2269,7 +2270,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,\n \n \tif (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash &&\n \t    reftable_ref_record_val1(&ref_record))\n-\t\toidread(&arg.update_oid, last_hash, the_repository->hash_algo);\n+\t\toidread(&arg.update_oid, last_hash, ref_store->repo->hash_algo);\n \n \targ.refs = refs;\n \targ.records = rewritten;\n-- \n2.46.0.rc1.dirty\n\n"},{"id":"499595","messageId":"CAOLa=ZQqh7x9xaZXenRoMM8+fE+c5jOG73J5hPg-q=b_s+vxXQ@mail.gmail.com","threadId":"61864","inReplyTo":"d164cd3aa12b67ba98c9b878543497482441ba2c.1722316795.git.ps@pks.im","subject":"Re: [PATCH 4/5] refs/packed: stop using `the_repository`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-07-30T11:23:55Z","receivedAt":"2024-07-30T11:23:57Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> Convert the packed ref backend to stop using `the_repository` in favor\n> of the repo that gets passed in via `struct ref_store`.\n>\n\nNit: Might be nice to add that we move to using `get_oid_hex_algop` in\nthis commit. Since it was also mentioned in a prev commit\n\n[snip]\n"},{"id":"499596","messageId":"CAOLa=ZR+2FV-pdk2nZ1vR5dUx3G2Ze8=18CUCn8r_JUXfvR6fQ@mail.gmail.com","threadId":"61864","inReplyTo":"cover.1722316795.git.ps@pks.im","subject":"Re: [PATCH 0/5] refs: stop using `the_repository`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-07-30T11:26:50Z","receivedAt":"2024-07-30T11:26:52Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> Hi,\n>\n> this patch series removes use of `the_repository` in the refs subsystem\n> and drops the `USE_THE_REPOSITORY_VARIABLE` macro define from those\n> files.\n>\n\nSo the idea is to slowly cleanup usages of `the_repository` and the\n`USE_THE_REPOSITORY_VARIABLE` macro acts as a check for this. I think\nthe changes look great. I even ran clang-format on this series and apart\nfrom line wrap suggestions, there were no issues.\n\nThanks for this.\n\n[snip]\n"},{"id":"499658","messageId":"D33BCEL5LQQ0.33TQBJ9KVBMBX@jamesliu.io","threadId":"61864","inReplyTo":"cover.1722316795.git.ps@pks.im","subject":"Re: [PATCH 0/5] refs: stop using `the_repository`","fromName":"James Liu","fromEmail":"james@jamesliu.io","sentAt":"2024-07-31T00:55:09Z","receivedAt":"2024-07-31T00:55:14Z","isPatch":true,"sender":{"key":"james@jamesliu.io","avatar":"https://avatars.githubusercontent.com/u/4476568?v=4"},"body":"On Tue Jul 30, 2024 at 3:22 PM AEST, Patrick Steinhardt wrote:\n> Hi,\n>\n> this patch series removes use of `the_repository` in the refs subsystem\n> and drops the `USE_THE_REPOSITORY_VARIABLE` macro define from those\n> files.\n>\n> Patrick\n\nThanks Patrick, these improvements make sense to me.\n\nIs there a priority order on removing `the_repository` from other parts\nof the codebase?\n\nCheers,\nJames\n\n"},{"id":"499662","messageId":"ZqnEuz9uFgUwWKkc@tanuki","threadId":"61864","inReplyTo":"CAOLa=ZQqh7x9xaZXenRoMM8+fE+c5jOG73J5hPg-q=b_s+vxXQ@mail.gmail.com","subject":"Re: [PATCH 4/5] refs/packed: stop using `the_repository`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-07-31T04:59:39Z","receivedAt":"2024-07-31T04:59:44Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Tue, Jul 30, 2024 at 07:23:55AM -0400, Karthik Nayak wrote:\n> Patrick Steinhardt <ps@pks.im> writes:\n> \n> > Convert the packed ref backend to stop using `the_repository` in favor\n> > of the repo that gets passed in via `struct ref_store`.\n> >\n> \n> Nit: Might be nice to add that we move to using `get_oid_hex_algop` in\n> this commit. Since it was also mentioned in a prev commit\n\nYeah, that'd make sense indeed. I'll refrain from sending out a new\nversion of this patch series just to amend the commit message, but have\nqueued the change locally and will send it out in case any other changes\nare required for this patch series.\n\nThanks!\n\nPatrick\n"},{"id":"499663","messageId":"ZqnFKFoaodui2C-P@tanuki","threadId":"61864","inReplyTo":"CAOLa=ZR+2FV-pdk2nZ1vR5dUx3G2Ze8=18CUCn8r_JUXfvR6fQ@mail.gmail.com","subject":"Re: [PATCH 0/5] refs: stop using `the_repository`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-07-31T05:01:28Z","receivedAt":"2024-07-31T05:01:33Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Tue, Jul 30, 2024 at 07:26:50AM -0400, Karthik Nayak wrote:\n> Patrick Steinhardt <ps@pks.im> writes:\n> \n> > Hi,\n> >\n> > this patch series removes use of `the_repository` in the refs subsystem\n> > and drops the `USE_THE_REPOSITORY_VARIABLE` macro define from those\n> > files.\n> >\n> \n> So the idea is to slowly cleanup usages of `the_repository` and the\n> `USE_THE_REPOSITORY_VARIABLE` macro acts as a check for this. I think\n> the changes look great. I even ran clang-format on this series and apart\n> from line wrap suggestions, there were no issues.\n\nExactly. One intent is to demonstrate to reviewers that a file actually\ngot rid of `the_repository`. The second intent is to hide away APIs that\nhave an implicit dependency on `the_repository`, which would be easy to\nmiss otherwise.\n\nThe second part is not perfect because we only hide away a subset of\ninterfaces. That part can be extended over time as required though.\n\nPatrick\n"},{"id":"499664","messageId":"ZqnGPeaqsXd4GTGb@tanuki","threadId":"61864","inReplyTo":"D33BCEL5LQQ0.33TQBJ9KVBMBX@jamesliu.io","subject":"Re: [PATCH 0/5] refs: stop using `the_repository`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-07-31T05:06:05Z","receivedAt":"2024-07-31T05:06:10Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Wed, Jul 31, 2024 at 10:55:09AM +1000, James Liu wrote:\n> On Tue Jul 30, 2024 at 3:22 PM AEST, Patrick Steinhardt wrote:\n> > Hi,\n> >\n> > this patch series removes use of `the_repository` in the refs subsystem\n> > and drops the `USE_THE_REPOSITORY_VARIABLE` macro define from those\n> > files.\n> >\n> > Patrick\n> \n> Thanks Patrick, these improvements make sense to me.\n> \n> Is there a priority order on removing `the_repository` from other parts\n> of the codebase?\n\nI was tackling the refs API because I knew that it was a \"leaf\" package\nthat doesn't have a ton of dependencies on subsystems that may be using\n`the_repository` itself. So I guess that the order that makes most sense\nis from leaf subsystems up to the root such that we can adjust layer by\nlayer.\n\nFiguring out what those leaf subsystems are is a different story though.\nI typically tend to brute force it, see how far I get and if I succeed\nthen I don't mention all the failed tries that led to the patch series\n;) Over time you then get some intuition for which parts to handle next,\neven though I realize that this is not particularly useful as advice to\nsomebody not that familiar with the codebase.\n\nPatrick\n"}]}