{"thread":{"id":"62424","subject":"[PATCH v3 1/9] packfile: add repository to struct `packed_git`","startedAt":"2024-10-30T14:32:39Z","lastAt":"2024-10-31T09:34:35Z","messageCount":13,"participants":["Karthik Nayak","Taylor Blau","karthik nayak"],"isPatch":true,"patchVersion":3,"patchTotal":9},"messages":[{"id":"506321","messageId":"cover.1730297934.git.karthik.188@gmail.com","threadId":"62424","inReplyTo":"cover.1729504640.git.karthik.188@gmail.com","subject":"[PATCH v3 0/9] packfile: avoid using the 'the_repository' global variable","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-10-30T14:32:25Z","receivedAt":"2024-10-30T14:32:39Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The `packfile.c` file uses the global variable 'the_repository' extensively\nthroughout the code. Let's remove all usecases of this, by modifying the\nrequired functions to accept a 'struct repository' instead. This is to clean up\nusage of global state.\n\nThe first 3 patches are mostly internal to `packfile.c`, we add the repository\nfield to the `packed_git` struct and this is used to clear up some useages of\nthe global variables.\n\nThe next 3 patches are more disruptive, they modify the function definition of\n`odb_pack_name`, `has_object[_kept]_pack` and `for_each_packed_object` to receive\na repository, helping remove other usages of 'the_repository' variable.\n\nFinally, the last two patches deal with global config values. These values are\nlocalized.\n\nThis series is based off on master: 6a11438f43 (The fifth batch, 2024-10-25),\nwith 'jk/dumb-http-finalize' merged in. I found no issues merging this with seen,\nbut since these patches cover a lot of files, there might be some conflicts.\n\nChanges in v3:\n- Improved commit messages. In the first commit to talk about how packed_git\nstruct could also be part of the alternates of a repository. In the 7th commit\nto talk about the motive behind removing the global variable.\n- Changed 'packed_git->repo' to 'packed_git->r' to keep it consistent with the\nrest of the code base.\n- Replaced 'the_repository' with locally available access to the repository\nstruct in multiple regions.\n- Removed unecessary inclusion of the 'repository.h' header file by forward\ndeclaring the 'repository' struct.\n- Replace memcpy with hashcpy.\n- Change the logic in the 7th patch to use if else statements.\n- Added an extra commit to cleanup `pack-bitmap.c`. \n\nKarthik Nayak (9):\n  packfile: add repository to struct `packed_git`\n  packfile: use `repository` from `packed_git` directly\n  packfile: pass `repository` to static function in the file\n  packfile: pass down repository to `odb_pack_name`\n  packfile: pass down repository to `has_object[_kept]_pack`\n  packfile: pass down repository to `for_each_packed_object`\n  config: make `delta_base_cache_limit` a non-global variable\n  config: make `packed_git_(limit|window_size)` non-global variables\n  midx: add repository to `multi_pack_index` struct\n\n builtin/cat-file.c       |   7 +-\n builtin/count-objects.c  |   2 +-\n builtin/fast-import.c    |  15 ++--\n builtin/fsck.c           |  20 +++--\n builtin/gc.c             |   5 +-\n builtin/index-pack.c     |  20 +++--\n builtin/pack-objects.c   |  11 ++-\n builtin/pack-redundant.c |   2 +-\n builtin/repack.c         |   2 +-\n builtin/rev-list.c       |   2 +-\n commit-graph.c           |   4 +-\n config.c                 |  22 -----\n connected.c              |   3 +-\n diff.c                   |   3 +-\n environment.c            |   3 -\n environment.h            |   1 -\n fsck.c                   |   2 +-\n http.c                   |   4 +-\n list-objects.c           |   7 +-\n midx-write.c             |   2 +-\n midx.c                   |   3 +-\n midx.h                   |   3 +\n object-store-ll.h        |   9 +-\n pack-bitmap.c            |  97 +++++++++++++--------\n pack-objects.h           |   3 +-\n pack-write.c             |   1 +\n pack.h                   |   1 +\n packfile.c               | 182 ++++++++++++++++++++++++++-------------\n packfile.h               |  18 ++--\n promisor-remote.c        |   2 +-\n prune-packed.c           |   2 +-\n reachable.c              |   4 +-\n revision.c               |  13 +--\n tag.c                    |   2 +-\n 34 files changed, 285 insertions(+), 192 deletions(-)\n\nRange-diff against v2:\n 1:  26d2461cc3 !  1:  5afb9af0af packfile: add repository to struct `packed_git`\n    @@ Commit message\n         on the global `the_repository` object in `packfile.c` by simply using\n         repository information now readily available in the struct.\n     \n    +    We do need to consider that a pack file could be part of the alternates\n    +    of a repository, but considering that we only have one repository struct\n    +    and also that we currently anyways use 'the_repository'. We should be\n    +    OK with this change.\n    +\n         We also modify `alloc_packed_git` to ensure that the repository is added\n         to newly created `packed_git` structs. This requires modifying the\n         function and all its callee to pass the repository object down the\n         levels.\n     \n    +    Helped-by: Taylor Blau <me@ttaylorr.com>\n         Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n     \n      ## builtin/fast-import.c ##\n    @@ builtin/fast-import.c: static void start_packfile(void)\n      \n      \tp->pack_fd = pack_fd;\n      \tp->do_not_close = 1;\n    -+\tp->repo = the_repository;\n    ++\tp->r = the_repository;\n      \tpack_file = hashfd(pack_fd, p->pack_name);\n      \n      \tpack_data = p;\n    @@ builtin/fast-import.c: static void end_packfile(void)\n      \n      \t\t/* Register the packfile with core git's machinery. */\n     -\t\tnew_p = add_packed_git(idx_name, strlen(idx_name), 1);\n    -+\t\tnew_p = add_packed_git(the_repository, idx_name, strlen(idx_name), 1);\n    ++\t\tnew_p = add_packed_git(pack_data->r, idx_name, strlen(idx_name), 1);\n      \t\tif (!new_p)\n      \t\t\tdie(\"core git rejected index %s\", idx_name);\n      \t\tall_packs[pack_id] = new_p;\n    @@ midx.c: int prepare_midx_pack(struct repository *r, struct multi_pack_index *m,\n     \n      ## object-store-ll.h ##\n     @@\n    - #include \"hashmap.h\"\n    - #include \"object.h\"\n    - #include \"list.h\"\n    -+#include \"repository.h\"\n    - #include \"thread-utils.h\"\n    - #include \"oidset.h\"\n    + struct oidmap;\n    + struct oidtree;\n    + struct strbuf;\n    ++struct repository;\n      \n    + struct object_directory {\n    + \tstruct object_directory *next;\n     @@ object-store-ll.h: struct packed_git {\n      \t */\n      \tconst uint32_t *mtimes_map;\n      \tsize_t mtimes_size;\n     +\n     +\t/* repo dentoes the repository this packed file belongs to */\n    -+\tstruct repository *repo;\n    ++\tstruct repository *r;\n     +\n      \t/* something like \".git/objects/pack/xxxxx.pack\" */\n      \tchar pack_name[FLEX_ARRAY]; /* more */\n    @@ packfile.c: uint32_t get_pack_fanout(struct packed_git *p, uint32_t value)\n      }\n      \n     -static struct packed_git *alloc_packed_git(int extra)\n    -+static struct packed_git *alloc_packed_git(struct repository *repo, int extra)\n    ++static struct packed_git *alloc_packed_git(struct repository *r, int extra)\n      {\n      \tstruct packed_git *p = xmalloc(st_add(sizeof(*p), extra));\n      \tmemset(p, 0, sizeof(*p));\n      \tp->pack_fd = -1;\n    -+\tp->repo = repo;\n    ++\tp->r = r;\n      \treturn p;\n      }\n      \n    @@ packfile.c: static char *pack_path_from_idx(const char *idx_path)\n      }\n      \n     -struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path)\n    -+struct packed_git *parse_pack_index(struct repository *repo,\n    -+\t\t\t\t    unsigned char *sha1, const char *idx_path)\n    ++struct packed_git *parse_pack_index(struct repository *r, unsigned char *sha1,\n    ++\t\t\t\t    const char *idx_path)\n      {\n      \tchar *path = pack_path_from_idx(idx_path);\n      \tsize_t alloc = st_add(strlen(path), 1);\n     -\tstruct packed_git *p = alloc_packed_git(alloc);\n    -+\tstruct packed_git *p = alloc_packed_git(repo, alloc);\n    ++\tstruct packed_git *p = alloc_packed_git(r, alloc);\n      \n      \tmemcpy(p->pack_name, path, alloc); /* includes NUL */\n      \tfree(path);\n    @@ packfile.c: void unuse_pack(struct pack_window **w_cursor)\n      }\n      \n     -struct packed_git *add_packed_git(const char *path, size_t path_len, int local)\n    -+struct packed_git *add_packed_git(struct repository *repo, const char *path,\n    ++struct packed_git *add_packed_git(struct repository *r, const char *path,\n     +\t\t\t\t  size_t path_len, int local)\n      {\n      \tstruct stat st;\n    @@ packfile.c: struct packed_git *add_packed_git(const char *path, size_t path_len,\n      \t */\n      \talloc = st_add3(path_len, strlen(\".promisor\"), 1);\n     -\tp = alloc_packed_git(alloc);\n    -+\tp = alloc_packed_git(repo, alloc);\n    ++\tp = alloc_packed_git(r, alloc);\n      \tmemcpy(p->pack_name, path, path_len);\n      \n      \txsnprintf(p->pack_name + path_len, alloc - path_len, \".keep\");\n    @@ packfile.h: const char *pack_basename(struct packed_git *p);\n       * packs. You probably want add_packed_git() instead.\n       */\n     -struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path);\n    -+struct packed_git *parse_pack_index(struct repository *repo,\n    -+\t\t\t\t    unsigned char *sha1, const char *idx_path);\n    ++struct packed_git *parse_pack_index(struct repository *r, unsigned char *sha1,\n    ++\t\t\t\t    const char *idx_path);\n      \n      typedef void each_file_in_pack_dir_fn(const char *full_path, size_t full_path_len,\n      \t\t\t\t      const char *file_name, void *data);\n    @@ packfile.h: void close_pack(struct packed_git *);\n      void unuse_pack(struct pack_window **);\n      void clear_delta_base_cache(void);\n     -struct packed_git *add_packed_git(const char *path, size_t path_len, int local);\n    -+struct packed_git *add_packed_git(struct repository *repo, const char *path,\n    ++struct packed_git *add_packed_git(struct repository *r, const char *path,\n     +\t\t\t\t  size_t path_len, int local);\n      \n      /*\n 2:  ca03355686 !  2:  5350b4f9fb packfile: use `repository` from `packed_git` directly\n    @@ Commit message\n         where there is no struct `packed_git` locally available, which will be\n         fixed in the following commits.\n     \n    +    Helped-by: Taylor Blau <me@ttaylorr.com>\n         Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n     \n      ## packfile.c ##\n    @@ packfile.c: static int check_packed_git_idx(const char *path, struct packed_git\n      \tint fd = git_open(path), ret;\n      \tstruct stat st;\n     -\tconst unsigned int hashsz = the_hash_algo->rawsz;\n    -+\tconst unsigned int hashsz = p->repo->hash_algo->rawsz;\n    ++\tconst unsigned int hashsz = p->r->hash_algo->rawsz;\n      \n      \tif (fd < 0)\n      \t\treturn -1;\n    -@@ packfile.c: struct packed_git *parse_pack_index(struct repository *repo,\n    +@@ packfile.c: struct packed_git *parse_pack_index(struct repository *r, unsigned char *sha1,\n      \n      \tmemcpy(p->pack_name, path, alloc); /* includes NUL */\n      \tfree(path);\n     -\thashcpy(p->hash, sha1, the_repository->hash_algo);\n    -+\thashcpy(p->hash, sha1, p->repo->hash_algo);\n    ++\thashcpy(p->hash, sha1, p->r->hash_algo);\n      \tif (check_packed_git_idx(idx_path, p)) {\n      \t\tfree(p);\n      \t\treturn NULL;\n    @@ packfile.c: static int unuse_one_window(struct packed_git *current)\n      \tif (current)\n      \t\tscan_windows(current, &lru_p, &lru_w, &lru_l);\n     -\tfor (p = the_repository->objects->packed_git; p; p = p->next)\n    -+\tfor (p = current->repo->objects->packed_git; p; p = p->next)\n    ++\tfor (p = current->r->objects->packed_git; p; p = p->next)\n      \t\tscan_windows(p, &lru_p, &lru_w, &lru_l);\n      \tif (lru_p) {\n      \t\tmunmap(lru_w->base, lru_w->len);\n    @@ packfile.c: static int open_packed_git_1(struct packed_git *p)\n      \tunsigned char *idx_hash;\n      \tssize_t read_result;\n     -\tconst unsigned hashsz = the_hash_algo->rawsz;\n    -+\tconst unsigned hashsz = p->repo->hash_algo->rawsz;\n    ++\tconst unsigned hashsz = p->r->hash_algo->rawsz;\n      \n      \tif (open_pack_index(p))\n      \t\treturn error(\"packfile %s index unavailable\", p->pack_name);\n    @@ packfile.c: static int open_packed_git_1(struct packed_git *p)\n      \t\treturn error(\"packfile %s signature is unavailable\", p->pack_name);\n      \tidx_hash = ((unsigned char *)p->index_data) + p->index_size - hashsz * 2;\n     -\tif (!hasheq(hash, idx_hash, the_repository->hash_algo))\n    -+\tif (!hasheq(hash, idx_hash, p->repo->hash_algo))\n    ++\tif (!hasheq(hash, idx_hash, p->r->hash_algo))\n      \t\treturn error(\"packfile %s does not match index\", p->pack_name);\n      \treturn 0;\n      }\n    @@ packfile.c: unsigned char *use_pack(struct packed_git *p,\n      \tif (!p->pack_size && p->pack_fd == -1 && open_packed_git(p))\n      \t\tdie(\"packfile %s cannot be accessed\", p->pack_name);\n     -\tif (offset > (p->pack_size - the_hash_algo->rawsz))\n    -+\tif (offset > (p->pack_size - p->repo->hash_algo->rawsz))\n    ++\tif (offset > (p->pack_size - p->r->hash_algo->rawsz))\n      \t\tdie(\"offset beyond end of packfile (truncated pack?)\");\n      \tif (offset < 0)\n      \t\tdie(_(\"offset before end of packfile (broken .idx?)\"));\n    -@@ packfile.c: struct packed_git *add_packed_git(struct repository *repo, const char *path,\n    +@@ packfile.c: struct packed_git *add_packed_git(struct repository *r, const char *path,\n      \tstruct stat st;\n      \tsize_t alloc;\n      \tstruct packed_git *p;\n    @@ packfile.c: struct packed_git *add_packed_git(struct repository *repo, const cha\n      \n      \t/*\n      \t * Make sure a corresponding .pack file exists and that\n    -@@ packfile.c: struct packed_git *add_packed_git(struct repository *repo, const char *path,\n    +@@ packfile.c: struct packed_git *add_packed_git(struct repository *r, const char *path,\n      \tp->pack_size = st.st_size;\n      \tp->pack_local = local;\n      \tp->mtime = st.st_mtime;\n     -\tif (path_len < the_hash_algo->hexsz ||\n     -\t    get_hash_hex(path + path_len - the_hash_algo->hexsz, p->hash))\n     -\t\thashclr(p->hash, the_repository->hash_algo);\n    -+\tif (path_len < repo->hash_algo->hexsz ||\n    -+\t    get_oid_hex_algop(path + path_len - repo->hash_algo->hexsz, &oid,\n    -+\t\t\t      repo->hash_algo))\n    -+\t\thashclr(p->hash, repo->hash_algo);\n    ++\tif (path_len < r->hash_algo->hexsz ||\n    ++\t    get_oid_hex_algop(path + path_len - r->hash_algo->hexsz, &oid,\n    ++\t\t\t      r->hash_algo))\n    ++\t\thashclr(p->hash, r->hash_algo);\n     +\telse\n    -+\t\tmemcpy(p->hash, oid.hash, repo->hash_algo->rawsz);\n    ++\t\thashcpy(p->hash, oid.hash, r->hash_algo);\n     +\n      \treturn p;\n      }\n    @@ packfile.c: off_t get_delta_base(struct packed_git *p,\n      \t\t/* The base entry _must_ be in the same pack */\n      \t\tstruct object_id oid;\n     -\t\toidread(&oid, base_info, the_repository->hash_algo);\n    -+\t\toidread(&oid, base_info, p->repo->hash_algo);\n    ++\t\toidread(&oid, base_info, p->r->hash_algo);\n      \t\tbase_offset = find_pack_entry_one(&oid, p);\n     -\t\t*curpos += the_hash_algo->rawsz;\n    -+\t\t*curpos += p->repo->hash_algo->rawsz;\n    ++\t\t*curpos += p->r->hash_algo->rawsz;\n      \t} else\n      \t\tdie(\"I am totally screwed\");\n      \treturn base_offset;\n    @@ packfile.c: static int get_delta_base_oid(struct packed_git *p,\n      \tif (type == OBJ_REF_DELTA) {\n      \t\tunsigned char *base = use_pack(p, w_curs, curpos, NULL);\n     -\t\toidread(oid, base, the_repository->hash_algo);\n    -+\t\toidread(oid, base, p->repo->hash_algo);\n    ++\t\toidread(oid, base, p->r->hash_algo);\n      \t\treturn 0;\n      \t} else if (type == OBJ_OFS_DELTA) {\n      \t\tuint32_t base_pos;\n    @@ packfile.c: int packed_object_info(struct repository *r, struct packed_git *p,\n      \t\t\t}\n      \t\t} else\n     -\t\t\toidclr(oi->delta_base_oid, the_repository->hash_algo);\n    -+\t\t\toidclr(oi->delta_base_oid, p->repo->hash_algo);\n    ++\t\t\toidclr(oi->delta_base_oid, p->r->hash_algo);\n      \t}\n      \n      \toi->whence = in_delta_base_cache(p, obj_offset) ? OI_DBCACHED :\n    @@ packfile.c: int bsearch_pack(const struct object_id *oid, const struct packed_gi\n      \tconst unsigned char *index_fanout = p->index_data;\n      \tconst unsigned char *index_lookup;\n     -\tconst unsigned int hashsz = the_hash_algo->rawsz;\n    -+\tconst unsigned int hashsz = p->repo->hash_algo->rawsz;\n    ++\tconst unsigned int hashsz = p->r->hash_algo->rawsz;\n      \tint index_lookup_width;\n      \n      \tif (!index_fanout)\n    @@ packfile.c: int nth_packed_object_id(struct object_id *oid,\n      {\n      \tconst unsigned char *index = p->index_data;\n     -\tconst unsigned int hashsz = the_hash_algo->rawsz;\n    -+\tconst unsigned int hashsz = p->repo->hash_algo->rawsz;\n    ++\tconst unsigned int hashsz = p->r->hash_algo->rawsz;\n      \tif (!index) {\n      \t\tif (open_pack_index(p))\n      \t\t\treturn -1;\n    @@ packfile.c: int nth_packed_object_id(struct object_id *oid,\n      \tif (p->index_version == 1) {\n      \t\toidread(oid, index + st_add(st_mult(hashsz + 4, n), 4),\n     -\t\t\tthe_repository->hash_algo);\n    -+\t\t\tp->repo->hash_algo);\n    ++\t\t\tp->r->hash_algo);\n      \t} else {\n      \t\tindex += 8;\n     -\t\toidread(oid, index + st_mult(hashsz, n),\n     -\t\t\tthe_repository->hash_algo);\n    -+\t\toidread(oid, index + st_mult(hashsz, n), p->repo->hash_algo);\n    ++\t\toidread(oid, index + st_mult(hashsz, n), p->r->hash_algo);\n      \t}\n      \treturn 0;\n      }\n    @@ packfile.c: void check_pack_index_ptr(const struct packed_git *p, const void *vp\n      {\n      \tconst unsigned char *index = p->index_data;\n     -\tconst unsigned int hashsz = the_hash_algo->rawsz;\n    -+\tconst unsigned int hashsz = p->repo->hash_algo->rawsz;\n    ++\tconst unsigned int hashsz = p->r->hash_algo->rawsz;\n      \tindex += 4 * 256;\n      \tif (p->index_version == 1) {\n      \t\treturn ntohl(*((uint32_t *)(index + st_mult(hashsz + 4, n))));\n    @@ packfile.c: int for_each_object_in_pack(struct packed_git *p,\n      \n      \tif (flags & FOR_EACH_OBJECT_PACK_ORDER) {\n     -\t\tif (load_pack_revindex(the_repository, p))\n    -+\t\tif (load_pack_revindex(p->repo, p))\n    ++\t\tif (load_pack_revindex(p->r, p))\n      \t\t\treturn -1;\n      \t}\n      \n    @@ packfile.c: static int add_promisor_object(const struct object_id *oid,\n      \tint we_parsed_object;\n      \n     -\tobj = lookup_object(the_repository, oid);\n    -+\tobj = lookup_object(pack->repo, oid);\n    ++\tobj = lookup_object(pack->r, oid);\n      \tif (obj && obj->parsed) {\n      \t\twe_parsed_object = 0;\n      \t} else {\n      \t\twe_parsed_object = 1;\n     -\t\tobj = parse_object(the_repository, oid);\n    -+\t\tobj = parse_object(pack->repo, oid);\n    ++\t\tobj = parse_object(pack->r, oid);\n      \t}\n      \n      \tif (!obj)\n -:  ---------- >  3:  5b975cb6d6 packfile: pass `repository` to static function in the file\n 4:  73ba9945a7 !  4:  13a166fcca packfile: pass down repository to `odb_pack_name`\n    @@ builtin/fast-import.c: static char *keep_pack(const char *curr_index_name)\n      \tint keep_fd;\n      \n     -\todb_pack_name(&name, pack_data->hash, \"keep\");\n    -+\todb_pack_name(the_repository, &name, pack_data->hash, \"keep\");\n    ++\todb_pack_name(pack_data->r, &name, pack_data->hash, \"keep\");\n      \tkeep_fd = odb_pack_keep(name.buf);\n      \tif (keep_fd < 0)\n      \t\tdie_errno(\"cannot create keep file\");\n    @@ builtin/fast-import.c: static char *keep_pack(const char *curr_index_name)\n      \t\tdie_errno(\"failed to write keep file\");\n      \n     -\todb_pack_name(&name, pack_data->hash, \"pack\");\n    -+\todb_pack_name(the_repository, &name, pack_data->hash, \"pack\");\n    ++\todb_pack_name(pack_data->r, &name, pack_data->hash, \"pack\");\n      \tif (finalize_object_file(pack_data->pack_name, name.buf))\n      \t\tdie(\"cannot store pack file\");\n      \n     -\todb_pack_name(&name, pack_data->hash, \"idx\");\n    -+\todb_pack_name(the_repository, &name, pack_data->hash, \"idx\");\n    ++\todb_pack_name(pack_data->r, &name, pack_data->hash, \"idx\");\n      \tif (finalize_object_file(curr_index_name, name.buf))\n      \t\tdie(\"cannot store index file\");\n      \tfree((void *)curr_index_name);\n    @@ builtin/fast-import.c: static void unkeep_all_packs(void)\n      \tfor (k = 0; k < pack_id; k++) {\n      \t\tstruct packed_git *p = all_packs[k];\n     -\t\todb_pack_name(&name, p->hash, \"keep\");\n    -+\t\todb_pack_name(p->repo, &name, p->hash, \"keep\");\n    ++\t\todb_pack_name(p->r, &name, p->hash, \"keep\");\n      \t\tunlink_or_warn(name.buf);\n      \t}\n      \tstrbuf_release(&name);\n    @@ builtin/index-pack.c: static void rename_tmp_packfile(const char **final_name,\n      \t\t\t    ext, *final_name);\n     \n      ## builtin/pack-redundant.c ##\n    -@@ builtin/pack-redundant.c: static void load_all(void)\n    - \t}\n    - }\n    - \n    --int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) {\n    -+int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo) {\n    - \tint i; int i_still_use_this = 0; struct pack_list *min = NULL, *red, *pl;\n    - \tstruct llist *ignore;\n    - \tstruct strbuf idx_name = STRBUF_INIT;\n     @@ builtin/pack-redundant.c: int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s\n      \tpl = red = pack_list_difference(local_packs, min);\n      \twhile (pl) {\n      \t\tprintf(\"%s\\n%s\\n\",\n     -\t\t       odb_pack_name(&idx_name, pl->pack->hash, \"idx\"),\n    -+\t\t       odb_pack_name(repo, &idx_name, pl->pack->hash, \"idx\"),\n    ++\t\t       odb_pack_name(pl->pack->r, &idx_name, pl->pack->hash, \"idx\"),\n      \t\t       pl->pack->pack_name);\n      \t\tpl = pl->next;\n      \t}\n    @@ packfile.c\n     -char *odb_pack_name(struct strbuf *buf,\n     -\t\t    const unsigned char *hash,\n     -\t\t    const char *ext)\n    -+char *odb_pack_name(struct repository *repo, struct strbuf *buf,\n    ++char *odb_pack_name(struct repository *r, struct strbuf *buf,\n     +\t\t    const unsigned char *hash, const char *ext)\n      {\n      \tstrbuf_reset(buf);\n     -\tstrbuf_addf(buf, \"%s/pack/pack-%s.%s\", repo_get_object_directory(the_repository),\n     -\t\t    hash_to_hex(hash), ext);\n    -+\tstrbuf_addf(buf, \"%s/pack/pack-%s.%s\", repo_get_object_directory(repo),\n    -+\t\t    hash_to_hex_algop(hash, repo->hash_algo), ext);\n    ++\tstrbuf_addf(buf, \"%s/pack/pack-%s.%s\", repo_get_object_directory(r),\n    ++\t\t    hash_to_hex_algop(hash, r->hash_algo), ext);\n      \treturn buf->buf;\n      }\n      \n    @@ packfile.h: struct pack_entry {\n       * Example: odb_pack_name(out, sha1, \"idx\") => \".git/objects/pack/pack-1234..idx\"\n       */\n     -char *odb_pack_name(struct strbuf *buf, const unsigned char *sha1, const char *ext);\n    -+char *odb_pack_name(struct repository *repo, struct strbuf *buf,\n    ++char *odb_pack_name(struct repository *r, struct strbuf *buf,\n     +\t\t    const unsigned char *hash, const char *ext);\n      \n      /*\n 5:  4e883a4d1c !  5:  1fac06f19e packfile: pass down repository to `has_object[_kept]_pack`\n    @@ builtin/pack-objects.c: static int want_found_object(const struct object_id *oid\n      \t\tif (ignore_packed_keep_in_core && p->pack_keep_in_core)\n      \t\t\treturn 0;\n     -\t\tif (has_object_kept_pack(oid, flags))\n    -+\t\tif (has_object_kept_pack(the_repository, oid, flags))\n    ++\t\tif (has_object_kept_pack(p->r, oid, flags))\n      \t\t\treturn 0;\n      \t}\n      \n    @@ builtin/pack-objects.c: static void show_cruft_commit(struct commit *commit, voi\n      static int cruft_include_check_obj(struct object *obj, void *data UNUSED)\n      {\n     -\treturn !has_object_kept_pack(&obj->oid, IN_CORE_KEEP_PACKS);\n    -+\treturn !has_object_kept_pack(the_repository, &obj->oid, IN_CORE_KEEP_PACKS);\n    ++\treturn !has_object_kept_pack(to_pack.repo, &obj->oid, IN_CORE_KEEP_PACKS);\n      }\n      \n      static int cruft_include_check(struct commit *commit, void *data)\n    @@ diff.c: static int reuse_worktree_file(struct index_state *istate,\n      \t */\n     -\tif (!FAST_WORKING_DIRECTORY && !want_file && has_object_pack(oid))\n     +\tif (!FAST_WORKING_DIRECTORY && !want_file &&\n    -+\t    has_object_pack(the_repository, oid))\n    ++\t    has_object_pack(istate->repo, oid))\n      \t\treturn 0;\n      \n      \t/*\n    @@ packfile.c: int find_kept_pack_entry(struct repository *r,\n      }\n      \n     -int has_object_pack(const struct object_id *oid)\n    -+int has_object_pack(struct repository *repo, const struct object_id *oid)\n    ++int has_object_pack(struct repository *r, const struct object_id *oid)\n      {\n      \tstruct pack_entry e;\n     -\treturn find_pack_entry(the_repository, oid, &e);\n    -+\treturn find_pack_entry(repo, oid, &e);\n    ++\treturn find_pack_entry(r, oid, &e);\n      }\n      \n     -int has_object_kept_pack(const struct object_id *oid, unsigned flags)\n    -+int has_object_kept_pack(struct repository *repo, const struct object_id *oid,\n    ++int has_object_kept_pack(struct repository *r, const struct object_id *oid,\n     +\t\t\t unsigned flags)\n      {\n      \tstruct pack_entry e;\n     -\treturn find_kept_pack_entry(the_repository, oid, flags, &e);\n    -+\treturn find_kept_pack_entry(repo, oid, flags, &e);\n    ++\treturn find_kept_pack_entry(r, oid, flags, &e);\n      }\n      \n      int for_each_object_in_pack(struct packed_git *p,\n    @@ packfile.h: const struct packed_git *has_packed_and_bad(struct repository *, con\n      \n     -int has_object_pack(const struct object_id *oid);\n     -int has_object_kept_pack(const struct object_id *oid, unsigned flags);\n    -+int has_object_pack(struct repository *repo, const struct object_id *oid);\n    -+int has_object_kept_pack(struct repository *repo, const struct object_id *oid,\n    ++int has_object_pack(struct repository *r, const struct object_id *oid);\n    ++int has_object_kept_pack(struct repository *r, const struct object_id *oid,\n     +\t\t\t unsigned flags);\n      \n      /*\n 6:  7c599e16f6 !  6:  a5fb3b1a4a packfile: pass down repository to `for_each_packed_object`\n    @@ builtin/pack-objects.c: static void show_object__ma_allow_promisor(struct object\n      \t */\n     -\tif (!has_object(the_repository, &obj->oid, 0) && is_promisor_object(&obj->oid))\n     +\tif (!has_object(the_repository, &obj->oid, 0) &&\n    -+\t    is_promisor_object(the_repository, &obj->oid))\n    ++\t    is_promisor_object(to_pack.repo, &obj->oid))\n      \t\treturn;\n      \n      \tshow_object(obj, name, data);\n    @@ builtin/pack-objects.c: static int add_object_in_unpacked_pack(const struct obje\n      static void add_objects_in_unpacked_packs(void)\n      {\n     -\tif (for_each_packed_object(add_object_in_unpacked_pack, NULL,\n    -+\tif (for_each_packed_object(the_repository,\n    ++\tif (for_each_packed_object(to_pack.repo,\n     +\t\t\t\t   add_object_in_unpacked_pack,\n     +\t\t\t\t   NULL,\n      \t\t\t\t   FOR_EACH_OBJECT_PACK_ORDER |\n    @@ packfile.c: static int add_promisor_object(const struct object_id *oid,\n      }\n      \n     -int is_promisor_object(const struct object_id *oid)\n    -+int is_promisor_object(struct repository *repo, const struct object_id *oid)\n    ++int is_promisor_object(struct repository *r, const struct object_id *oid)\n      {\n      \tstatic struct oidset promisor_objects;\n      \tstatic int promisor_objects_prepared;\n    @@ packfile.c: static int add_promisor_object(const struct object_id *oid,\n      \tif (!promisor_objects_prepared) {\n     -\t\tif (repo_has_promisor_remote(the_repository)) {\n     -\t\t\tfor_each_packed_object(add_promisor_object,\n    -+\t\tif (repo_has_promisor_remote(repo)) {\n    -+\t\t\tfor_each_packed_object(repo, add_promisor_object,\n    ++\t\tif (repo_has_promisor_remote(r)) {\n    ++\t\t\tfor_each_packed_object(r, add_promisor_object,\n      \t\t\t\t\t       &promisor_objects,\n      \t\t\t\t\t       FOR_EACH_OBJECT_PROMISOR_ONLY |\n      \t\t\t\t\t       FOR_EACH_OBJECT_PACK_ORDER);\n     \n      ## packfile.h ##\n    -@@ packfile.h: int has_object_kept_pack(struct repository *repo, const struct object_id *oid,\n    +@@ packfile.h: int has_object_kept_pack(struct repository *r, const struct object_id *oid,\n       * Return 1 if an object in a promisor packfile is or refers to the given\n       * object, 0 otherwise.\n       */\n     -int is_promisor_object(const struct object_id *oid);\n    -+int is_promisor_object(struct repository *repo, const struct object_id *oid);\n    ++int is_promisor_object(struct repository *r, const struct object_id *oid);\n      \n      /*\n       * Expose a function for fuzz testing.\n 7:  89ee3f48ce !  7:  6e5951ceea config: make `delta_base_cache_limit` a non-global variable\n    @@ Commit message\n         this value from the repository config, since the value is only used once\n         in the entire subsystem.\n     \n    +    These changes are made to remove the usage of `delta_base_cache_limit`\n    +    as a global variable in `packfile.c`. This brings us one step closer to\n    +    removing the `USE_THE_REPOSITORY_VARIABLE` definition in `packfile.c`\n    +    which we complete in the next patch.\n    +\n         Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n     \n      ## builtin/gc.c ##\n    @@ packfile.c\n     +#include \"config.h\"\n     +#include \"pack-objects.h\"\n      \n    - char *odb_pack_name(struct repository *repo, struct strbuf *buf,\n    + char *odb_pack_name(struct repository *r, struct strbuf *buf,\n      \t\t    const unsigned char *hash, const char *ext)\n     @@ packfile.c: void clear_delta_base_cache(void)\n      }\n 8:  e99b1dad54 !  8:  ec9061fbbd config: make `packed_git_(limit|window_size)` non-global variables\n    @@ Commit message\n         means we can also remove the `USE_THE_REPOSITORY_VARIABLE` guard from\n         the file.\n     \n    +    Helped-by: Taylor Blau <me@ttaylorr.com>\n         Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n     \n      ## builtin/fast-import.c ##\n    @@ packfile.c\n     +#define PACKFILE_CONFIG_INIT \\\n     +{ \\\n     +\t.packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE, \\\n    -+\t.packed_git_limit = DEFAULT_PACKED_GIT_LIMIT,  \\\n    ++\t.packed_git_limit = DEFAULT_PACKED_GIT_LIMIT, \\\n     +}\n     +\n    - char *odb_pack_name(struct repository *repo, struct strbuf *buf,\n    + char *odb_pack_name(struct repository *r, struct strbuf *buf,\n      \t\t    const unsigned char *hash, const char *ext)\n      {\n     @@ packfile.c: static size_t pack_mapped;\n    @@ packfile.c: static size_t pack_mapped;\n     -void pack_report(void)\n     +static int packfile_config(const char *var, const char *value,\n     +\t\t\t   const struct config_context *ctx, void *cb)\n    - {\n    ++{\n     +\tstruct packfile_config *config = cb;\n     +\n     +\tif (!strcmp(var, \"core.packedgitwindowsize\")) {\n    @@ packfile.c: static size_t pack_mapped;\n     +\t\t\tconfig->packed_git_window_size = 1;\n     +\t\tconfig->packed_git_window_size *= pgsz_x2;\n     +\t\treturn 0;\n    -+\t}\n    -+\n    -+\tif (!strcmp(var, \"core.packedgitlimit\")) {\n    ++\t} else if (!strcmp(var, \"core.packedgitlimit\")) {\n     +\t\tconfig->packed_git_limit = git_config_ulong(var, value, ctx->kvi);\n     +\t\treturn 0;\n    ++\t} else {\n    ++\t\treturn git_default_config(var, value, ctx, cb);\n     +\t}\n    -+\n    -+\treturn git_default_config(var, value, ctx, cb);\n     +}\n     +\n    -+\n     +void pack_report(struct repository *repo)\n    -+{\n    + {\n     +\tstruct packfile_config config = PACKFILE_CONFIG_INIT;\n     +\trepo_config(repo, packfile_config, &config);\n     +\n    @@ packfile.c: unsigned char *use_pack(struct packed_git *p,\n     +\t\t\tsize_t window_align;\n      \t\t\toff_t len;\n      \n    -+\t\t\trepo_config(p->repo, packfile_config, &config);\n    ++\t\t\trepo_config(p->r, packfile_config, &config);\n     +\t\t\twindow_align = config.packed_git_window_size / 2;\n     +\n      \t\t\tif (p->pack_fd == -1 && open_packed_git(p))\n 3:  1f8ef580e5 !  9:  c0b386412d packfile: pass `repository` to static function in the file\n    @@ Metadata\n     Author: Karthik Nayak <karthik.188@gmail.com>\n     \n      ## Commit message ##\n    -    packfile: pass `repository` to static function in the file\n    +    midx: add repository to `multi_pack_index` struct\n     \n    -    Some of the static functions in the `packfile.c` access global\n    -    variables, which can simply be avoiding by passing the `repository`\n    -    struct down to them. Let's do that.\n    +    The `multi_pack_index` struct represents the MIDX for a repository.\n    +    Here, we add a pointer to the repository in this struct, allowing direct\n    +    use of the repository variable without relying on the global\n    +    `the_repository` struct.\n    +\n    +    With this addition, we can determine the repository associated with a\n    +    `bitmap_index` struct. A `bitmap_index` points to either a `packed_git`\n    +    or a `multi_pack_index`, both of which have direct repository\n    +    references. To support this, we introduce a static helper function,\n    +    `bitmap_repo`, in `pack-bitmap.c`, which retrieves a repository given a\n    +    `bitmap_index`.\n    +\n    +    With this, we clear up all usages of `the_repository` within\n    +    `pack-bitmap.c` and also remove the `USE_THE_REPOSITORY_VARIABLE`\n    +    definition. Bringing us another step closer to remove all global\n    +    variable usage.\n    +\n    +    Although this change also opens up the potential to clean up `midx.c`,\n    +    doing so would require additional refactoring to pass the repository\n    +    struct to functions where the MIDX struct is created: a task better\n    +    suited for future patches.\n     \n         Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n     \n    - ## packfile.c ##\n    -@@ packfile.c: static void find_lru_pack(struct packed_git *p, struct packed_git **lru_p, struc\n    - \t*accept_windows_inuse = has_windows_inuse;\n    + ## midx.c ##\n    +@@ midx.c: static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir\n    + \tm->data = midx_map;\n    + \tm->data_len = midx_size;\n    + \tm->local = local;\n    ++\tm->r = the_repository;\n    + \n    + \tm->signature = get_be32(m->data);\n    + \tif (m->signature != MIDX_SIGNATURE)\n    +\n    + ## midx.h ##\n    +@@ midx.h: struct multi_pack_index {\n    + \n    + \tconst char **pack_names;\n    + \tstruct packed_git **packs;\n    ++\n    ++\tstruct repository *r;\n    ++\n    + \tchar object_dir[FLEX_ARRAY];\n    + };\n    + \n    +\n    + ## pack-bitmap.c ##\n    +@@\n    +-#define USE_THE_REPOSITORY_VARIABLE\n    +-\n    + #include \"git-compat-util.h\"\n    + #include \"commit.h\"\n    + #include \"gettext.h\"\n    +@@ pack-bitmap.c: static uint32_t bitmap_num_objects(struct bitmap_index *index)\n    + \treturn index->pack->num_objects;\n      }\n      \n    --static int close_one_pack(void)\n    -+static int close_one_pack(struct repository *repo)\n    ++static struct repository *bitmap_repo(struct bitmap_index *bitmap_git)\n    ++{\n    ++\tif (bitmap_is_midx(bitmap_git))\n    ++\t\treturn bitmap_git->midx->r;\n    ++\treturn bitmap_git->pack->r;\n    ++}\n    ++\n    + static int load_bitmap_header(struct bitmap_index *index)\n      {\n    - \tstruct packed_git *p, *lru_p = NULL;\n    - \tstruct pack_window *mru_w = NULL;\n    - \tint accept_windows_inuse = 1;\n    + \tstruct bitmap_disk_header *header = (void *)index->map;\n    +-\tsize_t header_size = sizeof(*header) - GIT_MAX_RAWSZ + the_hash_algo->rawsz;\n    ++\tconst struct git_hash_algo *hash_algo = bitmap_repo(index)->hash_algo;\n    ++\n    ++\tsize_t header_size = sizeof(*header) - GIT_MAX_RAWSZ + hash_algo->rawsz;\n      \n    --\tfor (p = the_repository->objects->packed_git; p; p = p->next) {\n    -+\tfor (p = repo->objects->packed_git; p; p = p->next) {\n    - \t\tif (p->pack_fd == -1)\n    - \t\t\tcontinue;\n    - \t\tfind_lru_pack(p, &lru_p, &mru_w, &accept_windows_inuse);\n    -@@ packfile.c: static int open_packed_git_1(struct packed_git *p)\n    - \t\t\tpack_max_fds = 1;\n    +-\tif (index->map_size < header_size + the_hash_algo->rawsz)\n    ++\tif (index->map_size < header_size + hash_algo->rawsz)\n    + \t\treturn error(_(\"corrupted bitmap index (too small)\"));\n    + \n    + \tif (memcmp(header->magic, BITMAP_IDX_SIGNATURE, sizeof(BITMAP_IDX_SIGNATURE)) != 0)\n    +@@ pack-bitmap.c: static int load_bitmap_header(struct bitmap_index *index)\n    + \t{\n    + \t\tuint32_t flags = ntohs(header->options);\n    + \t\tsize_t cache_size = st_mult(bitmap_num_objects(index), sizeof(uint32_t));\n    +-\t\tunsigned char *index_end = index->map + index->map_size - the_hash_algo->rawsz;\n    ++\t\tunsigned char *index_end = index->map + index->map_size - hash_algo->rawsz;\n    + \n    + \t\tif ((flags & BITMAP_OPT_FULL_DAG) == 0)\n    + \t\t\tBUG(\"unsupported options for bitmap index file \"\n    +@@ pack-bitmap.c: static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,\n    + \tif (bitmap_git->pack || bitmap_git->midx) {\n    + \t\tstruct strbuf buf = STRBUF_INIT;\n    + \t\tget_midx_filename(&buf, midx->object_dir);\n    +-\t\ttrace2_data_string(\"bitmap\", the_repository,\n    ++\t\ttrace2_data_string(\"bitmap\", bitmap_repo(bitmap_git),\n    + \t\t\t\t   \"ignoring extra midx bitmap file\", buf.buf);\n    + \t\tclose(fd);\n    + \t\tstrbuf_release(&buf);\n    +@@ pack-bitmap.c: static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,\n    + \t\tgoto cleanup;\n    + \n    + \tif (!hasheq(get_midx_checksum(bitmap_git->midx), bitmap_git->checksum,\n    +-\t\t    the_repository->hash_algo)) {\n    ++\t\t    bitmap_repo(bitmap_git)->hash_algo)) {\n    + \t\terror(_(\"checksum doesn't match in MIDX and bitmap\"));\n    + \t\tgoto cleanup;\n    + \t}\n    +@@ pack-bitmap.c: static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,\n    + \t}\n    + \n    + \tfor (i = 0; i < bitmap_git->midx->num_packs; i++) {\n    +-\t\tif (prepare_midx_pack(the_repository, bitmap_git->midx, i)) {\n    ++\t\tif (prepare_midx_pack(bitmap_repo(bitmap_git),\n    ++\t\t\t\t      bitmap_git->midx,\n    ++\t\t\t\t      i)) {\n    + \t\t\twarning(_(\"could not open pack %s\"),\n    + \t\t\t\tbitmap_git->midx->pack_names[i]);\n    + \t\t\tgoto cleanup;\n    +@@ pack-bitmap.c: static int open_pack_bitmap_1(struct bitmap_index *bitmap_git, struct packed_git\n      \t}\n      \n    --\twhile (pack_max_fds <= pack_open_fds && close_one_pack())\n    -+\twhile (pack_max_fds <= pack_open_fds && close_one_pack(p->repo))\n    - \t\t; /* nothing */\n    + \tif (bitmap_git->pack || bitmap_git->midx) {\n    +-\t\ttrace2_data_string(\"bitmap\", the_repository,\n    +-\t\t\t\t   \"ignoring extra bitmap file\", packfile->pack_name);\n    ++\t\ttrace2_data_string(\"bitmap\", bitmap_repo(bitmap_git),\n    ++\t\t\t\t   \"ignoring extra bitmap file\",\n    ++\t\t\t\t   packfile->pack_name);\n    + \t\tclose(fd);\n    + \t\treturn -1;\n    + \t}\n    +@@ pack-bitmap.c: static int open_pack_bitmap_1(struct bitmap_index *bitmap_git, struct packed_git\n    + \t\treturn -1;\n    + \t}\n      \n    - \tp->pack_fd = git_open(p->pack_name);\n    -@@ packfile.c: static int open_packed_git(struct packed_git *p)\n    - \treturn -1;\n    +-\ttrace2_data_string(\"bitmap\", the_repository, \"opened bitmap file\",\n    +-\t\t\t   packfile->pack_name);\n    ++\ttrace2_data_string(\"bitmap\", bitmap_repo(bitmap_git),\n    ++\t\t\t   \"opened bitmap file\", packfile->pack_name);\n    + \treturn 0;\n      }\n      \n    --static int in_window(struct pack_window *win, off_t offset)\n    -+static int in_window(struct repository *repo, struct pack_window *win,\n    -+\t\t     off_t offset)\n    +@@ pack-bitmap.c: struct bitmap_index *prepare_bitmap_git(struct repository *r)\n    + \n    + struct bitmap_index *prepare_midx_bitmap_git(struct multi_pack_index *midx)\n    + {\n    +-\tstruct repository *r = the_repository;\n    ++\tstruct repository *r = midx->r;\n    + \tstruct bitmap_index *bitmap_git = xcalloc(1, sizeof(*bitmap_git));\n    + \n    + \tif (!open_midx_bitmap_1(bitmap_git, midx) && !load_bitmap(r, bitmap_git))\n    +@@ pack-bitmap.c: static struct bitmap *find_boundary_objects(struct bitmap_index *bitmap_git,\n      {\n    - \t/* We must promise at least one full hash after the\n    - \t * offset is available from this window, otherwise the offset\n    -@@ packfile.c: static int in_window(struct pack_window *win, off_t offset)\n    + \tstruct bitmap_boundary_cb cb;\n    + \tstruct object_list *root;\n    ++\tstruct repository *repo;\n    + \tunsigned int i;\n    + \tunsigned int tmp_blobs, tmp_trees, tmp_tags;\n    + \tint any_missing = 0;\n    +@@ pack-bitmap.c: static struct bitmap *find_boundary_objects(struct bitmap_index *bitmap_git,\n    + \tcb.base = bitmap_new();\n    + \tobject_array_init(&cb.boundary);\n    + \n    ++\trepo = bitmap_repo(bitmap_git);\n    ++\n    + \trevs->ignore_missing_links = 1;\n    + \n    + \tif (bitmap_git->pseudo_merges.nr) {\n    +@@ pack-bitmap.c: static struct bitmap *find_boundary_objects(struct bitmap_index *bitmap_git,\n    + \t * revision walk to (a) OR in any bitmaps that are UNINTERESTING\n    + \t * between the tips and boundary, and (b) record the boundary.\n      \t */\n    - \toff_t win_off = win->offset;\n    - \treturn win_off <= offset\n    --\t\t&& (offset + the_hash_algo->rawsz) <= (win_off + win->len);\n    -+\t\t&& (offset + repo->hash_algo->rawsz) <= (win_off + win->len);\n    +-\ttrace2_region_enter(\"pack-bitmap\", \"boundary-prepare\", the_repository);\n    ++\ttrace2_region_enter(\"pack-bitmap\", \"boundary-prepare\", repo);\n    + \tif (prepare_revision_walk(revs))\n    + \t\tdie(\"revision walk setup failed\");\n    +-\ttrace2_region_leave(\"pack-bitmap\", \"boundary-prepare\", the_repository);\n    ++\ttrace2_region_leave(\"pack-bitmap\", \"boundary-prepare\", repo);\n    + \n    +-\ttrace2_region_enter(\"pack-bitmap\", \"boundary-traverse\", the_repository);\n    ++\ttrace2_region_enter(\"pack-bitmap\", \"boundary-traverse\", repo);\n    + \trevs->boundary = 1;\n    + \ttraverse_commit_list_filtered(revs,\n    + \t\t\t\t      show_boundary_commit,\n    + \t\t\t\t      show_boundary_object,\n    + \t\t\t\t      &cb, NULL);\n    + \trevs->boundary = 0;\n    +-\ttrace2_region_leave(\"pack-bitmap\", \"boundary-traverse\", the_repository);\n    ++\ttrace2_region_leave(\"pack-bitmap\", \"boundary-traverse\", repo);\n    + \n    + \trevs->blob_objects = tmp_blobs;\n    + \trevs->tree_objects = tmp_trees;\n    +@@ pack-bitmap.c: static struct bitmap *find_boundary_objects(struct bitmap_index *bitmap_git,\n    + \t/*\n    + \t * Then add the boundary commit(s) as fill-in traversal tips.\n    + \t */\n    +-\ttrace2_region_enter(\"pack-bitmap\", \"boundary-fill-in\", the_repository);\n    ++\ttrace2_region_enter(\"pack-bitmap\", \"boundary-fill-in\", repo);\n    + \tfor (i = 0; i < cb.boundary.nr; i++) {\n    + \t\tstruct object *obj = cb.boundary.objects[i].item;\n    + \t\tif (bitmap_walk_contains(bitmap_git, cb.base, &obj->oid))\n    +@@ pack-bitmap.c: static struct bitmap *find_boundary_objects(struct bitmap_index *bitmap_git,\n    + \t}\n    + \tif (revs->pending.nr)\n    + \t\tcb.base = fill_in_bitmap(bitmap_git, revs, cb.base, NULL);\n    +-\ttrace2_region_leave(\"pack-bitmap\", \"boundary-fill-in\", the_repository);\n    ++\ttrace2_region_leave(\"pack-bitmap\", \"boundary-fill-in\", repo);\n    + \n    + cleanup:\n    + \tobject_array_clear(&cb.boundary);\n    +@@ pack-bitmap.c: static unsigned long get_size_by_pos(struct bitmap_index *bitmap_git,\n    + \t\t\tofs = pack_pos_to_offset(pack, pos);\n    + \t\t}\n    + \n    +-\t\tif (packed_object_info(the_repository, pack, ofs, &oi) < 0) {\n    ++\t\tif (packed_object_info(bitmap_repo(bitmap_git), pack, ofs,\n    ++\t\t\t\t       &oi) < 0) {\n    + \t\t\tstruct object_id oid;\n    + \t\t\tnth_bitmap_object_oid(bitmap_git, &oid,\n    + \t\t\t\t\t      pack_pos_to_index(pack, pos));\n    +@@ pack-bitmap.c: static unsigned long get_size_by_pos(struct bitmap_index *bitmap_git,\n    + \t} else {\n    + \t\tstruct eindex *eindex = &bitmap_git->ext_index;\n    + \t\tstruct object *obj = eindex->objects[pos - bitmap_num_objects(bitmap_git)];\n    +-\t\tif (oid_object_info_extended(the_repository, &obj->oid, &oi, 0) < 0)\n    ++\t\tif (oid_object_info_extended(bitmap_repo(bitmap_git), &obj->oid,\n    ++\t\t\t\t\t     &oi, 0) < 0)\n    + \t\t\tdie(_(\"unable to get size of %s\"), oid_to_hex(&obj->oid));\n    + \t}\n    + \n    +@@ pack-bitmap.c: static void filter_packed_objects_from_bitmap(struct bitmap_index *bitmap_git,\n    + \t\tbitmap_unset(result, i);\n    + \n    + \tfor (i = 0; i < eindex->count; ++i) {\n    +-\t\tif (has_object_pack(the_repository, &eindex->objects[i]->oid))\n    ++\t\tif (has_object_pack(bitmap_repo(bitmap_git),\n    ++\t\t\t\t    &eindex->objects[i]->oid))\n    + \t\t\tbitmap_unset(result, objects_nr + i);\n    + \t}\n      }\n    +@@ pack-bitmap.c: struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,\n    + \tstruct bitmap *haves_bitmap = NULL;\n      \n    - unsigned char *use_pack(struct packed_git *p,\n    -@@ packfile.c: unsigned char *use_pack(struct packed_git *p,\n    - \tif (offset < 0)\n    - \t\tdie(_(\"offset before end of packfile (broken .idx?)\"));\n    - \n    --\tif (!win || !in_window(win, offset)) {\n    -+\tif (!win || !in_window(p->repo, win, offset)) {\n    - \t\tif (win)\n    - \t\t\twin->inuse_cnt--;\n    - \t\tfor (win = p->windows; win; win = win->next) {\n    --\t\t\tif (in_window(win, offset))\n    -+\t\t\tif (in_window(p->repo, win, offset))\n    - \t\t\t\tbreak;\n    + \tstruct bitmap_index *bitmap_git;\n    ++\tstruct repository *repo;\n    + \n    + \t/*\n    + \t * We can't do pathspec limiting with bitmaps, because we don't know\n    +@@ pack-bitmap.c: struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,\n    + \tif (!use_boundary_traversal)\n    + \t\tobject_array_clear(&revs->pending);\n    + \n    ++\trepo = bitmap_repo(bitmap_git);\n    ++\n    + \tif (haves) {\n    +-\t\tif (use_boundary_traversal) {\n    +-\t\t\ttrace2_region_enter(\"pack-bitmap\", \"haves/boundary\", the_repository);\n    ++\t\tif (use_boundary_traversal)\n    ++\t\t{\n    ++\t\t\ttrace2_region_enter(\"pack-bitmap\", \"haves/boundary\", repo);\n    + \t\t\thaves_bitmap = find_boundary_objects(bitmap_git, revs, haves);\n    +-\t\t\ttrace2_region_leave(\"pack-bitmap\", \"haves/boundary\", the_repository);\n    +-\t\t} else {\n    +-\t\t\ttrace2_region_enter(\"pack-bitmap\", \"haves/classic\", the_repository);\n    ++\t\t\ttrace2_region_leave(\"pack-bitmap\", \"haves/boundary\", repo);\n    ++\t\t}\n    ++\t\telse\n    ++\t\t{\n    ++\t\t\ttrace2_region_enter(\"pack-bitmap\", \"haves/classic\", repo);\n    + \t\t\trevs->ignore_missing_links = 1;\n    + \t\t\thaves_bitmap = find_objects(bitmap_git, revs, haves, NULL);\n    + \t\t\treset_revision_walk();\n    + \t\t\trevs->ignore_missing_links = 0;\n    +-\t\t\ttrace2_region_leave(\"pack-bitmap\", \"haves/classic\", the_repository);\n    ++\t\t\ttrace2_region_leave(\"pack-bitmap\", \"haves/classic\", repo);\n      \t\t}\n    - \t\tif (!win) {\n    + \n    + \t\tif (!haves_bitmap)\n    +@@ pack-bitmap.c: struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,\n    + \tobject_list_free(&wants);\n    + \tobject_list_free(&haves);\n    + \n    +-\ttrace2_data_intmax(\"bitmap\", the_repository, \"pseudo_merges_satisfied\",\n    ++\ttrace2_data_intmax(\"bitmap\", repo, \"pseudo_merges_satisfied\",\n    + \t\t\t   pseudo_merges_satisfied_nr);\n    +-\ttrace2_data_intmax(\"bitmap\", the_repository, \"pseudo_merges_cascades\",\n    ++\ttrace2_data_intmax(\"bitmap\", repo, \"pseudo_merges_cascades\",\n    + \t\t\t   pseudo_merges_cascades_nr);\n    +-\ttrace2_data_intmax(\"bitmap\", the_repository, \"bitmap/hits\",\n    ++\ttrace2_data_intmax(\"bitmap\", repo, \"bitmap/hits\",\n    + \t\t\t   existing_bitmaps_hits_nr);\n    +-\ttrace2_data_intmax(\"bitmap\", the_repository, \"bitmap/misses\",\n    ++\ttrace2_data_intmax(\"bitmap\", repo, \"bitmap/misses\",\n    + \t\t\t   existing_bitmaps_misses_nr);\n    +-\ttrace2_data_intmax(\"bitmap\", the_repository, \"bitmap/roots_with_bitmap\",\n    ++\ttrace2_data_intmax(\"bitmap\", repo, \"bitmap/roots_with_bitmap\",\n    + \t\t\t   roots_with_bitmaps_nr);\n    +-\ttrace2_data_intmax(\"bitmap\", the_repository, \"bitmap/roots_without_bitmap\",\n    ++\ttrace2_data_intmax(\"bitmap\", repo, \"bitmap/roots_without_bitmap\",\n    + \t\t\t   roots_without_bitmaps_nr);\n    + \n    + \treturn bitmap_git;\n    +@@ pack-bitmap.c: void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,\n    + \t\t\t\t\tstruct bitmap **reuse_out,\n    + \t\t\t\t\tint multi_pack_reuse)\n    + {\n    +-\tstruct repository *r = the_repository;\n    ++\tstruct repository *r = bitmap_repo(bitmap_git);\n    + \tstruct bitmapped_pack *packs = NULL;\n    + \tstruct bitmap *result = bitmap_git->result;\n    + \tstruct bitmap *reuse;\n    +@@ pack-bitmap.c: int rebuild_bitmap(const uint32_t *reposition,\n    + uint32_t *create_bitmap_mapping(struct bitmap_index *bitmap_git,\n    + \t\t\t\tstruct packing_data *mapping)\n    + {\n    +-\tstruct repository *r = the_repository;\n    ++\tstruct repository *r = bitmap_repo(bitmap_git);\n    + \tuint32_t i, num_objects;\n    + \tuint32_t *reposition;\n    + \n    +@@ pack-bitmap.c: static off_t get_disk_usage_for_extended(struct bitmap_index *bitmap_git)\n    + \t\t\t\tst_add(bitmap_num_objects(bitmap_git), i)))\n    + \t\t\tcontinue;\n    + \n    +-\t\tif (oid_object_info_extended(the_repository, &obj->oid, &oi, 0) < 0)\n    ++\t\tif (oid_object_info_extended(bitmap_repo(bitmap_git), &obj->oid,\n    ++\t\t\t\t\t     &oi, 0) < 0)\n    + \t\t\tdie(_(\"unable to get disk usage of '%s'\"),\n    + \t\t\t    oid_to_hex(&obj->oid));\n    + \n-- \n2.47.0\n\n"},{"id":"506319","messageId":"5afb9af0afdf6062b16dea2d1347170485e7d73e.1730297934.git.karthik.188@gmail.com","threadId":"62424","inReplyTo":"cover.1730297934.git.karthik.188@gmail.com","subject":"[PATCH v3 1/9] packfile: add repository to struct `packed_git`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-10-30T14:32:26Z","receivedAt":"2024-10-30T14:32:40Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The struct `packed_git` holds information regarding a packed object\nfile. Let's add the repository variable to this object, to represent the\nrepository that this packfile belongs to. This helps remove dependency\non the global `the_repository` object in `packfile.c` by simply using\nrepository information now readily available in the struct.\n\nWe do need to consider that a pack file could be part of the alternates\nof a repository, but considering that we only have one repository struct\nand also that we currently anyways use 'the_repository'. We should be\nOK with this change.\n\nWe also modify `alloc_packed_git` to ensure that the repository is added\nto newly created `packed_git` structs. This requires modifying the\nfunction and all its callee to pass the repository object down the\nlevels.\n\nHelped-by: Taylor Blau <me@ttaylorr.com>\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n builtin/fast-import.c |  3 ++-\n builtin/index-pack.c  |  6 ++++--\n commit-graph.c        |  2 +-\n connected.c           |  3 ++-\n http.c                |  2 +-\n midx-write.c          |  2 +-\n midx.c                |  2 +-\n object-store-ll.h     |  5 +++++\n packfile.c            | 15 +++++++++------\n packfile.h            |  6 ++++--\n 10 files changed, 30 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin/fast-import.c b/builtin/fast-import.c\nindex 76d5c20f14..f8d3d7e0c7 100644\n--- a/builtin/fast-import.c\n+++ b/builtin/fast-import.c\n@@ -765,6 +765,7 @@ static void start_packfile(void)\n \n \tp->pack_fd = pack_fd;\n \tp->do_not_close = 1;\n+\tp->r = the_repository;\n \tpack_file = hashfd(pack_fd, p->pack_name);\n \n \tpack_data = p;\n@@ -888,7 +889,7 @@ static void end_packfile(void)\n \t\tidx_name = keep_pack(create_index());\n \n \t\t/* Register the packfile with core git's machinery. */\n-\t\tnew_p = add_packed_git(idx_name, strlen(idx_name), 1);\n+\t\tnew_p = add_packed_git(pack_data->r, idx_name, strlen(idx_name), 1);\n \t\tif (!new_p)\n \t\t\tdie(\"core git rejected index %s\", idx_name);\n \t\tall_packs[pack_id] = new_p;\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 9d23b41b3a..be2f99625e 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -1552,7 +1552,8 @@ static void final(const char *final_pack_name, const char *curr_pack_name,\n \n \tif (do_fsck_object) {\n \t\tstruct packed_git *p;\n-\t\tp = add_packed_git(final_index_name, strlen(final_index_name), 0);\n+\t\tp = add_packed_git(the_repository, final_index_name,\n+\t\t\t\t   strlen(final_index_name), 0);\n \t\tif (p)\n \t\t\tinstall_packed_git(the_repository, p);\n \t}\n@@ -1650,7 +1651,8 @@ static void read_v2_anomalous_offsets(struct packed_git *p,\n \n static void read_idx_option(struct pack_idx_option *opts, const char *pack_name)\n {\n-\tstruct packed_git *p = add_packed_git(pack_name, strlen(pack_name), 1);\n+\tstruct packed_git *p = add_packed_git(the_repository, pack_name,\n+\t\t\t\t\t      strlen(pack_name), 1);\n \n \tif (!p)\n \t\tdie(_(\"Cannot open existing pack file '%s'\"), pack_name);\ndiff --git a/commit-graph.c b/commit-graph.c\nindex 5bd89c0acd..83dd69bfeb 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -1914,7 +1914,7 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,\n \t\tstruct packed_git *p;\n \t\tstrbuf_setlen(&packname, dirlen);\n \t\tstrbuf_addstr(&packname, pack_indexes->items[i].string);\n-\t\tp = add_packed_git(packname.buf, packname.len, 1);\n+\t\tp = add_packed_git(ctx->r, packname.buf, packname.len, 1);\n \t\tif (!p) {\n \t\t\tret = error(_(\"error adding pack %s\"), packname.buf);\n \t\t\tgoto cleanup;\ndiff --git a/connected.c b/connected.c\nindex a9e2e13995..3099da84f3 100644\n--- a/connected.c\n+++ b/connected.c\n@@ -54,7 +54,8 @@ int check_connected(oid_iterate_fn fn, void *cb_data,\n \t\tstrbuf_add(&idx_file, transport->pack_lockfiles.items[0].string,\n \t\t\t   base_len);\n \t\tstrbuf_addstr(&idx_file, \".idx\");\n-\t\tnew_pack = add_packed_git(idx_file.buf, idx_file.len, 1);\n+\t\tnew_pack = add_packed_git(the_repository, idx_file.buf,\n+\t\t\t\t\t  idx_file.len, 1);\n \t\tstrbuf_release(&idx_file);\n \t}\n \ndiff --git a/http.c b/http.c\nindex 510332ab04..7e5be05207 100644\n--- a/http.c\n+++ b/http.c\n@@ -2437,7 +2437,7 @@ static int fetch_and_setup_pack_index(struct packed_git **packs_head,\n \tif (!tmp_idx)\n \t\treturn -1;\n \n-\tnew_pack = parse_pack_index(sha1, tmp_idx);\n+\tnew_pack = parse_pack_index(the_repository, sha1, tmp_idx);\n \tif (!new_pack) {\n \t\tunlink(tmp_idx);\n \t\tfree(tmp_idx);\ndiff --git a/midx-write.c b/midx-write.c\nindex b3a5f6c516..c57726ef94 100644\n--- a/midx-write.c\n+++ b/midx-write.c\n@@ -154,7 +154,7 @@ static void add_pack_to_midx(const char *full_path, size_t full_path_len,\n \t\t\treturn;\n \n \t\tALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc);\n-\t\tp = add_packed_git(full_path, full_path_len, 0);\n+\t\tp = add_packed_git(the_repository, full_path, full_path_len, 0);\n \t\tif (!p) {\n \t\t\twarning(_(\"failed to add packfile '%s'\"),\n \t\t\t\tfull_path);\ndiff --git a/midx.c b/midx.c\nindex e82d4f2e65..8edb75f51d 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -464,7 +464,7 @@ int prepare_midx_pack(struct repository *r, struct multi_pack_index *m,\n \t\t\t\t\tstrhash(key.buf), key.buf,\n \t\t\t\t\tstruct packed_git, packmap_ent);\n \tif (!p) {\n-\t\tp = add_packed_git(pack_name.buf, pack_name.len, m->local);\n+\t\tp = add_packed_git(r, pack_name.buf, pack_name.len, m->local);\n \t\tif (p) {\n \t\t\tinstall_packed_git(r, p);\n \t\t\tlist_add_tail(&p->mru, &r->objects->packed_git_mru);\ndiff --git a/object-store-ll.h b/object-store-ll.h\nindex 53b8e693b1..e8a22ab5fc 100644\n--- a/object-store-ll.h\n+++ b/object-store-ll.h\n@@ -10,6 +10,7 @@\n struct oidmap;\n struct oidtree;\n struct strbuf;\n+struct repository;\n \n struct object_directory {\n \tstruct object_directory *next;\n@@ -135,6 +136,10 @@ struct packed_git {\n \t */\n \tconst uint32_t *mtimes_map;\n \tsize_t mtimes_size;\n+\n+\t/* repo dentoes the repository this packed file belongs to */\n+\tstruct repository *r;\n+\n \t/* something like \".git/objects/pack/xxxxx.pack\" */\n \tchar pack_name[FLEX_ARRAY]; /* more */\n };\ndiff --git a/packfile.c b/packfile.c\nindex 9560f0a33c..1423f23f57 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -217,11 +217,12 @@ uint32_t get_pack_fanout(struct packed_git *p, uint32_t value)\n \treturn ntohl(level1_ofs[value]);\n }\n \n-static struct packed_git *alloc_packed_git(int extra)\n+static struct packed_git *alloc_packed_git(struct repository *r, int extra)\n {\n \tstruct packed_git *p = xmalloc(st_add(sizeof(*p), extra));\n \tmemset(p, 0, sizeof(*p));\n \tp->pack_fd = -1;\n+\tp->r = r;\n \treturn p;\n }\n \n@@ -233,11 +234,12 @@ static char *pack_path_from_idx(const char *idx_path)\n \treturn xstrfmt(\"%.*s.pack\", (int)len, idx_path);\n }\n \n-struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path)\n+struct packed_git *parse_pack_index(struct repository *r, unsigned char *sha1,\n+\t\t\t\t    const char *idx_path)\n {\n \tchar *path = pack_path_from_idx(idx_path);\n \tsize_t alloc = st_add(strlen(path), 1);\n-\tstruct packed_git *p = alloc_packed_git(alloc);\n+\tstruct packed_git *p = alloc_packed_git(r, alloc);\n \n \tmemcpy(p->pack_name, path, alloc); /* includes NUL */\n \tfree(path);\n@@ -703,7 +705,8 @@ void unuse_pack(struct pack_window **w_cursor)\n \t}\n }\n \n-struct packed_git *add_packed_git(const char *path, size_t path_len, int local)\n+struct packed_git *add_packed_git(struct repository *r, const char *path,\n+\t\t\t\t  size_t path_len, int local)\n {\n \tstruct stat st;\n \tsize_t alloc;\n@@ -721,7 +724,7 @@ struct packed_git *add_packed_git(const char *path, size_t path_len, int local)\n \t * the use xsnprintf double-checks that)\n \t */\n \talloc = st_add3(path_len, strlen(\".promisor\"), 1);\n-\tp = alloc_packed_git(alloc);\n+\tp = alloc_packed_git(r, alloc);\n \tmemcpy(p->pack_name, path, path_len);\n \n \txsnprintf(p->pack_name + path_len, alloc - path_len, \".keep\");\n@@ -877,7 +880,7 @@ static void prepare_pack(const char *full_name, size_t full_name_len,\n \n \t\t/* Don't reopen a pack we already have. */\n \t\tif (!hashmap_get(&data->r->objects->pack_map, &hent, pack_name)) {\n-\t\t\tp = add_packed_git(full_name, full_name_len, data->local);\n+\t\t\tp = add_packed_git(data->r, full_name, full_name_len, data->local);\n \t\t\tif (p)\n \t\t\t\tinstall_packed_git(data->r, p);\n \t\t}\ndiff --git a/packfile.h b/packfile.h\nindex 08f88a7ff5..aee69d1a0b 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -46,7 +46,8 @@ const char *pack_basename(struct packed_git *p);\n  * and does not add the resulting packed_git struct to the internal list of\n  * packs. You probably want add_packed_git() instead.\n  */\n-struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path);\n+struct packed_git *parse_pack_index(struct repository *r, unsigned char *sha1,\n+\t\t\t\t    const char *idx_path);\n \n typedef void each_file_in_pack_dir_fn(const char *full_path, size_t full_path_len,\n \t\t\t\t      const char *file_name, void *data);\n@@ -113,7 +114,8 @@ void close_pack(struct packed_git *);\n void close_object_store(struct raw_object_store *o);\n void unuse_pack(struct pack_window **);\n void clear_delta_base_cache(void);\n-struct packed_git *add_packed_git(const char *path, size_t path_len, int local);\n+struct packed_git *add_packed_git(struct repository *r, const char *path,\n+\t\t\t\t  size_t path_len, int local);\n \n /*\n  * Unlink the .pack and associated extension files.\n-- \n2.47.0\n\n"},{"id":"506320","messageId":"5b975cb6d6ad760d70c9e9649c30978f2952bff9.1730297934.git.karthik.188@gmail.com","threadId":"62424","inReplyTo":"cover.1730297934.git.karthik.188@gmail.com","subject":"[PATCH v3 3/9] packfile: pass `repository` to static function in the file","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-10-30T14:32:28Z","receivedAt":"2024-10-30T14:32:42Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Some of the static functions in the `packfile.c` access global\nvariables, which can simply be avoiding by passing the `repository`\nstruct down to them. Let's do that.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n packfile.c | 15 ++++++++-------\n 1 file changed, 8 insertions(+), 7 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex ecb284fd98..a391474031 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -460,13 +460,13 @@ static void find_lru_pack(struct packed_git *p, struct packed_git **lru_p, struc\n \t*accept_windows_inuse = has_windows_inuse;\n }\n \n-static int close_one_pack(void)\n+static int close_one_pack(struct repository *r)\n {\n \tstruct packed_git *p, *lru_p = NULL;\n \tstruct pack_window *mru_w = NULL;\n \tint accept_windows_inuse = 1;\n \n-\tfor (p = the_repository->objects->packed_git; p; p = p->next) {\n+\tfor (p = r->objects->packed_git; p; p = p->next) {\n \t\tif (p->pack_fd == -1)\n \t\t\tcontinue;\n \t\tfind_lru_pack(p, &lru_p, &mru_w, &accept_windows_inuse);\n@@ -555,7 +555,7 @@ static int open_packed_git_1(struct packed_git *p)\n \t\t\tpack_max_fds = 1;\n \t}\n \n-\twhile (pack_max_fds <= pack_open_fds && close_one_pack())\n+\twhile (pack_max_fds <= pack_open_fds && close_one_pack(p->r))\n \t\t; /* nothing */\n \n \tp->pack_fd = git_open(p->pack_name);\n@@ -610,7 +610,8 @@ static int open_packed_git(struct packed_git *p)\n \treturn -1;\n }\n \n-static int in_window(struct pack_window *win, off_t offset)\n+static int in_window(struct repository *r, struct pack_window *win,\n+\t\t     off_t offset)\n {\n \t/* We must promise at least one full hash after the\n \t * offset is available from this window, otherwise the offset\n@@ -620,7 +621,7 @@ static int in_window(struct pack_window *win, off_t offset)\n \t */\n \toff_t win_off = win->offset;\n \treturn win_off <= offset\n-\t\t&& (offset + the_hash_algo->rawsz) <= (win_off + win->len);\n+\t\t&& (offset + r->hash_algo->rawsz) <= (win_off + win->len);\n }\n \n unsigned char *use_pack(struct packed_git *p,\n@@ -642,11 +643,11 @@ unsigned char *use_pack(struct packed_git *p,\n \tif (offset < 0)\n \t\tdie(_(\"offset before end of packfile (broken .idx?)\"));\n \n-\tif (!win || !in_window(win, offset)) {\n+\tif (!win || !in_window(p->r, win, offset)) {\n \t\tif (win)\n \t\t\twin->inuse_cnt--;\n \t\tfor (win = p->windows; win; win = win->next) {\n-\t\t\tif (in_window(win, offset))\n+\t\t\tif (in_window(p->r, win, offset))\n \t\t\t\tbreak;\n \t\t}\n \t\tif (!win) {\n-- \n2.47.0\n\n"},{"id":"506322","messageId":"5350b4f9fb4eff5f0b24468cf3f8b29321b33c9d.1730297934.git.karthik.188@gmail.com","threadId":"62424","inReplyTo":"cover.1730297934.git.karthik.188@gmail.com","subject":"[PATCH v3 2/9] packfile: use `repository` from `packed_git` directly","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-10-30T14:32:27Z","receivedAt":"2024-10-30T14:32:43Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"In the previous commit, we introduced the `repository` structure inside\n`packed_git`. This provides an alternative route instead of using the\nglobal `the_repository` variable. Let's modify `packfile.c` now to use\nthis field wherever possible instead of relying on the global state.\nThere are still a few instances of `the_repository` usage in the file,\nwhere there is no struct `packed_git` locally available, which will be\nfixed in the following commits.\n\nHelped-by: Taylor Blau <me@ttaylorr.com>\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n packfile.c | 50 +++++++++++++++++++++++++++-----------------------\n 1 file changed, 27 insertions(+), 23 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex 1423f23f57..ecb284fd98 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -79,7 +79,7 @@ static int check_packed_git_idx(const char *path, struct packed_git *p)\n \tsize_t idx_size;\n \tint fd = git_open(path), ret;\n \tstruct stat st;\n-\tconst unsigned int hashsz = the_hash_algo->rawsz;\n+\tconst unsigned int hashsz = p->r->hash_algo->rawsz;\n \n \tif (fd < 0)\n \t\treturn -1;\n@@ -243,7 +243,7 @@ struct packed_git *parse_pack_index(struct repository *r, unsigned char *sha1,\n \n \tmemcpy(p->pack_name, path, alloc); /* includes NUL */\n \tfree(path);\n-\thashcpy(p->hash, sha1, the_repository->hash_algo);\n+\thashcpy(p->hash, sha1, p->r->hash_algo);\n \tif (check_packed_git_idx(idx_path, p)) {\n \t\tfree(p);\n \t\treturn NULL;\n@@ -278,7 +278,7 @@ static int unuse_one_window(struct packed_git *current)\n \n \tif (current)\n \t\tscan_windows(current, &lru_p, &lru_w, &lru_l);\n-\tfor (p = the_repository->objects->packed_git; p; p = p->next)\n+\tfor (p = current->r->objects->packed_git; p; p = p->next)\n \t\tscan_windows(p, &lru_p, &lru_w, &lru_l);\n \tif (lru_p) {\n \t\tmunmap(lru_w->base, lru_w->len);\n@@ -540,7 +540,7 @@ static int open_packed_git_1(struct packed_git *p)\n \tunsigned char hash[GIT_MAX_RAWSZ];\n \tunsigned char *idx_hash;\n \tssize_t read_result;\n-\tconst unsigned hashsz = the_hash_algo->rawsz;\n+\tconst unsigned hashsz = p->r->hash_algo->rawsz;\n \n \tif (open_pack_index(p))\n \t\treturn error(\"packfile %s index unavailable\", p->pack_name);\n@@ -597,7 +597,7 @@ static int open_packed_git_1(struct packed_git *p)\n \tif (read_result != hashsz)\n \t\treturn error(\"packfile %s signature is unavailable\", p->pack_name);\n \tidx_hash = ((unsigned char *)p->index_data) + p->index_size - hashsz * 2;\n-\tif (!hasheq(hash, idx_hash, the_repository->hash_algo))\n+\tif (!hasheq(hash, idx_hash, p->r->hash_algo))\n \t\treturn error(\"packfile %s does not match index\", p->pack_name);\n \treturn 0;\n }\n@@ -637,7 +637,7 @@ unsigned char *use_pack(struct packed_git *p,\n \t */\n \tif (!p->pack_size && p->pack_fd == -1 && open_packed_git(p))\n \t\tdie(\"packfile %s cannot be accessed\", p->pack_name);\n-\tif (offset > (p->pack_size - the_hash_algo->rawsz))\n+\tif (offset > (p->pack_size - p->r->hash_algo->rawsz))\n \t\tdie(\"offset beyond end of packfile (truncated pack?)\");\n \tif (offset < 0)\n \t\tdie(_(\"offset before end of packfile (broken .idx?)\"));\n@@ -711,6 +711,7 @@ struct packed_git *add_packed_git(struct repository *r, const char *path,\n \tstruct stat st;\n \tsize_t alloc;\n \tstruct packed_git *p;\n+\tstruct object_id oid;\n \n \t/*\n \t * Make sure a corresponding .pack file exists and that\n@@ -751,9 +752,13 @@ struct packed_git *add_packed_git(struct repository *r, const char *path,\n \tp->pack_size = st.st_size;\n \tp->pack_local = local;\n \tp->mtime = st.st_mtime;\n-\tif (path_len < the_hash_algo->hexsz ||\n-\t    get_hash_hex(path + path_len - the_hash_algo->hexsz, p->hash))\n-\t\thashclr(p->hash, the_repository->hash_algo);\n+\tif (path_len < r->hash_algo->hexsz ||\n+\t    get_oid_hex_algop(path + path_len - r->hash_algo->hexsz, &oid,\n+\t\t\t      r->hash_algo))\n+\t\thashclr(p->hash, r->hash_algo);\n+\telse\n+\t\thashcpy(p->hash, oid.hash, r->hash_algo);\n+\n \treturn p;\n }\n \n@@ -1243,9 +1248,9 @@ off_t get_delta_base(struct packed_git *p,\n \t} else if (type == OBJ_REF_DELTA) {\n \t\t/* The base entry _must_ be in the same pack */\n \t\tstruct object_id oid;\n-\t\toidread(&oid, base_info, the_repository->hash_algo);\n+\t\toidread(&oid, base_info, p->r->hash_algo);\n \t\tbase_offset = find_pack_entry_one(&oid, p);\n-\t\t*curpos += the_hash_algo->rawsz;\n+\t\t*curpos += p->r->hash_algo->rawsz;\n \t} else\n \t\tdie(\"I am totally screwed\");\n \treturn base_offset;\n@@ -1266,7 +1271,7 @@ static int get_delta_base_oid(struct packed_git *p,\n {\n \tif (type == OBJ_REF_DELTA) {\n \t\tunsigned char *base = use_pack(p, w_curs, curpos, NULL);\n-\t\toidread(oid, base, the_repository->hash_algo);\n+\t\toidread(oid, base, p->r->hash_algo);\n \t\treturn 0;\n \t} else if (type == OBJ_OFS_DELTA) {\n \t\tuint32_t base_pos;\n@@ -1608,7 +1613,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,\n \t\t\t\tgoto out;\n \t\t\t}\n \t\t} else\n-\t\t\toidclr(oi->delta_base_oid, the_repository->hash_algo);\n+\t\t\toidclr(oi->delta_base_oid, p->r->hash_algo);\n \t}\n \n \toi->whence = in_delta_base_cache(p, obj_offset) ? OI_DBCACHED :\n@@ -1897,7 +1902,7 @@ int bsearch_pack(const struct object_id *oid, const struct packed_git *p, uint32\n {\n \tconst unsigned char *index_fanout = p->index_data;\n \tconst unsigned char *index_lookup;\n-\tconst unsigned int hashsz = the_hash_algo->rawsz;\n+\tconst unsigned int hashsz = p->r->hash_algo->rawsz;\n \tint index_lookup_width;\n \n \tif (!index_fanout)\n@@ -1922,7 +1927,7 @@ int nth_packed_object_id(struct object_id *oid,\n \t\t\t uint32_t n)\n {\n \tconst unsigned char *index = p->index_data;\n-\tconst unsigned int hashsz = the_hash_algo->rawsz;\n+\tconst unsigned int hashsz = p->r->hash_algo->rawsz;\n \tif (!index) {\n \t\tif (open_pack_index(p))\n \t\t\treturn -1;\n@@ -1933,11 +1938,10 @@ int nth_packed_object_id(struct object_id *oid,\n \tindex += 4 * 256;\n \tif (p->index_version == 1) {\n \t\toidread(oid, index + st_add(st_mult(hashsz + 4, n), 4),\n-\t\t\tthe_repository->hash_algo);\n+\t\t\tp->r->hash_algo);\n \t} else {\n \t\tindex += 8;\n-\t\toidread(oid, index + st_mult(hashsz, n),\n-\t\t\tthe_repository->hash_algo);\n+\t\toidread(oid, index + st_mult(hashsz, n), p->r->hash_algo);\n \t}\n \treturn 0;\n }\n@@ -1959,7 +1963,7 @@ void check_pack_index_ptr(const struct packed_git *p, const void *vptr)\n off_t nth_packed_object_offset(const struct packed_git *p, uint32_t n)\n {\n \tconst unsigned char *index = p->index_data;\n-\tconst unsigned int hashsz = the_hash_algo->rawsz;\n+\tconst unsigned int hashsz = p->r->hash_algo->rawsz;\n \tindex += 4 * 256;\n \tif (p->index_version == 1) {\n \t\treturn ntohl(*((uint32_t *)(index + st_mult(hashsz + 4, n))));\n@@ -2159,7 +2163,7 @@ int for_each_object_in_pack(struct packed_git *p,\n \tint r = 0;\n \n \tif (flags & FOR_EACH_OBJECT_PACK_ORDER) {\n-\t\tif (load_pack_revindex(the_repository, p))\n+\t\tif (load_pack_revindex(p->r, p))\n \t\t\treturn -1;\n \t}\n \n@@ -2227,7 +2231,7 @@ int for_each_packed_object(each_packed_object_fn cb, void *data,\n }\n \n static int add_promisor_object(const struct object_id *oid,\n-\t\t\t       struct packed_git *pack UNUSED,\n+\t\t\t       struct packed_git *pack,\n \t\t\t       uint32_t pos UNUSED,\n \t\t\t       void *set_)\n {\n@@ -2235,12 +2239,12 @@ static int add_promisor_object(const struct object_id *oid,\n \tstruct object *obj;\n \tint we_parsed_object;\n \n-\tobj = lookup_object(the_repository, oid);\n+\tobj = lookup_object(pack->r, oid);\n \tif (obj && obj->parsed) {\n \t\twe_parsed_object = 0;\n \t} else {\n \t\twe_parsed_object = 1;\n-\t\tobj = parse_object(the_repository, oid);\n+\t\tobj = parse_object(pack->r, oid);\n \t}\n \n \tif (!obj)\n-- \n2.47.0\n\n"},{"id":"506323","messageId":"13a166fcca0985b2efe476548f9bc2f950d1d41b.1730297934.git.karthik.188@gmail.com","threadId":"62424","inReplyTo":"cover.1730297934.git.karthik.188@gmail.com","subject":"[PATCH v3 4/9] packfile: pass down repository to `odb_pack_name`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-10-30T14:32:29Z","receivedAt":"2024-10-30T14:32:44Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The function `odb_pack_name` currently relies on the global variable\n`the_repository`. To eliminate global variable usage in `packfile.c`, we\nshould progressively shift the dependency on the_repository to higher\nlayers.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n builtin/fast-import.c    | 8 ++++----\n builtin/index-pack.c     | 4 ++--\n builtin/pack-redundant.c | 2 +-\n http.c                   | 2 +-\n packfile.c               | 9 ++++-----\n packfile.h               | 3 ++-\n 6 files changed, 14 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/fast-import.c b/builtin/fast-import.c\nindex f8d3d7e0c7..2ca8198153 100644\n--- a/builtin/fast-import.c\n+++ b/builtin/fast-import.c\n@@ -806,7 +806,7 @@ static char *keep_pack(const char *curr_index_name)\n \tstruct strbuf name = STRBUF_INIT;\n \tint keep_fd;\n \n-\todb_pack_name(&name, pack_data->hash, \"keep\");\n+\todb_pack_name(pack_data->r, &name, pack_data->hash, \"keep\");\n \tkeep_fd = odb_pack_keep(name.buf);\n \tif (keep_fd < 0)\n \t\tdie_errno(\"cannot create keep file\");\n@@ -814,11 +814,11 @@ static char *keep_pack(const char *curr_index_name)\n \tif (close(keep_fd))\n \t\tdie_errno(\"failed to write keep file\");\n \n-\todb_pack_name(&name, pack_data->hash, \"pack\");\n+\todb_pack_name(pack_data->r, &name, pack_data->hash, \"pack\");\n \tif (finalize_object_file(pack_data->pack_name, name.buf))\n \t\tdie(\"cannot store pack file\");\n \n-\todb_pack_name(&name, pack_data->hash, \"idx\");\n+\todb_pack_name(pack_data->r, &name, pack_data->hash, \"idx\");\n \tif (finalize_object_file(curr_index_name, name.buf))\n \t\tdie(\"cannot store index file\");\n \tfree((void *)curr_index_name);\n@@ -832,7 +832,7 @@ static void unkeep_all_packs(void)\n \n \tfor (k = 0; k < pack_id; k++) {\n \t\tstruct packed_git *p = all_packs[k];\n-\t\todb_pack_name(&name, p->hash, \"keep\");\n+\t\todb_pack_name(p->r, &name, p->hash, \"keep\");\n \t\tunlink_or_warn(name.buf);\n \t}\n \tstrbuf_release(&name);\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex be2f99625e..eaefb41761 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -1479,7 +1479,7 @@ static void write_special_file(const char *suffix, const char *msg,\n \tif (pack_name)\n \t\tfilename = derive_filename(pack_name, \"pack\", suffix, &name_buf);\n \telse\n-\t\tfilename = odb_pack_name(&name_buf, hash, suffix);\n+\t\tfilename = odb_pack_name(the_repository, &name_buf, hash, suffix);\n \n \tfd = odb_pack_keep(filename);\n \tif (fd < 0) {\n@@ -1507,7 +1507,7 @@ static void rename_tmp_packfile(const char **final_name,\n {\n \tif (!*final_name || strcmp(*final_name, curr_name)) {\n \t\tif (!*final_name)\n-\t\t\t*final_name = odb_pack_name(name, hash, ext);\n+\t\t\t*final_name = odb_pack_name(the_repository, name, hash, ext);\n \t\tif (finalize_object_file(curr_name, *final_name))\n \t\t\tdie(_(\"unable to rename temporary '*.%s' file to '%s'\"),\n \t\t\t    ext, *final_name);\ndiff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c\nindex d2c1c4e5ec..01d1362c5b 100644\n--- a/builtin/pack-redundant.c\n+++ b/builtin/pack-redundant.c\n@@ -690,7 +690,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s\n \tpl = red = pack_list_difference(local_packs, min);\n \twhile (pl) {\n \t\tprintf(\"%s\\n%s\\n\",\n-\t\t       odb_pack_name(&idx_name, pl->pack->hash, \"idx\"),\n+\t\t       odb_pack_name(pl->pack->r, &idx_name, pl->pack->hash, \"idx\"),\n \t\t       pl->pack->pack_name);\n \t\tpl = pl->next;\n \t}\ndiff --git a/http.c b/http.c\nindex 7e5be05207..50d8811cea 100644\n--- a/http.c\n+++ b/http.c\n@@ -2579,7 +2579,7 @@ struct http_pack_request *new_direct_http_pack_request(\n \n \tpreq->url = url;\n \n-\todb_pack_name(&preq->tmpfile, packed_git_hash, \"pack\");\n+\todb_pack_name(the_repository, &preq->tmpfile, packed_git_hash, \"pack\");\n \tstrbuf_addstr(&preq->tmpfile, \".temp\");\n \tpreq->packfile = fopen(preq->tmpfile.buf, \"a\");\n \tif (!preq->packfile) {\ndiff --git a/packfile.c b/packfile.c\nindex a391474031..ce701255dd 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -25,13 +25,12 @@\n #include \"pack-revindex.h\"\n #include \"promisor-remote.h\"\n \n-char *odb_pack_name(struct strbuf *buf,\n-\t\t    const unsigned char *hash,\n-\t\t    const char *ext)\n+char *odb_pack_name(struct repository *r, struct strbuf *buf,\n+\t\t    const unsigned char *hash, const char *ext)\n {\n \tstrbuf_reset(buf);\n-\tstrbuf_addf(buf, \"%s/pack/pack-%s.%s\", repo_get_object_directory(the_repository),\n-\t\t    hash_to_hex(hash), ext);\n+\tstrbuf_addf(buf, \"%s/pack/pack-%s.%s\", repo_get_object_directory(r),\n+\t\t    hash_to_hex_algop(hash, r->hash_algo), ext);\n \treturn buf->buf;\n }\n \ndiff --git a/packfile.h b/packfile.h\nindex aee69d1a0b..51187f2393 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -29,7 +29,8 @@ struct pack_entry {\n  *\n  * Example: odb_pack_name(out, sha1, \"idx\") => \".git/objects/pack/pack-1234..idx\"\n  */\n-char *odb_pack_name(struct strbuf *buf, const unsigned char *sha1, const char *ext);\n+char *odb_pack_name(struct repository *r, struct strbuf *buf,\n+\t\t    const unsigned char *hash, const char *ext);\n \n /*\n  * Return the basename of the packfile, omitting any containing directory\n-- \n2.47.0\n\n"},{"id":"506324","messageId":"1fac06f19e482863cb64d30015c87c42a3993d64.1730297934.git.karthik.188@gmail.com","threadId":"62424","inReplyTo":"cover.1730297934.git.karthik.188@gmail.com","subject":"[PATCH v3 5/9] packfile: pass down repository to `has_object[_kept]_pack`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-10-30T14:32:30Z","receivedAt":"2024-10-30T14:32:44Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The functions `has_object[_kept]_pack` currently rely on the global\nvariable `the_repository`. To eliminate global variable usage in\n`packfile.c`, we should progressively shift the dependency on\nthe_repository to higher layers. Let's remove its usage from these\nfunctions and any related ones.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n builtin/count-objects.c | 2 +-\n builtin/fsck.c          | 2 +-\n builtin/pack-objects.c  | 4 ++--\n diff.c                  | 3 ++-\n list-objects.c          | 3 ++-\n pack-bitmap.c           | 2 +-\n packfile.c              | 9 +++++----\n packfile.h              | 5 +++--\n prune-packed.c          | 2 +-\n reachable.c             | 2 +-\n revision.c              | 4 ++--\n 11 files changed, 21 insertions(+), 17 deletions(-)\n\ndiff --git a/builtin/count-objects.c b/builtin/count-objects.c\nindex 04d80887e0..1e89148ed7 100644\n--- a/builtin/count-objects.c\n+++ b/builtin/count-objects.c\n@@ -67,7 +67,7 @@ static int count_loose(const struct object_id *oid, const char *path,\n \telse {\n \t\tloose_size += on_disk_bytes(st);\n \t\tloose++;\n-\t\tif (verbose && has_object_pack(oid))\n+\t\tif (verbose && has_object_pack(the_repository, oid))\n \t\t\tpacked_loose++;\n \t}\n \treturn 0;\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 7f4e2f0414..bb56eb98ac 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -272,7 +272,7 @@ static void check_reachable_object(struct object *obj)\n \tif (!(obj->flags & HAS_OBJ)) {\n \t\tif (is_promisor_object(&obj->oid))\n \t\t\treturn;\n-\t\tif (has_object_pack(&obj->oid))\n+\t\tif (has_object_pack(the_repository, &obj->oid))\n \t\t\treturn; /* it is in pack - forget about it */\n \t\tprintf_ln(_(\"missing %s %s\"),\n \t\t\t  printable_type(&obj->oid, obj->type),\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 0800714267..ceb7e76b10 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -1529,7 +1529,7 @@ static int want_found_object(const struct object_id *oid, int exclude,\n \t\t\treturn 0;\n \t\tif (ignore_packed_keep_in_core && p->pack_keep_in_core)\n \t\t\treturn 0;\n-\t\tif (has_object_kept_pack(oid, flags))\n+\t\tif (has_object_kept_pack(p->r, oid, flags))\n \t\t\treturn 0;\n \t}\n \n@@ -3627,7 +3627,7 @@ static void show_cruft_commit(struct commit *commit, void *data)\n \n static int cruft_include_check_obj(struct object *obj, void *data UNUSED)\n {\n-\treturn !has_object_kept_pack(&obj->oid, IN_CORE_KEEP_PACKS);\n+\treturn !has_object_kept_pack(to_pack.repo, &obj->oid, IN_CORE_KEEP_PACKS);\n }\n \n static int cruft_include_check(struct commit *commit, void *data)\ndiff --git a/diff.c b/diff.c\nindex dceac20d18..266ddf18e7 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -4041,7 +4041,8 @@ static int reuse_worktree_file(struct index_state *istate,\n \t * objects however would tend to be slower as they need\n \t * to be individually opened and inflated.\n \t */\n-\tif (!FAST_WORKING_DIRECTORY && !want_file && has_object_pack(oid))\n+\tif (!FAST_WORKING_DIRECTORY && !want_file &&\n+\t    has_object_pack(istate->repo, oid))\n \t\treturn 0;\n \n \t/*\ndiff --git a/list-objects.c b/list-objects.c\nindex 985d008799..31236a8dc9 100644\n--- a/list-objects.c\n+++ b/list-objects.c\n@@ -41,7 +41,8 @@ static void show_object(struct traversal_context *ctx,\n {\n \tif (!ctx->show_object)\n \t\treturn;\n-\tif (ctx->revs->unpacked && has_object_pack(&object->oid))\n+\tif (ctx->revs->unpacked && has_object_pack(ctx->revs->repo,\n+\t\t\t\t\t\t   &object->oid))\n \t\treturn;\n \n \tctx->show_object(object, name, ctx->show_data);\ndiff --git a/pack-bitmap.c b/pack-bitmap.c\nindex 4fa9dfc771..d34ba9909a 100644\n--- a/pack-bitmap.c\n+++ b/pack-bitmap.c\n@@ -1889,7 +1889,7 @@ static void filter_packed_objects_from_bitmap(struct bitmap_index *bitmap_git,\n \t\tbitmap_unset(result, i);\n \n \tfor (i = 0; i < eindex->count; ++i) {\n-\t\tif (has_object_pack(&eindex->objects[i]->oid))\n+\t\tif (has_object_pack(the_repository, &eindex->objects[i]->oid))\n \t\t\tbitmap_unset(result, objects_nr + i);\n \t}\n }\ndiff --git a/packfile.c b/packfile.c\nindex ce701255dd..3894646573 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -2143,16 +2143,17 @@ int find_kept_pack_entry(struct repository *r,\n \treturn 0;\n }\n \n-int has_object_pack(const struct object_id *oid)\n+int has_object_pack(struct repository *r, const struct object_id *oid)\n {\n \tstruct pack_entry e;\n-\treturn find_pack_entry(the_repository, oid, &e);\n+\treturn find_pack_entry(r, oid, &e);\n }\n \n-int has_object_kept_pack(const struct object_id *oid, unsigned flags)\n+int has_object_kept_pack(struct repository *r, const struct object_id *oid,\n+\t\t\t unsigned flags)\n {\n \tstruct pack_entry e;\n-\treturn find_kept_pack_entry(the_repository, oid, flags, &e);\n+\treturn find_kept_pack_entry(r, oid, flags, &e);\n }\n \n int for_each_object_in_pack(struct packed_git *p,\ndiff --git a/packfile.h b/packfile.h\nindex 51187f2393..b09fb2c530 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -193,8 +193,9 @@ const struct packed_git *has_packed_and_bad(struct repository *, const struct ob\n int find_pack_entry(struct repository *r, const struct object_id *oid, struct pack_entry *e);\n int find_kept_pack_entry(struct repository *r, const struct object_id *oid, unsigned flags, struct pack_entry *e);\n \n-int has_object_pack(const struct object_id *oid);\n-int has_object_kept_pack(const struct object_id *oid, unsigned flags);\n+int has_object_pack(struct repository *r, const struct object_id *oid);\n+int has_object_kept_pack(struct repository *r, const struct object_id *oid,\n+\t\t\t unsigned flags);\n \n /*\n  * Return 1 if an object in a promisor packfile is or refers to the given\ndiff --git a/prune-packed.c b/prune-packed.c\nindex 2bb99c29df..d1c65ab10e 100644\n--- a/prune-packed.c\n+++ b/prune-packed.c\n@@ -24,7 +24,7 @@ static int prune_object(const struct object_id *oid, const char *path,\n {\n \tint *opts = data;\n \n-\tif (!has_object_pack(oid))\n+\tif (!has_object_pack(the_repository, oid))\n \t\treturn 0;\n \n \tif (*opts & PRUNE_PACKED_DRY_RUN)\ndiff --git a/reachable.c b/reachable.c\nindex 3e9b3dd0a4..09d2c50079 100644\n--- a/reachable.c\n+++ b/reachable.c\n@@ -239,7 +239,7 @@ static int want_recent_object(struct recent_data *data,\n \t\t\t      const struct object_id *oid)\n {\n \tif (data->ignore_in_core_kept_packs &&\n-\t    has_object_kept_pack(oid, IN_CORE_KEEP_PACKS))\n+\t    has_object_kept_pack(data->revs->repo, oid, IN_CORE_KEEP_PACKS))\n \t\treturn 0;\n \treturn 1;\n }\ndiff --git a/revision.c b/revision.c\nindex f5f5b84f2b..d1d152a67b 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -4103,10 +4103,10 @@ enum commit_action get_commit_action(struct rev_info *revs, struct commit *commi\n {\n \tif (commit->object.flags & SHOWN)\n \t\treturn commit_ignore;\n-\tif (revs->unpacked && has_object_pack(&commit->object.oid))\n+\tif (revs->unpacked && has_object_pack(revs->repo, &commit->object.oid))\n \t\treturn commit_ignore;\n \tif (revs->no_kept_objects) {\n-\t\tif (has_object_kept_pack(&commit->object.oid,\n+\t\tif (has_object_kept_pack(revs->repo, &commit->object.oid,\n \t\t\t\t\t revs->keep_pack_cache_flags))\n \t\t\treturn commit_ignore;\n \t}\n-- \n2.47.0\n\n"},{"id":"506325","messageId":"6e5951ceea2062893decc43c6155ad14abc3a48d.1730297934.git.karthik.188@gmail.com","threadId":"62424","inReplyTo":"cover.1730297934.git.karthik.188@gmail.com","subject":"[PATCH v3 7/9] config: make `delta_base_cache_limit` a non-global variable","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-10-30T14:32:32Z","receivedAt":"2024-10-30T14:32:46Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The `delta_base_cache_limit` variable is a global config variable used\nby multiple subsystems. Let's make this non-global, by adding this\nvariable to the stack of each of the subsystems where it is used.\n\nIn `gc.c` we add it to the `gc_config` struct and also the constructor\nfunction. In `index-pack.c` we add it to the `pack_idx_option` struct\nand its constructor. Finally, in `packfile.c` we dynamically retrieve\nthis value from the repository config, since the value is only used once\nin the entire subsystem.\n\nThese changes are made to remove the usage of `delta_base_cache_limit`\nas a global variable in `packfile.c`. This brings us one step closer to\nremoving the `USE_THE_REPOSITORY_VARIABLE` definition in `packfile.c`\nwhich we complete in the next patch.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n builtin/gc.c         |  5 ++++-\n builtin/index-pack.c | 10 +++++++---\n config.c             |  5 -----\n environment.c        |  1 -\n environment.h        |  1 -\n pack-objects.h       |  3 ++-\n pack-write.c         |  1 +\n pack.h               |  1 +\n packfile.c           | 13 +++++++++++--\n 9 files changed, 26 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/gc.c b/builtin/gc.c\nindex d52735354c..9a10eb58bc 100644\n--- a/builtin/gc.c\n+++ b/builtin/gc.c\n@@ -138,6 +138,7 @@ struct gc_config {\n \tchar *repack_filter_to;\n \tunsigned long big_pack_threshold;\n \tunsigned long max_delta_cache_size;\n+\tunsigned long delta_base_cache_limit;\n };\n \n #define GC_CONFIG_INIT { \\\n@@ -153,6 +154,7 @@ struct gc_config {\n \t.prune_expire = xstrdup(\"2.weeks.ago\"), \\\n \t.prune_worktrees_expire = xstrdup(\"3.months.ago\"), \\\n \t.max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE, \\\n+\t.delta_base_cache_limit = DEFAULT_DELTA_BASE_CACHE_LIMIT, \\\n }\n \n static void gc_config_release(struct gc_config *cfg)\n@@ -205,6 +207,7 @@ static void gc_config(struct gc_config *cfg)\n \n \tgit_config_get_ulong(\"gc.bigpackthreshold\", &cfg->big_pack_threshold);\n \tgit_config_get_ulong(\"pack.deltacachesize\", &cfg->max_delta_cache_size);\n+\tgit_config_get_ulong(\"core.deltabasecachelimit\", &cfg->delta_base_cache_limit);\n \n \tif (!git_config_get_string(\"gc.repackfilter\", &owned)) {\n \t\tfree(cfg->repack_filter);\n@@ -416,7 +419,7 @@ static uint64_t estimate_repack_memory(struct gc_config *cfg,\n \t * read_sha1_file() (either at delta calculation phase, or\n \t * writing phase) also fills up the delta base cache\n \t */\n-\theap += delta_base_cache_limit;\n+\theap += cfg->delta_base_cache_limit;\n \t/* and of course pack-objects has its own delta cache */\n \theap += cfg->max_delta_cache_size;\n \ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex eaefb41761..23bfa45403 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -1238,7 +1238,7 @@ static void parse_pack_objects(unsigned char *hash)\n  *   recursively checking if the resulting object is used as a base\n  *   for some more deltas.\n  */\n-static void resolve_deltas(void)\n+static void resolve_deltas(struct pack_idx_option *opts)\n {\n \tint i;\n \n@@ -1254,7 +1254,7 @@ static void resolve_deltas(void)\n \t\t\t\t\t  nr_ref_deltas + nr_ofs_deltas);\n \n \tnr_dispatched = 0;\n-\tbase_cache_limit = delta_base_cache_limit * nr_threads;\n+\tbase_cache_limit = opts->delta_base_cache_limit * nr_threads;\n \tif (nr_threads > 1 || getenv(\"GIT_FORCE_THREADS\")) {\n \t\tinit_thread();\n \t\twork_lock();\n@@ -1604,6 +1604,10 @@ static int git_index_pack_config(const char *k, const char *v,\n \t\telse\n \t\t\topts->flags &= ~WRITE_REV;\n \t}\n+\tif (!strcmp(k, \"core.deltabasecachelimit\")) {\n+\t\topts->delta_base_cache_limit = git_config_ulong(k, v, ctx->kvi);\n+\t\treturn 0;\n+\t}\n \treturn git_default_config(k, v, ctx, cb);\n }\n \n@@ -1930,7 +1934,7 @@ int cmd_index_pack(int argc,\n \tparse_pack_objects(pack_hash);\n \tif (report_end_of_input)\n \t\twrite_in_full(2, \"\\0\", 1);\n-\tresolve_deltas();\n+\tresolve_deltas(&opts);\n \tconclude_pack(fix_thin_pack, curr_pack, pack_hash);\n \tfree(ofs_deltas);\n \tfree(ref_deltas);\ndiff --git a/config.c b/config.c\nindex a11bb85da3..728ef98e42 100644\n--- a/config.c\n+++ b/config.c\n@@ -1515,11 +1515,6 @@ static int git_default_core_config(const char *var, const char *value,\n \t\treturn 0;\n \t}\n \n-\tif (!strcmp(var, \"core.deltabasecachelimit\")) {\n-\t\tdelta_base_cache_limit = git_config_ulong(var, value, ctx->kvi);\n-\t\treturn 0;\n-\t}\n-\n \tif (!strcmp(var, \"core.autocrlf\")) {\n \t\tif (value && !strcasecmp(value, \"input\")) {\n \t\t\tauto_crlf = AUTO_CRLF_INPUT;\ndiff --git a/environment.c b/environment.c\nindex a2ce998081..8e5022c282 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -51,7 +51,6 @@ enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT;\n enum fsync_component fsync_components = FSYNC_COMPONENTS_DEFAULT;\n size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;\n size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;\n-size_t delta_base_cache_limit = 96 * 1024 * 1024;\n unsigned long big_file_threshold = 512 * 1024 * 1024;\n char *editor_program;\n char *askpass_program;\ndiff --git a/environment.h b/environment.h\nindex 923e12661e..2f43340f0b 100644\n--- a/environment.h\n+++ b/environment.h\n@@ -165,7 +165,6 @@ extern int zlib_compression_level;\n extern int pack_compression_level;\n extern size_t packed_git_window_size;\n extern size_t packed_git_limit;\n-extern size_t delta_base_cache_limit;\n extern unsigned long big_file_threshold;\n extern unsigned long pack_size_limit_cfg;\n extern int max_allowed_tree_depth;\ndiff --git a/pack-objects.h b/pack-objects.h\nindex b9898a4e64..3f6f504203 100644\n--- a/pack-objects.h\n+++ b/pack-objects.h\n@@ -7,7 +7,8 @@\n \n struct repository;\n \n-#define DEFAULT_DELTA_CACHE_SIZE (256 * 1024 * 1024)\n+#define DEFAULT_DELTA_CACHE_SIZE       (256 * 1024 * 1024)\n+#define DEFAULT_DELTA_BASE_CACHE_LIMIT (96 * 1024 * 1024)\n \n #define OE_DFS_STATE_BITS\t2\n #define OE_DEPTH_BITS\t\t12\ndiff --git a/pack-write.c b/pack-write.c\nindex 8c7dfddc5a..98a8c0e785 100644\n--- a/pack-write.c\n+++ b/pack-write.c\n@@ -21,6 +21,7 @@ void reset_pack_idx_option(struct pack_idx_option *opts)\n \tmemset(opts, 0, sizeof(*opts));\n \topts->version = 2;\n \topts->off32_limit = 0x7fffffff;\n+\topts->delta_base_cache_limit = DEFAULT_DELTA_BASE_CACHE_LIMIT;\n }\n \n static int sha1_compare(const void *_a, const void *_b)\ndiff --git a/pack.h b/pack.h\nindex 02bbdfb19c..1a33751565 100644\n--- a/pack.h\n+++ b/pack.h\n@@ -58,6 +58,7 @@ struct pack_idx_option {\n \t */\n \tint anomaly_alloc, anomaly_nr;\n \tuint32_t *anomaly;\n+\tunsigned long delta_base_cache_limit;\n };\n \n void reset_pack_idx_option(struct pack_idx_option *);\ndiff --git a/packfile.c b/packfile.c\nindex 9eca5a86a7..56a5c55a5d 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -24,6 +24,8 @@\n #include \"commit-graph.h\"\n #include \"pack-revindex.h\"\n #include \"promisor-remote.h\"\n+#include \"config.h\"\n+#include \"pack-objects.h\"\n \n char *odb_pack_name(struct repository *r, struct strbuf *buf,\n \t\t    const unsigned char *hash, const char *ext)\n@@ -1496,7 +1498,9 @@ void clear_delta_base_cache(void)\n }\n \n static void add_delta_base_cache(struct packed_git *p, off_t base_offset,\n-\tvoid *base, unsigned long base_size, enum object_type type)\n+\t\t\t\t void *base, unsigned long base_size,\n+\t\t\t\t unsigned long delta_base_cache_limit,\n+\t\t\t\t enum object_type type)\n {\n \tstruct delta_base_cache_entry *ent;\n \tstruct list_head *lru, *tmp;\n@@ -1697,6 +1701,9 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,\n \tstruct unpack_entry_stack_ent *delta_stack = small_delta_stack;\n \tint delta_stack_nr = 0, delta_stack_alloc = UNPACK_ENTRY_STACK_PREALLOC;\n \tint base_from_cache = 0;\n+\tunsigned long delta_base_cache_limit = DEFAULT_DELTA_BASE_CACHE_LIMIT;\n+\n+\trepo_config_get_ulong(r, \"core.deltabasecachelimit\", &delta_base_cache_limit);\n \n \twrite_pack_access_log(p, obj_offset);\n \n@@ -1878,7 +1885,9 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,\n \t\t * before we are done using it.\n \t\t */\n \t\tif (!external_base)\n-\t\t\tadd_delta_base_cache(p, base_obj_offset, base, base_size, type);\n+\t\t\tadd_delta_base_cache(p, base_obj_offset, base,\n+\t\t\t\t\t     base_size, delta_base_cache_limit,\n+\t\t\t\t\t     type);\n \n \t\tfree(delta_data);\n \t\tfree(external_base);\n-- \n2.47.0\n\n"},{"id":"506326","messageId":"ec9061fbbd779185b96963c259026df602e447d6.1730297934.git.karthik.188@gmail.com","threadId":"62424","inReplyTo":"cover.1730297934.git.karthik.188@gmail.com","subject":"[PATCH v3 8/9] config: make `packed_git_(limit|window_size)` non-global variables","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-10-30T14:32:33Z","receivedAt":"2024-10-30T14:32:47Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The variables `packed_git_window_size` and `packed_git_limit` are global\nconfig variables used in the `packfile.c` file. Since it is only used in\nthis file, let's change it from being a global config variable to a\nlocal variable for the subsystem.\n\nWe do this by introducing a new local `packfile_config` struct in\n`packfile.c` and also adding the required function to parse the said\nconfig. We then use this within `packfile.c` to obtain the variables.\n\nWith this, we rid `packfile.c` from all global variable usage and this\nmeans we can also remove the `USE_THE_REPOSITORY_VARIABLE` guard from\nthe file.\n\nHelped-by: Taylor Blau <me@ttaylorr.com>\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n builtin/fast-import.c |  4 +--\n config.c              | 17 -------------\n environment.c         |  2 --\n packfile.c            | 57 +++++++++++++++++++++++++++++++++++++------\n packfile.h            |  2 +-\n 5 files changed, 52 insertions(+), 30 deletions(-)\n\ndiff --git a/builtin/fast-import.c b/builtin/fast-import.c\nindex 2ca8198153..c159cc584b 100644\n--- a/builtin/fast-import.c\n+++ b/builtin/fast-import.c\n@@ -3539,7 +3539,7 @@ static void parse_argv(void)\n int cmd_fast_import(int argc,\n \t\t    const char **argv,\n \t\t    const char *prefix,\n-\t\t    struct repository *repo UNUSED)\n+\t\t    struct repository *repo)\n {\n \tunsigned int i;\n \n@@ -3660,7 +3660,7 @@ int cmd_fast_import(int argc,\n \t\tfprintf(stderr, \"       pools:    %10lu KiB\\n\", (unsigned long)((tree_entry_allocd + fi_mem_pool.pool_alloc) /1024));\n \t\tfprintf(stderr, \"     objects:    %10\" PRIuMAX \" KiB\\n\", (alloc_count*sizeof(struct object_entry))/1024);\n \t\tfprintf(stderr, \"---------------------------------------------------------------------\\n\");\n-\t\tpack_report();\n+\t\tpack_report(repo);\n \t\tfprintf(stderr, \"---------------------------------------------------------------------\\n\");\n \t\tfprintf(stderr, \"\\n\");\n \t}\ndiff --git a/config.c b/config.c\nindex 728ef98e42..2c295f7430 100644\n--- a/config.c\n+++ b/config.c\n@@ -1493,28 +1493,11 @@ static int git_default_core_config(const char *var, const char *value,\n \t\treturn 0;\n \t}\n \n-\tif (!strcmp(var, \"core.packedgitwindowsize\")) {\n-\t\tint pgsz_x2 = getpagesize() * 2;\n-\t\tpacked_git_window_size = git_config_ulong(var, value, ctx->kvi);\n-\n-\t\t/* This value must be multiple of (pagesize * 2) */\n-\t\tpacked_git_window_size /= pgsz_x2;\n-\t\tif (packed_git_window_size < 1)\n-\t\t\tpacked_git_window_size = 1;\n-\t\tpacked_git_window_size *= pgsz_x2;\n-\t\treturn 0;\n-\t}\n-\n \tif (!strcmp(var, \"core.bigfilethreshold\")) {\n \t\tbig_file_threshold = git_config_ulong(var, value, ctx->kvi);\n \t\treturn 0;\n \t}\n \n-\tif (!strcmp(var, \"core.packedgitlimit\")) {\n-\t\tpacked_git_limit = git_config_ulong(var, value, ctx->kvi);\n-\t\treturn 0;\n-\t}\n-\n \tif (!strcmp(var, \"core.autocrlf\")) {\n \t\tif (value && !strcasecmp(value, \"input\")) {\n \t\t\tauto_crlf = AUTO_CRLF_INPUT;\ndiff --git a/environment.c b/environment.c\nindex 8e5022c282..8389a27270 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -49,8 +49,6 @@ int fsync_object_files = -1;\n int use_fsync = -1;\n enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT;\n enum fsync_component fsync_components = FSYNC_COMPONENTS_DEFAULT;\n-size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;\n-size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;\n unsigned long big_file_threshold = 512 * 1024 * 1024;\n char *editor_program;\n char *askpass_program;\ndiff --git a/packfile.c b/packfile.c\nindex 56a5c55a5d..426606585f 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n \n #include \"git-compat-util.h\"\n #include \"environment.h\"\n@@ -27,6 +26,17 @@\n #include \"config.h\"\n #include \"pack-objects.h\"\n \n+struct packfile_config {\n+\tunsigned long packed_git_window_size;\n+\tunsigned long packed_git_limit;\n+};\n+\n+#define PACKFILE_CONFIG_INIT \\\n+{ \\\n+\t.packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE, \\\n+\t.packed_git_limit = DEFAULT_PACKED_GIT_LIMIT, \\\n+}\n+\n char *odb_pack_name(struct repository *r, struct strbuf *buf,\n \t\t    const unsigned char *hash, const char *ext)\n {\n@@ -48,15 +58,41 @@ static size_t pack_mapped;\n #define SZ_FMT PRIuMAX\n static inline uintmax_t sz_fmt(size_t s) { return s; }\n \n-void pack_report(void)\n+static int packfile_config(const char *var, const char *value,\n+\t\t\t   const struct config_context *ctx, void *cb)\n+{\n+\tstruct packfile_config *config = cb;\n+\n+\tif (!strcmp(var, \"core.packedgitwindowsize\")) {\n+\t\tint pgsz_x2 = getpagesize() * 2;\n+\t\tconfig->packed_git_window_size = git_config_ulong(var, value, ctx->kvi);\n+\n+\t\t/* This value must be multiple of (pagesize * 2) */\n+\t\tconfig->packed_git_window_size /= pgsz_x2;\n+\t\tif (config->packed_git_window_size < 1)\n+\t\t\tconfig->packed_git_window_size = 1;\n+\t\tconfig->packed_git_window_size *= pgsz_x2;\n+\t\treturn 0;\n+\t} else if (!strcmp(var, \"core.packedgitlimit\")) {\n+\t\tconfig->packed_git_limit = git_config_ulong(var, value, ctx->kvi);\n+\t\treturn 0;\n+\t} else {\n+\t\treturn git_default_config(var, value, ctx, cb);\n+\t}\n+}\n+\n+void pack_report(struct repository *repo)\n {\n+\tstruct packfile_config config = PACKFILE_CONFIG_INIT;\n+\trepo_config(repo, packfile_config, &config);\n+\n \tfprintf(stderr,\n \t\t\"pack_report: getpagesize()            = %10\" SZ_FMT \"\\n\"\n \t\t\"pack_report: core.packedGitWindowSize = %10\" SZ_FMT \"\\n\"\n \t\t\"pack_report: core.packedGitLimit      = %10\" SZ_FMT \"\\n\",\n \t\tsz_fmt(getpagesize()),\n-\t\tsz_fmt(packed_git_window_size),\n-\t\tsz_fmt(packed_git_limit));\n+\t\tsz_fmt(config.packed_git_window_size),\n+\t\tsz_fmt(config.packed_git_limit));\n \tfprintf(stderr,\n \t\t\"pack_report: pack_used_ctr            = %10u\\n\"\n \t\t\"pack_report: pack_mmap_calls          = %10u\\n\"\n@@ -652,20 +688,25 @@ unsigned char *use_pack(struct packed_git *p,\n \t\t\t\tbreak;\n \t\t}\n \t\tif (!win) {\n-\t\t\tsize_t window_align = packed_git_window_size / 2;\n+\t\t\tstruct packfile_config config = PACKFILE_CONFIG_INIT;\n+\t\t\tsize_t window_align;\n \t\t\toff_t len;\n \n+\t\t\trepo_config(p->r, packfile_config, &config);\n+\t\t\twindow_align = config.packed_git_window_size / 2;\n+\n \t\t\tif (p->pack_fd == -1 && open_packed_git(p))\n \t\t\t\tdie(\"packfile %s cannot be accessed\", p->pack_name);\n \n \t\t\tCALLOC_ARRAY(win, 1);\n \t\t\twin->offset = (offset / window_align) * window_align;\n \t\t\tlen = p->pack_size - win->offset;\n-\t\t\tif (len > packed_git_window_size)\n-\t\t\t\tlen = packed_git_window_size;\n+\t\t\tif (len > config.packed_git_window_size)\n+\t\t\t\tlen = config.packed_git_window_size;\n \t\t\twin->len = (size_t)len;\n \t\t\tpack_mapped += win->len;\n-\t\t\twhile (packed_git_limit < pack_mapped\n+\n+\t\t\twhile (config.packed_git_limit < pack_mapped\n \t\t\t\t&& unuse_one_window(p))\n \t\t\t\t; /* nothing */\n \t\t\twin->base = xmmap_gently(NULL, win->len,\ndiff --git a/packfile.h b/packfile.h\nindex addb95b0c4..58104fa009 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -89,7 +89,7 @@ unsigned long repo_approximate_object_count(struct repository *r);\n struct packed_git *find_oid_pack(const struct object_id *oid,\n \t\t\t\t struct packed_git *packs);\n \n-void pack_report(void);\n+void pack_report(struct repository *repo);\n \n /*\n  * mmap the index file for the specified packfile (if it is not\n-- \n2.47.0\n\n"},{"id":"506327","messageId":"a5fb3b1a4a242e568a73e2895eeb8d77876b6d4c.1730297934.git.karthik.188@gmail.com","threadId":"62424","inReplyTo":"cover.1730297934.git.karthik.188@gmail.com","subject":"[PATCH v3 6/9] packfile: pass down repository to `for_each_packed_object`","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-10-30T14:32:31Z","receivedAt":"2024-10-30T14:32:47Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The function `for_each_packed_object` currently relies on the global\nvariable `the_repository`. To eliminate global variable usage in\n`packfile.c`, we should progressively shift the dependency on\nthe_repository to higher layers. Let's remove its usage from this\nfunction and closely related function `is_promisor_object`.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n builtin/cat-file.c     |  7 ++++---\n builtin/fsck.c         | 18 +++++++++++-------\n builtin/pack-objects.c |  7 +++++--\n builtin/repack.c       |  2 +-\n builtin/rev-list.c     |  2 +-\n commit-graph.c         |  2 +-\n fsck.c                 |  2 +-\n list-objects.c         |  4 ++--\n object-store-ll.h      |  4 ++--\n packfile.c             | 14 +++++++-------\n packfile.h             |  2 +-\n promisor-remote.c      |  2 +-\n reachable.c            |  2 +-\n revision.c             |  9 +++++----\n tag.c                  |  2 +-\n 15 files changed, 44 insertions(+), 35 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex bfdfb51c7c..d67b101c20 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -827,15 +827,16 @@ static int batch_objects(struct batch_options *opt)\n \t\t\tcb.seen = &seen;\n \n \t\t\tfor_each_loose_object(batch_unordered_loose, &cb, 0);\n-\t\t\tfor_each_packed_object(batch_unordered_packed, &cb,\n-\t\t\t\t\t       FOR_EACH_OBJECT_PACK_ORDER);\n+\t\t\tfor_each_packed_object(the_repository, batch_unordered_packed,\n+\t\t\t\t\t       &cb, FOR_EACH_OBJECT_PACK_ORDER);\n \n \t\t\toidset_clear(&seen);\n \t\t} else {\n \t\t\tstruct oid_array sa = OID_ARRAY_INIT;\n \n \t\t\tfor_each_loose_object(collect_loose_object, &sa, 0);\n-\t\t\tfor_each_packed_object(collect_packed_object, &sa, 0);\n+\t\t\tfor_each_packed_object(the_repository, collect_packed_object,\n+\t\t\t\t\t       &sa, 0);\n \n \t\t\toid_array_for_each_unique(&sa, batch_object_cb, &cb);\n \ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex bb56eb98ac..0196c54eb6 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -150,7 +150,7 @@ static int mark_object(struct object *obj, enum object_type type,\n \t\treturn 0;\n \tobj->flags |= REACHABLE;\n \n-\tif (is_promisor_object(&obj->oid))\n+\tif (is_promisor_object(the_repository, &obj->oid))\n \t\t/*\n \t\t * Further recursion does not need to be performed on this\n \t\t * object since it is a promisor object (so it does not need to\n@@ -270,7 +270,7 @@ static void check_reachable_object(struct object *obj)\n \t * do a full fsck\n \t */\n \tif (!(obj->flags & HAS_OBJ)) {\n-\t\tif (is_promisor_object(&obj->oid))\n+\t\tif (is_promisor_object(the_repository, &obj->oid))\n \t\t\treturn;\n \t\tif (has_object_pack(the_repository, &obj->oid))\n \t\t\treturn; /* it is in pack - forget about it */\n@@ -391,7 +391,10 @@ static void check_connectivity(void)\n \t\t * traversal.\n \t\t */\n \t\tfor_each_loose_object(mark_loose_unreachable_referents, NULL, 0);\n-\t\tfor_each_packed_object(mark_packed_unreachable_referents, NULL, 0);\n+\t\tfor_each_packed_object(the_repository,\n+\t\t\t\t       mark_packed_unreachable_referents,\n+\t\t\t\t       NULL,\n+\t\t\t\t       0);\n \t}\n \n \t/* Look up all the requirements, warn about missing objects.. */\n@@ -488,7 +491,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,\n \t\t\t\t\t\t     refname, timestamp);\n \t\t\tobj->flags |= USED;\n \t\t\tmark_object_reachable(obj);\n-\t\t} else if (!is_promisor_object(oid)) {\n+\t\t} else if (!is_promisor_object(the_repository, oid)) {\n \t\t\terror(_(\"%s: invalid reflog entry %s\"),\n \t\t\t      refname, oid_to_hex(oid));\n \t\t\terrors_found |= ERROR_REACHABLE;\n@@ -531,7 +534,7 @@ static int fsck_handle_ref(const char *refname, const char *referent UNUSED, con\n \n \tobj = parse_object(the_repository, oid);\n \tif (!obj) {\n-\t\tif (is_promisor_object(oid)) {\n+\t\tif (is_promisor_object(the_repository, oid)) {\n \t\t\t/*\n \t\t\t * Increment default_refs anyway, because this is a\n \t\t\t * valid ref.\n@@ -966,7 +969,8 @@ int cmd_fsck(int argc,\n \n \tif (connectivity_only) {\n \t\tfor_each_loose_object(mark_loose_for_connectivity, NULL, 0);\n-\t\tfor_each_packed_object(mark_packed_for_connectivity, NULL, 0);\n+\t\tfor_each_packed_object(the_repository,\n+\t\t\t\t       mark_packed_for_connectivity, NULL, 0);\n \t} else {\n \t\tprepare_alt_odb(the_repository);\n \t\tfor (odb = the_repository->objects->odb; odb; odb = odb->next)\n@@ -1011,7 +1015,7 @@ int cmd_fsck(int argc,\n \t\t\t\t\t\t\t   &oid);\n \n \t\t\tif (!obj || !(obj->flags & HAS_OBJ)) {\n-\t\t\t\tif (is_promisor_object(&oid))\n+\t\t\t\tif (is_promisor_object(the_repository, &oid))\n \t\t\t\t\tcontinue;\n \t\t\t\terror(_(\"%s: object missing\"), oid_to_hex(&oid));\n \t\t\t\terrors_found |= ERROR_OBJECT;\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex ceb7e76b10..755d521440 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -3858,7 +3858,8 @@ static void show_object__ma_allow_promisor(struct object *obj, const char *name,\n \t * Quietly ignore EXPECTED missing objects.  This avoids problems with\n \t * staging them now and getting an odd error later.\n \t */\n-\tif (!has_object(the_repository, &obj->oid, 0) && is_promisor_object(&obj->oid))\n+\tif (!has_object(the_repository, &obj->oid, 0) &&\n+\t    is_promisor_object(to_pack.repo, &obj->oid))\n \t\treturn;\n \n \tshow_object(obj, name, data);\n@@ -3927,7 +3928,9 @@ static int add_object_in_unpacked_pack(const struct object_id *oid,\n \n static void add_objects_in_unpacked_packs(void)\n {\n-\tif (for_each_packed_object(add_object_in_unpacked_pack, NULL,\n+\tif (for_each_packed_object(to_pack.repo,\n+\t\t\t\t   add_object_in_unpacked_pack,\n+\t\t\t\t   NULL,\n \t\t\t\t   FOR_EACH_OBJECT_PACK_ORDER |\n \t\t\t\t   FOR_EACH_OBJECT_LOCAL_ONLY |\n \t\t\t\t   FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS |\ndiff --git a/builtin/repack.c b/builtin/repack.c\nindex d6bb37e84a..96a4fa234b 100644\n--- a/builtin/repack.c\n+++ b/builtin/repack.c\n@@ -404,7 +404,7 @@ static void repack_promisor_objects(const struct pack_objects_args *args,\n \t * {type -> existing pack order} ordering when computing deltas instead\n \t * of a {type -> size} ordering, which may produce better deltas.\n \t */\n-\tfor_each_packed_object(write_oid, &cmd,\n+\tfor_each_packed_object(the_repository, write_oid, &cmd,\n \t\t\t       FOR_EACH_OBJECT_PROMISOR_ONLY);\n \n \tif (cmd.in == -1) {\ndiff --git a/builtin/rev-list.c b/builtin/rev-list.c\nindex f62bcbf2b1..43c42621e3 100644\n--- a/builtin/rev-list.c\n+++ b/builtin/rev-list.c\n@@ -121,7 +121,7 @@ static inline void finish_object__ma(struct object *obj)\n \t\treturn;\n \n \tcase MA_ALLOW_PROMISOR:\n-\t\tif (is_promisor_object(&obj->oid))\n+\t\tif (is_promisor_object(the_repository, &obj->oid))\n \t\t\treturn;\n \t\tdie(\"unexpected missing %s object '%s'\",\n \t\t    type_name(obj->type), oid_to_hex(&obj->oid));\ndiff --git a/commit-graph.c b/commit-graph.c\nindex 83dd69bfeb..e2e2083951 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -1960,7 +1960,7 @@ static void fill_oids_from_all_packs(struct write_commit_graph_context *ctx)\n \t\tctx->progress = start_delayed_progress(\n \t\t\t_(\"Finding commits for commit graph among packed objects\"),\n \t\t\tctx->approx_nr_objects);\n-\tfor_each_packed_object(add_packed_commits, ctx,\n+\tfor_each_packed_object(ctx->r, add_packed_commits, ctx,\n \t\t\t       FOR_EACH_OBJECT_PACK_ORDER);\n \tif (ctx->progress_done < ctx->approx_nr_objects)\n \t\tdisplay_progress(ctx->progress, ctx->approx_nr_objects);\ndiff --git a/fsck.c b/fsck.c\nindex 3756f52459..87ce999a49 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -1295,7 +1295,7 @@ static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done,\n \n \t\tbuf = repo_read_object_file(the_repository, oid, &type, &size);\n \t\tif (!buf) {\n-\t\t\tif (is_promisor_object(oid))\n+\t\t\tif (is_promisor_object(the_repository, oid))\n \t\t\t\tcontinue;\n \t\t\tret |= report(options,\n \t\t\t\t      oid, OBJ_BLOB, msg_missing,\ndiff --git a/list-objects.c b/list-objects.c\nindex 31236a8dc9..d11a389b3a 100644\n--- a/list-objects.c\n+++ b/list-objects.c\n@@ -75,7 +75,7 @@ static void process_blob(struct traversal_context *ctx,\n \t */\n \tif (ctx->revs->exclude_promisor_objects &&\n \t    !repo_has_object_file(the_repository, &obj->oid) &&\n-\t    is_promisor_object(&obj->oid))\n+\t    is_promisor_object(ctx->revs->repo, &obj->oid))\n \t\treturn;\n \n \tpathlen = path->len;\n@@ -180,7 +180,7 @@ static void process_tree(struct traversal_context *ctx,\n \t\t * an incomplete list of missing objects.\n \t\t */\n \t\tif (revs->exclude_promisor_objects &&\n-\t\t    is_promisor_object(&obj->oid))\n+\t\t    is_promisor_object(revs->repo, &obj->oid))\n \t\t\treturn;\n \n \t\tif (!revs->do_not_die_on_missing_objects)\ndiff --git a/object-store-ll.h b/object-store-ll.h\nindex e8a22ab5fc..ce73d9a670 100644\n--- a/object-store-ll.h\n+++ b/object-store-ll.h\n@@ -550,7 +550,7 @@ typedef int each_packed_object_fn(const struct object_id *oid,\n int for_each_object_in_pack(struct packed_git *p,\n \t\t\t    each_packed_object_fn, void *data,\n \t\t\t    enum for_each_object_flags flags);\n-int for_each_packed_object(each_packed_object_fn, void *,\n-\t\t\t   enum for_each_object_flags flags);\n+int for_each_packed_object(struct repository *repo, each_packed_object_fn cb,\n+\t\t\t   void *data, enum for_each_object_flags flags);\n \n #endif /* OBJECT_STORE_LL_H */\ndiff --git a/packfile.c b/packfile.c\nindex 3894646573..9eca5a86a7 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -2200,15 +2200,15 @@ int for_each_object_in_pack(struct packed_git *p,\n \treturn r;\n }\n \n-int for_each_packed_object(each_packed_object_fn cb, void *data,\n-\t\t\t   enum for_each_object_flags flags)\n+int for_each_packed_object(struct repository *repo, each_packed_object_fn cb,\n+\t\t\t   void *data, enum for_each_object_flags flags)\n {\n \tstruct packed_git *p;\n \tint r = 0;\n \tint pack_errors = 0;\n \n-\tprepare_packed_git(the_repository);\n-\tfor (p = get_all_packs(the_repository); p; p = p->next) {\n+\tprepare_packed_git(repo);\n+\tfor (p = get_all_packs(repo); p; p = p->next) {\n \t\tif ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)\n \t\t\tcontinue;\n \t\tif ((flags & FOR_EACH_OBJECT_PROMISOR_ONLY) &&\n@@ -2286,14 +2286,14 @@ static int add_promisor_object(const struct object_id *oid,\n \treturn 0;\n }\n \n-int is_promisor_object(const struct object_id *oid)\n+int is_promisor_object(struct repository *r, const struct object_id *oid)\n {\n \tstatic struct oidset promisor_objects;\n \tstatic int promisor_objects_prepared;\n \n \tif (!promisor_objects_prepared) {\n-\t\tif (repo_has_promisor_remote(the_repository)) {\n-\t\t\tfor_each_packed_object(add_promisor_object,\n+\t\tif (repo_has_promisor_remote(r)) {\n+\t\t\tfor_each_packed_object(r, add_promisor_object,\n \t\t\t\t\t       &promisor_objects,\n \t\t\t\t\t       FOR_EACH_OBJECT_PROMISOR_ONLY |\n \t\t\t\t\t       FOR_EACH_OBJECT_PACK_ORDER);\ndiff --git a/packfile.h b/packfile.h\nindex b09fb2c530..addb95b0c4 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -201,7 +201,7 @@ int has_object_kept_pack(struct repository *r, const struct object_id *oid,\n  * Return 1 if an object in a promisor packfile is or refers to the given\n  * object, 0 otherwise.\n  */\n-int is_promisor_object(const struct object_id *oid);\n+int is_promisor_object(struct repository *r, const struct object_id *oid);\n \n /*\n  * Expose a function for fuzz testing.\ndiff --git a/promisor-remote.c b/promisor-remote.c\nindex 9345ae3db2..c714f4f007 100644\n--- a/promisor-remote.c\n+++ b/promisor-remote.c\n@@ -283,7 +283,7 @@ void promisor_remote_get_direct(struct repository *repo,\n \t}\n \n \tfor (i = 0; i < remaining_nr; i++) {\n-\t\tif (is_promisor_object(&remaining_oids[i]))\n+\t\tif (is_promisor_object(repo, &remaining_oids[i]))\n \t\t\tdie(_(\"could not fetch %s from promisor remote\"),\n \t\t\t    oid_to_hex(&remaining_oids[i]));\n \t}\ndiff --git a/reachable.c b/reachable.c\nindex 09d2c50079..ecf7ccf504 100644\n--- a/reachable.c\n+++ b/reachable.c\n@@ -324,7 +324,7 @@ int add_unseen_recent_objects_to_traversal(struct rev_info *revs,\n \tif (ignore_in_core_kept_packs)\n \t\tflags |= FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS;\n \n-\tr = for_each_packed_object(add_recent_packed, &data, flags);\n+\tr = for_each_packed_object(revs->repo, add_recent_packed, &data, flags);\n \n done:\n \toidset_clear(&data.extra_recent_oids);\ndiff --git a/revision.c b/revision.c\nindex d1d152a67b..45dc6d2819 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -390,7 +390,8 @@ static struct object *get_reference(struct rev_info *revs, const char *name,\n \tif (!object) {\n \t\tif (revs->ignore_missing)\n \t\t\treturn NULL;\n-\t\tif (revs->exclude_promisor_objects && is_promisor_object(oid))\n+\t\tif (revs->exclude_promisor_objects &&\n+\t\t    is_promisor_object(revs->repo, oid))\n \t\t\treturn NULL;\n \t\tif (revs->do_not_die_on_missing_objects) {\n \t\t\toidset_insert(&revs->missing_commits, oid);\n@@ -432,7 +433,7 @@ static struct commit *handle_commit(struct rev_info *revs,\n \t\t\tif (revs->ignore_missing_links || (flags & UNINTERESTING))\n \t\t\t\treturn NULL;\n \t\t\tif (revs->exclude_promisor_objects &&\n-\t\t\t    is_promisor_object(&tag->tagged->oid))\n+\t\t\t    is_promisor_object(revs->repo, &tag->tagged->oid))\n \t\t\t\treturn NULL;\n \t\t\tif (revs->do_not_die_on_missing_objects && oid) {\n \t\t\t\toidset_insert(&revs->missing_commits, oid);\n@@ -1211,7 +1212,7 @@ static int process_parents(struct rev_info *revs, struct commit *commit,\n \t\t\t     revs->do_not_die_on_missing_objects;\n \t\tif (repo_parse_commit_gently(revs->repo, p, gently) < 0) {\n \t\t\tif (revs->exclude_promisor_objects &&\n-\t\t\t    is_promisor_object(&p->object.oid)) {\n+\t\t\t    is_promisor_object(revs->repo, &p->object.oid)) {\n \t\t\t\tif (revs->first_parent_only)\n \t\t\t\t\tbreak;\n \t\t\t\tcontinue;\n@@ -3915,7 +3916,7 @@ int prepare_revision_walk(struct rev_info *revs)\n \t\trevs->treesame.name = \"treesame\";\n \n \tif (revs->exclude_promisor_objects) {\n-\t\tfor_each_packed_object(mark_uninteresting, revs,\n+\t\tfor_each_packed_object(revs->repo, mark_uninteresting, revs,\n \t\t\t\t       FOR_EACH_OBJECT_PROMISOR_ONLY);\n \t}\n \ndiff --git a/tag.c b/tag.c\nindex d24170e340..beef9571b5 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -84,7 +84,7 @@ struct object *deref_tag(struct repository *r, struct object *o, const char *war\n \t\t\to = NULL;\n \t\t}\n \tif (!o && warn) {\n-\t\tif (last_oid && is_promisor_object(last_oid))\n+\t\tif (last_oid && is_promisor_object(r, last_oid))\n \t\t\treturn NULL;\n \t\tif (!warnlen)\n \t\t\twarnlen = strlen(warn);\n-- \n2.47.0\n\n"},{"id":"506328","messageId":"c0b386412d5c464aa838dbe7c7679d4c8618a2c7.1730297934.git.karthik.188@gmail.com","threadId":"62424","inReplyTo":"cover.1730297934.git.karthik.188@gmail.com","subject":"[PATCH v3 9/9] midx: add repository to `multi_pack_index` struct","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-10-30T14:32:34Z","receivedAt":"2024-10-30T14:32:48Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"The `multi_pack_index` struct represents the MIDX for a repository.\nHere, we add a pointer to the repository in this struct, allowing direct\nuse of the repository variable without relying on the global\n`the_repository` struct.\n\nWith this addition, we can determine the repository associated with a\n`bitmap_index` struct. A `bitmap_index` points to either a `packed_git`\nor a `multi_pack_index`, both of which have direct repository\nreferences. To support this, we introduce a static helper function,\n`bitmap_repo`, in `pack-bitmap.c`, which retrieves a repository given a\n`bitmap_index`.\n\nWith this, we clear up all usages of `the_repository` within\n`pack-bitmap.c` and also remove the `USE_THE_REPOSITORY_VARIABLE`\ndefinition. Bringing us another step closer to remove all global\nvariable usage.\n\nAlthough this change also opens up the potential to clean up `midx.c`,\ndoing so would require additional refactoring to pass the repository\nstruct to functions where the MIDX struct is created: a task better\nsuited for future patches.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n midx.c        |  1 +\n midx.h        |  3 ++\n pack-bitmap.c | 97 +++++++++++++++++++++++++++++++--------------------\n 3 files changed, 64 insertions(+), 37 deletions(-)\n\ndiff --git a/midx.c b/midx.c\nindex 8edb75f51d..7a34473010 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -131,6 +131,7 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir\n \tm->data = midx_map;\n \tm->data_len = midx_size;\n \tm->local = local;\n+\tm->r = the_repository;\n \n \tm->signature = get_be32(m->data);\n \tif (m->signature != MIDX_SIGNATURE)\ndiff --git a/midx.h b/midx.h\nindex 42d4f8d149..7d39fb24e9 100644\n--- a/midx.h\n+++ b/midx.h\n@@ -71,6 +71,9 @@ struct multi_pack_index {\n \n \tconst char **pack_names;\n \tstruct packed_git **packs;\n+\n+\tstruct repository *r;\n+\n \tchar object_dir[FLEX_ARRAY];\n };\n \ndiff --git a/pack-bitmap.c b/pack-bitmap.c\nindex d34ba9909a..ef9958b96e 100644\n--- a/pack-bitmap.c\n+++ b/pack-bitmap.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"git-compat-util.h\"\n #include \"commit.h\"\n #include \"gettext.h\"\n@@ -177,12 +175,21 @@ static uint32_t bitmap_num_objects(struct bitmap_index *index)\n \treturn index->pack->num_objects;\n }\n \n+static struct repository *bitmap_repo(struct bitmap_index *bitmap_git)\n+{\n+\tif (bitmap_is_midx(bitmap_git))\n+\t\treturn bitmap_git->midx->r;\n+\treturn bitmap_git->pack->r;\n+}\n+\n static int load_bitmap_header(struct bitmap_index *index)\n {\n \tstruct bitmap_disk_header *header = (void *)index->map;\n-\tsize_t header_size = sizeof(*header) - GIT_MAX_RAWSZ + the_hash_algo->rawsz;\n+\tconst struct git_hash_algo *hash_algo = bitmap_repo(index)->hash_algo;\n+\n+\tsize_t header_size = sizeof(*header) - GIT_MAX_RAWSZ + hash_algo->rawsz;\n \n-\tif (index->map_size < header_size + the_hash_algo->rawsz)\n+\tif (index->map_size < header_size + hash_algo->rawsz)\n \t\treturn error(_(\"corrupted bitmap index (too small)\"));\n \n \tif (memcmp(header->magic, BITMAP_IDX_SIGNATURE, sizeof(BITMAP_IDX_SIGNATURE)) != 0)\n@@ -196,7 +203,7 @@ static int load_bitmap_header(struct bitmap_index *index)\n \t{\n \t\tuint32_t flags = ntohs(header->options);\n \t\tsize_t cache_size = st_mult(bitmap_num_objects(index), sizeof(uint32_t));\n-\t\tunsigned char *index_end = index->map + index->map_size - the_hash_algo->rawsz;\n+\t\tunsigned char *index_end = index->map + index->map_size - hash_algo->rawsz;\n \n \t\tif ((flags & BITMAP_OPT_FULL_DAG) == 0)\n \t\t\tBUG(\"unsupported options for bitmap index file \"\n@@ -409,7 +416,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,\n \tif (bitmap_git->pack || bitmap_git->midx) {\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tget_midx_filename(&buf, midx->object_dir);\n-\t\ttrace2_data_string(\"bitmap\", the_repository,\n+\t\ttrace2_data_string(\"bitmap\", bitmap_repo(bitmap_git),\n \t\t\t\t   \"ignoring extra midx bitmap file\", buf.buf);\n \t\tclose(fd);\n \t\tstrbuf_release(&buf);\n@@ -427,7 +434,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,\n \t\tgoto cleanup;\n \n \tif (!hasheq(get_midx_checksum(bitmap_git->midx), bitmap_git->checksum,\n-\t\t    the_repository->hash_algo)) {\n+\t\t    bitmap_repo(bitmap_git)->hash_algo)) {\n \t\terror(_(\"checksum doesn't match in MIDX and bitmap\"));\n \t\tgoto cleanup;\n \t}\n@@ -438,7 +445,9 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,\n \t}\n \n \tfor (i = 0; i < bitmap_git->midx->num_packs; i++) {\n-\t\tif (prepare_midx_pack(the_repository, bitmap_git->midx, i)) {\n+\t\tif (prepare_midx_pack(bitmap_repo(bitmap_git),\n+\t\t\t\t      bitmap_git->midx,\n+\t\t\t\t      i)) {\n \t\t\twarning(_(\"could not open pack %s\"),\n \t\t\t\tbitmap_git->midx->pack_names[i]);\n \t\t\tgoto cleanup;\n@@ -492,8 +501,9 @@ static int open_pack_bitmap_1(struct bitmap_index *bitmap_git, struct packed_git\n \t}\n \n \tif (bitmap_git->pack || bitmap_git->midx) {\n-\t\ttrace2_data_string(\"bitmap\", the_repository,\n-\t\t\t\t   \"ignoring extra bitmap file\", packfile->pack_name);\n+\t\ttrace2_data_string(\"bitmap\", bitmap_repo(bitmap_git),\n+\t\t\t\t   \"ignoring extra bitmap file\",\n+\t\t\t\t   packfile->pack_name);\n \t\tclose(fd);\n \t\treturn -1;\n \t}\n@@ -518,8 +528,8 @@ static int open_pack_bitmap_1(struct bitmap_index *bitmap_git, struct packed_git\n \t\treturn -1;\n \t}\n \n-\ttrace2_data_string(\"bitmap\", the_repository, \"opened bitmap file\",\n-\t\t\t   packfile->pack_name);\n+\ttrace2_data_string(\"bitmap\", bitmap_repo(bitmap_git),\n+\t\t\t   \"opened bitmap file\", packfile->pack_name);\n \treturn 0;\n }\n \n@@ -649,7 +659,7 @@ struct bitmap_index *prepare_bitmap_git(struct repository *r)\n \n struct bitmap_index *prepare_midx_bitmap_git(struct multi_pack_index *midx)\n {\n-\tstruct repository *r = the_repository;\n+\tstruct repository *r = midx->r;\n \tstruct bitmap_index *bitmap_git = xcalloc(1, sizeof(*bitmap_git));\n \n \tif (!open_midx_bitmap_1(bitmap_git, midx) && !load_bitmap(r, bitmap_git))\n@@ -1213,6 +1223,7 @@ static struct bitmap *find_boundary_objects(struct bitmap_index *bitmap_git,\n {\n \tstruct bitmap_boundary_cb cb;\n \tstruct object_list *root;\n+\tstruct repository *repo;\n \tunsigned int i;\n \tunsigned int tmp_blobs, tmp_trees, tmp_tags;\n \tint any_missing = 0;\n@@ -1222,6 +1233,8 @@ static struct bitmap *find_boundary_objects(struct bitmap_index *bitmap_git,\n \tcb.base = bitmap_new();\n \tobject_array_init(&cb.boundary);\n \n+\trepo = bitmap_repo(bitmap_git);\n+\n \trevs->ignore_missing_links = 1;\n \n \tif (bitmap_git->pseudo_merges.nr) {\n@@ -1280,19 +1293,19 @@ static struct bitmap *find_boundary_objects(struct bitmap_index *bitmap_git,\n \t * revision walk to (a) OR in any bitmaps that are UNINTERESTING\n \t * between the tips and boundary, and (b) record the boundary.\n \t */\n-\ttrace2_region_enter(\"pack-bitmap\", \"boundary-prepare\", the_repository);\n+\ttrace2_region_enter(\"pack-bitmap\", \"boundary-prepare\", repo);\n \tif (prepare_revision_walk(revs))\n \t\tdie(\"revision walk setup failed\");\n-\ttrace2_region_leave(\"pack-bitmap\", \"boundary-prepare\", the_repository);\n+\ttrace2_region_leave(\"pack-bitmap\", \"boundary-prepare\", repo);\n \n-\ttrace2_region_enter(\"pack-bitmap\", \"boundary-traverse\", the_repository);\n+\ttrace2_region_enter(\"pack-bitmap\", \"boundary-traverse\", repo);\n \trevs->boundary = 1;\n \ttraverse_commit_list_filtered(revs,\n \t\t\t\t      show_boundary_commit,\n \t\t\t\t      show_boundary_object,\n \t\t\t\t      &cb, NULL);\n \trevs->boundary = 0;\n-\ttrace2_region_leave(\"pack-bitmap\", \"boundary-traverse\", the_repository);\n+\ttrace2_region_leave(\"pack-bitmap\", \"boundary-traverse\", repo);\n \n \trevs->blob_objects = tmp_blobs;\n \trevs->tree_objects = tmp_trees;\n@@ -1304,7 +1317,7 @@ static struct bitmap *find_boundary_objects(struct bitmap_index *bitmap_git,\n \t/*\n \t * Then add the boundary commit(s) as fill-in traversal tips.\n \t */\n-\ttrace2_region_enter(\"pack-bitmap\", \"boundary-fill-in\", the_repository);\n+\ttrace2_region_enter(\"pack-bitmap\", \"boundary-fill-in\", repo);\n \tfor (i = 0; i < cb.boundary.nr; i++) {\n \t\tstruct object *obj = cb.boundary.objects[i].item;\n \t\tif (bitmap_walk_contains(bitmap_git, cb.base, &obj->oid))\n@@ -1314,7 +1327,7 @@ static struct bitmap *find_boundary_objects(struct bitmap_index *bitmap_git,\n \t}\n \tif (revs->pending.nr)\n \t\tcb.base = fill_in_bitmap(bitmap_git, revs, cb.base, NULL);\n-\ttrace2_region_leave(\"pack-bitmap\", \"boundary-fill-in\", the_repository);\n+\ttrace2_region_leave(\"pack-bitmap\", \"boundary-fill-in\", repo);\n \n cleanup:\n \tobject_array_clear(&cb.boundary);\n@@ -1718,7 +1731,8 @@ static unsigned long get_size_by_pos(struct bitmap_index *bitmap_git,\n \t\t\tofs = pack_pos_to_offset(pack, pos);\n \t\t}\n \n-\t\tif (packed_object_info(the_repository, pack, ofs, &oi) < 0) {\n+\t\tif (packed_object_info(bitmap_repo(bitmap_git), pack, ofs,\n+\t\t\t\t       &oi) < 0) {\n \t\t\tstruct object_id oid;\n \t\t\tnth_bitmap_object_oid(bitmap_git, &oid,\n \t\t\t\t\t      pack_pos_to_index(pack, pos));\n@@ -1727,7 +1741,8 @@ static unsigned long get_size_by_pos(struct bitmap_index *bitmap_git,\n \t} else {\n \t\tstruct eindex *eindex = &bitmap_git->ext_index;\n \t\tstruct object *obj = eindex->objects[pos - bitmap_num_objects(bitmap_git)];\n-\t\tif (oid_object_info_extended(the_repository, &obj->oid, &oi, 0) < 0)\n+\t\tif (oid_object_info_extended(bitmap_repo(bitmap_git), &obj->oid,\n+\t\t\t\t\t     &oi, 0) < 0)\n \t\t\tdie(_(\"unable to get size of %s\"), oid_to_hex(&obj->oid));\n \t}\n \n@@ -1889,7 +1904,8 @@ static void filter_packed_objects_from_bitmap(struct bitmap_index *bitmap_git,\n \t\tbitmap_unset(result, i);\n \n \tfor (i = 0; i < eindex->count; ++i) {\n-\t\tif (has_object_pack(the_repository, &eindex->objects[i]->oid))\n+\t\tif (has_object_pack(bitmap_repo(bitmap_git),\n+\t\t\t\t    &eindex->objects[i]->oid))\n \t\t\tbitmap_unset(result, objects_nr + i);\n \t}\n }\n@@ -1907,6 +1923,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,\n \tstruct bitmap *haves_bitmap = NULL;\n \n \tstruct bitmap_index *bitmap_git;\n+\tstruct repository *repo;\n \n \t/*\n \t * We can't do pathspec limiting with bitmaps, because we don't know\n@@ -1980,18 +1997,23 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,\n \tif (!use_boundary_traversal)\n \t\tobject_array_clear(&revs->pending);\n \n+\trepo = bitmap_repo(bitmap_git);\n+\n \tif (haves) {\n-\t\tif (use_boundary_traversal) {\n-\t\t\ttrace2_region_enter(\"pack-bitmap\", \"haves/boundary\", the_repository);\n+\t\tif (use_boundary_traversal)\n+\t\t{\n+\t\t\ttrace2_region_enter(\"pack-bitmap\", \"haves/boundary\", repo);\n \t\t\thaves_bitmap = find_boundary_objects(bitmap_git, revs, haves);\n-\t\t\ttrace2_region_leave(\"pack-bitmap\", \"haves/boundary\", the_repository);\n-\t\t} else {\n-\t\t\ttrace2_region_enter(\"pack-bitmap\", \"haves/classic\", the_repository);\n+\t\t\ttrace2_region_leave(\"pack-bitmap\", \"haves/boundary\", repo);\n+\t\t}\n+\t\telse\n+\t\t{\n+\t\t\ttrace2_region_enter(\"pack-bitmap\", \"haves/classic\", repo);\n \t\t\trevs->ignore_missing_links = 1;\n \t\t\thaves_bitmap = find_objects(bitmap_git, revs, haves, NULL);\n \t\t\treset_revision_walk();\n \t\t\trevs->ignore_missing_links = 0;\n-\t\t\ttrace2_region_leave(\"pack-bitmap\", \"haves/classic\", the_repository);\n+\t\t\ttrace2_region_leave(\"pack-bitmap\", \"haves/classic\", repo);\n \t\t}\n \n \t\tif (!haves_bitmap)\n@@ -2025,17 +2047,17 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,\n \tobject_list_free(&wants);\n \tobject_list_free(&haves);\n \n-\ttrace2_data_intmax(\"bitmap\", the_repository, \"pseudo_merges_satisfied\",\n+\ttrace2_data_intmax(\"bitmap\", repo, \"pseudo_merges_satisfied\",\n \t\t\t   pseudo_merges_satisfied_nr);\n-\ttrace2_data_intmax(\"bitmap\", the_repository, \"pseudo_merges_cascades\",\n+\ttrace2_data_intmax(\"bitmap\", repo, \"pseudo_merges_cascades\",\n \t\t\t   pseudo_merges_cascades_nr);\n-\ttrace2_data_intmax(\"bitmap\", the_repository, \"bitmap/hits\",\n+\ttrace2_data_intmax(\"bitmap\", repo, \"bitmap/hits\",\n \t\t\t   existing_bitmaps_hits_nr);\n-\ttrace2_data_intmax(\"bitmap\", the_repository, \"bitmap/misses\",\n+\ttrace2_data_intmax(\"bitmap\", repo, \"bitmap/misses\",\n \t\t\t   existing_bitmaps_misses_nr);\n-\ttrace2_data_intmax(\"bitmap\", the_repository, \"bitmap/roots_with_bitmap\",\n+\ttrace2_data_intmax(\"bitmap\", repo, \"bitmap/roots_with_bitmap\",\n \t\t\t   roots_with_bitmaps_nr);\n-\ttrace2_data_intmax(\"bitmap\", the_repository, \"bitmap/roots_without_bitmap\",\n+\ttrace2_data_intmax(\"bitmap\", repo, \"bitmap/roots_without_bitmap\",\n \t\t\t   roots_without_bitmaps_nr);\n \n \treturn bitmap_git;\n@@ -2256,7 +2278,7 @@ void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,\n \t\t\t\t\tstruct bitmap **reuse_out,\n \t\t\t\t\tint multi_pack_reuse)\n {\n-\tstruct repository *r = the_repository;\n+\tstruct repository *r = bitmap_repo(bitmap_git);\n \tstruct bitmapped_pack *packs = NULL;\n \tstruct bitmap *result = bitmap_git->result;\n \tstruct bitmap *reuse;\n@@ -2792,7 +2814,7 @@ int rebuild_bitmap(const uint32_t *reposition,\n uint32_t *create_bitmap_mapping(struct bitmap_index *bitmap_git,\n \t\t\t\tstruct packing_data *mapping)\n {\n-\tstruct repository *r = the_repository;\n+\tstruct repository *r = bitmap_repo(bitmap_git);\n \tuint32_t i, num_objects;\n \tuint32_t *reposition;\n \n@@ -2948,7 +2970,8 @@ static off_t get_disk_usage_for_extended(struct bitmap_index *bitmap_git)\n \t\t\t\tst_add(bitmap_num_objects(bitmap_git), i)))\n \t\t\tcontinue;\n \n-\t\tif (oid_object_info_extended(the_repository, &obj->oid, &oi, 0) < 0)\n+\t\tif (oid_object_info_extended(bitmap_repo(bitmap_git), &obj->oid,\n+\t\t\t\t\t     &oi, 0) < 0)\n \t\t\tdie(_(\"unable to get disk usage of '%s'\"),\n \t\t\t    oid_to_hex(&obj->oid));\n \n-- \n2.47.0\n\n"},{"id":"506332","messageId":"ZyKQRu+1v6IJjbSR@nand.local","threadId":"62424","inReplyTo":"5afb9af0afdf6062b16dea2d1347170485e7d73e.1730297934.git.karthik.188@gmail.com","subject":"Re: [PATCH v3 1/9] packfile: add repository to struct `packed_git`","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-10-30T20:00:06Z","receivedAt":"2024-10-30T20:00:09Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Wed, Oct 30, 2024 at 03:32:26PM +0100, Karthik Nayak wrote:\n> [...]\n>\n> We do need to consider that a pack file could be part of the alternates\n> of a repository, but considering that we only have one repository struct\n> and also that we currently anyways use 'the_repository'. We should be\n> OK with this change.\n\nNicely explained.\n\n> diff --git a/object-store-ll.h b/object-store-ll.h\n> index 53b8e693b1..e8a22ab5fc 100644\n> --- a/object-store-ll.h\n> +++ b/object-store-ll.h\n> @@ -10,6 +10,7 @@\n>  struct oidmap;\n>  struct oidtree;\n>  struct strbuf;\n> +struct repository;\n>\n>  struct object_directory {\n>  \tstruct object_directory *next;\n> @@ -135,6 +136,10 @@ struct packed_git {\n>  \t */\n>  \tconst uint32_t *mtimes_map;\n>  \tsize_t mtimes_size;\n> +\n> +\t/* repo dentoes the repository this packed file belongs to */\n> +\tstruct repository *r;\n> +\n\nHmm. What I meant in my earlier suggestion was that we should leave the\nmember of the struct called \"repo\", but change the name only in function\narguments.\n\nSorry to split hairs, but I am somewhat opposed to having such a short\nvariable name in a struct. In either event, the comment should be made\nconsistent with the variable name.\n\n>  \t/* something like \".git/objects/pack/xxxxx.pack\" */\n>  \tchar pack_name[FLEX_ARRAY]; /* more */\n>  };\n> diff --git a/packfile.c b/packfile.c\n> index 9560f0a33c..1423f23f57 100644\n> --- a/packfile.c\n> +++ b/packfile.c\n> @@ -217,11 +217,12 @@ uint32_t get_pack_fanout(struct packed_git *p, uint32_t value)\n>  \treturn ntohl(level1_ofs[value]);\n>  }\n>\n> -static struct packed_git *alloc_packed_git(int extra)\n> +static struct packed_git *alloc_packed_git(struct repository *r, int extra)\n\nThis spot I would leave alone.\n\n>  {\n>  \tstruct packed_git *p = xmalloc(st_add(sizeof(*p), extra));\n>  \tmemset(p, 0, sizeof(*p));\n>  \tp->pack_fd = -1;\n> +\tp->r = r;\n\nAnd this spot I would change to:\n\n    p->repo = r;\n\nThe rest is looking good.\n\nThanks,\nTaylor\n"},{"id":"506334","messageId":"ZyKTTYGPDQ0SWJCZ@nand.local","threadId":"62424","inReplyTo":"c0b386412d5c464aa838dbe7c7679d4c8618a2c7.1730297934.git.karthik.188@gmail.com","subject":"Re: [PATCH v3 9/9] midx: add repository to `multi_pack_index` struct","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-10-30T20:13:01Z","receivedAt":"2024-10-30T20:13:04Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Wed, Oct 30, 2024 at 03:32:34PM +0100, Karthik Nayak wrote:\n> The `multi_pack_index` struct represents the MIDX for a repository.\n> Here, we add a pointer to the repository in this struct, allowing direct\n> use of the repository variable without relying on the global\n> `the_repository` struct.\n>\n> With this addition, we can determine the repository associated with a\n> `bitmap_index` struct. A `bitmap_index` points to either a `packed_git`\n> or a `multi_pack_index`, both of which have direct repository\n> references. To support this, we introduce a static helper function,\n> `bitmap_repo`, in `pack-bitmap.c`, which retrieves a repository given a\n> `bitmap_index`.\n>\n> With this, we clear up all usages of `the_repository` within\n> `pack-bitmap.c` and also remove the `USE_THE_REPOSITORY_VARIABLE`\n> definition. Bringing us another step closer to remove all global\n> variable usage.\n>\n> Although this change also opens up the potential to clean up `midx.c`,\n> doing so would require additional refactoring to pass the repository\n> struct to functions where the MIDX struct is created: a task better\n> suited for future patches.\n>\n> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n> ---\n>  midx.c        |  1 +\n>  midx.h        |  3 ++\n>  pack-bitmap.c | 97 +++++++++++++++++++++++++++++++--------------------\n>  3 files changed, 64 insertions(+), 37 deletions(-)\n>\n> diff --git a/midx.c b/midx.c\n> index 8edb75f51d..7a34473010 100644\n> --- a/midx.c\n> +++ b/midx.c\n> @@ -131,6 +131,7 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir\n>  \tm->data = midx_map;\n>  \tm->data_len = midx_size;\n>  \tm->local = local;\n> +\tm->r = the_repository;\n\nSame note here about calling this 'r' rather than 'repo'.\n\nI do wonder if it creates any awkwardness to have the_repository\nassigned here unconditionally when we do specify the object_dir. I think\nit's OK so long as we don't start replacing 'm->object_dir' with\n'm->repo->objects->odb->path'.\n\n> @@ -1980,18 +1997,23 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,\n>  \tif (!use_boundary_traversal)\n>  \t\tobject_array_clear(&revs->pending);\n>\n> +\trepo = bitmap_repo(bitmap_git);\n> +\n>  \tif (haves) {\n> -\t\tif (use_boundary_traversal) {\n> -\t\t\ttrace2_region_enter(\"pack-bitmap\", \"haves/boundary\", the_repository);\n> +\t\tif (use_boundary_traversal)\n> +\t\t{\n> +\t\t\ttrace2_region_enter(\"pack-bitmap\", \"haves/boundary\", repo);\n>  \t\t\thaves_bitmap = find_boundary_objects(bitmap_git, revs, haves);\n> -\t\t\ttrace2_region_leave(\"pack-bitmap\", \"haves/boundary\", the_repository);\n> -\t\t} else {\n> -\t\t\ttrace2_region_enter(\"pack-bitmap\", \"haves/classic\", the_repository);\n> +\t\t\ttrace2_region_leave(\"pack-bitmap\", \"haves/boundary\", repo);\n> +\t\t}\n> +\t\telse\n> +\t\t{\n> +\t\t\ttrace2_region_enter(\"pack-bitmap\", \"haves/classic\", repo);\n>  \t\t\trevs->ignore_missing_links = 1;\n>  \t\t\thaves_bitmap = find_objects(bitmap_git, revs, haves, NULL);\n>  \t\t\treset_revision_walk();\n>  \t\t\trevs->ignore_missing_links = 0;\n> -\t\t\ttrace2_region_leave(\"pack-bitmap\", \"haves/classic\", the_repository);\n> +\t\t\ttrace2_region_leave(\"pack-bitmap\", \"haves/classic\", repo);\n>  \t\t}\n\nOdd braces?\n\nThanks,\nTaylor\n"},{"id":"506366","messageId":"CAOLa=ZT6_JkyLoBTTAkfRJhuw9xvvYe95N32w8sT5gHmiKt1Rg@mail.gmail.com","threadId":"62424","inReplyTo":"ZyKTTYGPDQ0SWJCZ@nand.local","subject":"Re: [PATCH v3 9/9] midx: add repository to `multi_pack_index` struct","fromName":"karthik nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2024-10-31T09:34:33Z","receivedAt":"2024-10-31T09:34:35Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n> On Wed, Oct 30, 2024 at 03:32:34PM +0100, Karthik Nayak wrote:\n>> The `multi_pack_index` struct represents the MIDX for a repository.\n>> Here, we add a pointer to the repository in this struct, allowing direct\n>> use of the repository variable without relying on the global\n>> `the_repository` struct.\n>>\n>> With this addition, we can determine the repository associated with a\n>> `bitmap_index` struct. A `bitmap_index` points to either a `packed_git`\n>> or a `multi_pack_index`, both of which have direct repository\n>> references. To support this, we introduce a static helper function,\n>> `bitmap_repo`, in `pack-bitmap.c`, which retrieves a repository given a\n>> `bitmap_index`.\n>>\n>> With this, we clear up all usages of `the_repository` within\n>> `pack-bitmap.c` and also remove the `USE_THE_REPOSITORY_VARIABLE`\n>> definition. Bringing us another step closer to remove all global\n>> variable usage.\n>>\n>> Although this change also opens up the potential to clean up `midx.c`,\n>> doing so would require additional refactoring to pass the repository\n>> struct to functions where the MIDX struct is created: a task better\n>> suited for future patches.\n>>\n>> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>\n>> ---\n>>  midx.c        |  1 +\n>>  midx.h        |  3 ++\n>>  pack-bitmap.c | 97 +++++++++++++++++++++++++++++++--------------------\n>>  3 files changed, 64 insertions(+), 37 deletions(-)\n>>\n>> diff --git a/midx.c b/midx.c\n>> index 8edb75f51d..7a34473010 100644\n>> --- a/midx.c\n>> +++ b/midx.c\n>> @@ -131,6 +131,7 @@ static struct multi_pack_index *load_multi_pack_index_one(const char *object_dir\n>>  \tm->data = midx_map;\n>>  \tm->data_len = midx_size;\n>>  \tm->local = local;\n>> +\tm->r = the_repository;\n>\n> Same note here about calling this 'r' rather than 'repo'.\n>\n\nMy bad, I'll fix it in the next version.\n\n> I do wonder if it creates any awkwardness to have the_repository\n> assigned here unconditionally when we do specify the object_dir. I think\n> it's OK so long as we don't start replacing 'm->object_dir' with\n> 'm->repo->objects->odb->path'.\n>\n>> @@ -1980,18 +1997,23 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,\n>>  \tif (!use_boundary_traversal)\n>>  \t\tobject_array_clear(&revs->pending);\n>>\n>> +\trepo = bitmap_repo(bitmap_git);\n>> +\n>>  \tif (haves) {\n>> -\t\tif (use_boundary_traversal) {\n>> -\t\t\ttrace2_region_enter(\"pack-bitmap\", \"haves/boundary\", the_repository);\n>> +\t\tif (use_boundary_traversal)\n>> +\t\t{\n>> +\t\t\ttrace2_region_enter(\"pack-bitmap\", \"haves/boundary\", repo);\n>>  \t\t\thaves_bitmap = find_boundary_objects(bitmap_git, revs, haves);\n>> -\t\t\ttrace2_region_leave(\"pack-bitmap\", \"haves/boundary\", the_repository);\n>> -\t\t} else {\n>> -\t\t\ttrace2_region_enter(\"pack-bitmap\", \"haves/classic\", the_repository);\n>> +\t\t\ttrace2_region_leave(\"pack-bitmap\", \"haves/boundary\", repo);\n>> +\t\t}\n>> +\t\telse\n>> +\t\t{\n>> +\t\t\ttrace2_region_enter(\"pack-bitmap\", \"haves/classic\", repo);\n>>  \t\t\trevs->ignore_missing_links = 1;\n>>  \t\t\thaves_bitmap = find_objects(bitmap_git, revs, haves, NULL);\n>>  \t\t\treset_revision_walk();\n>>  \t\t\trevs->ignore_missing_links = 0;\n>> -\t\t\ttrace2_region_leave(\"pack-bitmap\", \"haves/classic\", the_repository);\n>> +\t\t\ttrace2_region_leave(\"pack-bitmap\", \"haves/classic\", repo);\n>>  \t\t}\n>\n> Odd braces?\n>\n\nIndeed. Will fix this too.\n\n> Thanks,\n> Taylor\n\nThanks for the review.\n"}]}