git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 01/12] csum-file: stop depending on `the_repository`

From
Karthik Nayak <karthik.188@gmail.com>
Date
Mar 6, 2025, 10:37 UTC
Message-ID
<CAOLa=ZREou-t8m6-HqUXpgB1SygNzP1JXSUV09NzpaoKgEUdwQ@mail.gmail.com>
In-Reply-To
<20250303-b4-pks-objects-without-the-repository-v1-1-c5dd43f2476e@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 39 quoted lines
> There are multiple sites in "csum-file.c" where we use the global
> `the_repository` variable, either explicitly or implicitly by using
> `the_hash_algo`.
>
> Refactor the code to stop using `the_repository` by adapting functions
> to receive required data as parameters. Adapt callsites accordingly by
> either using `the_repository->hash_algo`, or by using a context-provided
> hash algorithm in case the subsystem already got rid of its dependency
> on `the_repository`.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  builtin/fast-import.c  |  2 +-
>  builtin/index-pack.c   |  2 +-
>  builtin/pack-objects.c |  3 ++-
>  commit-graph.c         |  9 ++++++---
>  csum-file.c            | 28 ++++++++++++++++------------
>  csum-file.h            | 12 ++++++++----
>  midx-write.c           |  6 ++++--
>  midx.c                 |  3 ++-
>  pack-bitmap-write.c    |  2 +-
>  pack-bitmap.c          |  9 +++++----
>  pack-check.c           |  2 +-
>  pack-revindex.c        |  3 ++-
>  pack-write.c           | 12 ++++++------
>  read-cache.c           |  2 +-
>  14 files changed, 56 insertions(+), 39 deletions(-)
>
> diff --git a/builtin/fast-import.c b/builtin/fast-import.c
> index 397a6f46ad8..86e6e754816 100644
> --- a/builtin/fast-import.c
> +++ b/builtin/fast-import.c
> @@ -770,7 +770,7 @@ static void start_packfile(void)
>  	p->pack_fd = pack_fd;
>  	p->do_not_close = 1;
>  	p->repo = the_repository;
> -	pack_file = hashfd(pack_fd, p->pack_name);
> +	pack_file = hashfd(the_repository->hash_algo, pack_fd, p->pack_name);
>

I recall that `p->repo` should be an option here, but it makes to use `the_repository` directly here and not worry about it, this should apply to the other changes below too.

[snip]
The rest of the changes look good.
Show 23 quoted lines
> diff --git a/pack-bitmap.c b/pack-bitmap.c
> index 6406953d322..f0e2c000252 100644
> --- a/pack-bitmap.c
> +++ b/pack-bitmap.c
> @@ -3024,7 +3024,8 @@ int bitmap_is_preferred_refname(struct repository *r, const char *refname)
>  	return 0;
>  }
>
> -static int verify_bitmap_file(const char *name)
> +static int verify_bitmap_file(const struct git_hash_algo *algop,
> +			      const char *name)
>  {
>  	struct stat st;
>  	unsigned char *data;
> @@ -3040,7 +3041,7 @@ static int verify_bitmap_file(const char *name)
>
>  	data = xmmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
>  	close(fd);
> -	if (!hashfile_checksum_valid(data, st.st_size))
> +	if (!hashfile_checksum_valid(algop, data, st.st_size))
>  		res = error(_("bitmap file '%s' has invalid checksum"),
>  			    name);
>

Here, we're modifying an internal function since it needs to pass the algo to `hashfile_checksum_valid`. Makes sense.

Show 16 quoted lines
> @@ -3055,14 +3056,14 @@ int verify_bitmap_files(struct repository *r)
>  	for (struct multi_pack_index *m = get_multi_pack_index(r);
>  	     m; m = m->next) {
>  		char *midx_bitmap_name = midx_bitmap_filename(m);
> -		res |= verify_bitmap_file(midx_bitmap_name);
> +		res |= verify_bitmap_file(r->hash_algo, midx_bitmap_name);
>  		free(midx_bitmap_name);
>  	}
>
>  	for (struct packed_git *p = get_all_packs(r);
>  	     p; p = p->next) {
>  		char *pack_bitmap_name = pack_bitmap_filename(p);
> -		res |= verify_bitmap_file(pack_bitmap_name);
> +		res |= verify_bitmap_file(r->hash_algo, pack_bitmap_name);
>  		free(pack_bitmap_name);
>  	}
[snip]
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 3 of 73 in “Stop depending on `the_repository` in object-related subsystems”
  1. 00/12 Stop depending on `the_repository` in object-related subsystemsPatrick Steinhardt, Mar 3, 2025
  2. 01/12 csum-file: stop depending on `the_repository`Patrick Steinhardt, Mar 3, 2025
  3. Karthik NayakMar 6, 2025
  4. 03/12 pack-write: stop depending on `the_repository` and `the_hash_algo`Patrick Steinhardt, Mar 3, 2025
  5. Justin ToblerMar 4, 2025
  6. 02/12 object: stop depending on `the_repository`Patrick Steinhardt, Mar 3, 2025
  7. Karthik NayakMar 6, 2025
  8. Patrick SteinhardtMar 6, 2025
  9. 05/12 pack-check: stop depending on `the_repository`Patrick Steinhardt, Mar 3, 2025
  10. Karthik NayakMar 6, 2025
  11. 04/12 environment: move access to "core.bigFileThreshold" into repo settingsPatrick Steinhardt, Mar 3, 2025
  12. Justin ToblerMar 4, 2025
  13. Patrick SteinhardtMar 6, 2025
  14. 06/12 pack-revindex: stop depending on `the_repository`Patrick Steinhardt, Mar 3, 2025
  15. 07/12 pack-bitmap-write: stop depending on `the_repository`Patrick Steinhardt, Mar 3, 2025
  16. 08/12 object-file-convert: stop depending on `the_repository`Patrick Steinhardt, Mar 3, 2025
  17. Justin ToblerMar 4, 2025
  18. 09/12 delta-islands: stop depending on `the_repository`Patrick Steinhardt, Mar 3, 2025
  19. Justin ToblerMar 4, 2025
  20. 10/12 object-file: split out logic regarding hash algorithmsPatrick Steinhardt, Mar 3, 2025
  21. 11/12 hash: fix "-Wsign-compare" warningsPatrick Steinhardt, Mar 3, 2025
  22. 12/12 hash: stop depending on `the_repository` in `null_oid()`Patrick Steinhardt, Mar 3, 2025
  23. Justin ToblerMar 4, 2025
  24. Karthik NayakMar 6, 2025
  25. 00/12 Stop depending on `the_repository` in object-related subsystemsPatrick Steinhardt, Mar 6, 2025
  26. 01/12 csum-file: stop depending on `the_repository`Patrick Steinhardt, Mar 6, 2025
  27. 02/12 object: stop depending on `the_repository`Patrick Steinhardt, Mar 6, 2025
  28. 03/12 pack-write: stop depending on `the_repository` and `the_hash_algo`Patrick Steinhardt, Mar 6, 2025
  29. 04/12 environment: move access to "core.bigFileThreshold" into repo settingsPatrick Steinhardt, Mar 6, 2025
  30. 05/12 pack-check: stop depending on `the_repository`Patrick Steinhardt, Mar 6, 2025
  31. 06/12 pack-revindex: stop depending on `the_repository`Patrick Steinhardt, Mar 6, 2025
  32. 07/12 pack-bitmap-write: stop depending on `the_repository`Patrick Steinhardt, Mar 6, 2025
  33. 08/12 object-file-convert: stop depending on `the_repository`Patrick Steinhardt, Mar 6, 2025
  34. 09/12 delta-islands: stop depending on `the_repository`Patrick Steinhardt, Mar 6, 2025
  35. 11/12 hash: fix "-Wsign-compare" warningsPatrick Steinhardt, Mar 6, 2025
  36. 10/12 object-file: split out logic regarding hash algorithmsPatrick Steinhardt, Mar 6, 2025
  37. 12/12 hash: stop depending on `the_repository` in `null_oid()`Patrick Steinhardt, Mar 6, 2025
  38. Junio C HamanoMar 6, 2025
  39. Patrick SteinhardtMar 7, 2025
  40. Junio C HamanoMar 7, 2025
  41. Karthik NayakMar 6, 2025
  42. 00/12 Stop depending on `the_repository` in object-related subsystemsPatrick Steinhardt, Mar 7, 2025
  43. 02/12 object: stop depending on `the_repository`Patrick Steinhardt, Mar 7, 2025
  44. 01/12 csum-file: stop depending on `the_repository`Patrick Steinhardt, Mar 7, 2025
  45. 03/12 pack-write: stop depending on `the_repository` and `the_hash_algo`Patrick Steinhardt, Mar 7, 2025
  46. 05/12 pack-check: stop depending on `the_repository`Patrick Steinhardt, Mar 7, 2025
  47. 04/12 environment: move access to "core.bigFileThreshold" into repo settingsPatrick Steinhardt, Mar 7, 2025
  48. 06/12 pack-revindex: stop depending on `the_repository`Patrick Steinhardt, Mar 7, 2025
  49. 07/12 pack-bitmap-write: stop depending on `the_repository`Patrick Steinhardt, Mar 7, 2025
  50. 08/12 object-file-convert: stop depending on `the_repository`Patrick Steinhardt, Mar 7, 2025
  51. 09/12 delta-islands: stop depending on `the_repository`Patrick Steinhardt, Mar 7, 2025
  52. 10/12 object-file: split out logic regarding hash algorithmsPatrick Steinhardt, Mar 7, 2025
  53. 11/12 hash: fix "-Wsign-compare" warningsPatrick Steinhardt, Mar 7, 2025
  54. 12/12 hash: stop depending on `the_repository` in `null_oid()`Patrick Steinhardt, Mar 7, 2025
  55. Elijah NewrenMar 8, 2025
  56. Patrick SteinhardtMar 10, 2025
  57. Elijah NewrenMar 10, 2025
  58. Junio C HamanoMar 10, 2025
  59. Elijah NewrenMar 8, 2025
  60. 00/12 Stop depending on `the_repository` in object-related subsystemsPatrick Steinhardt, Mar 10, 2025
  61. 01/12 csum-file: stop depending on `the_repository`Patrick Steinhardt, Mar 10, 2025
  62. 02/12 object: stop depending on `the_repository`Patrick Steinhardt, Mar 10, 2025
  63. 03/12 pack-write: stop depending on `the_repository` and `the_hash_algo`Patrick Steinhardt, Mar 10, 2025
  64. 04/12 environment: move access to "core.bigFileThreshold" into repo settingsPatrick Steinhardt, Mar 10, 2025
  65. 05/12 pack-check: stop depending on `the_repository`Patrick Steinhardt, Mar 10, 2025
  66. 06/12 pack-revindex: stop depending on `the_repository`Patrick Steinhardt, Mar 10, 2025
  67. 07/12 pack-bitmap-write: stop depending on `the_repository`Patrick Steinhardt, Mar 10, 2025
  68. 08/12 object-file-convert: stop depending on `the_repository`Patrick Steinhardt, Mar 10, 2025
  69. 09/12 delta-islands: stop depending on `the_repository`Patrick Steinhardt, Mar 10, 2025
  70. 11/12 hash: fix "-Wsign-compare" warningsPatrick Steinhardt, Mar 10, 2025
  71. 10/12 object-file: split out logic regarding hash algorithmsPatrick Steinhardt, Mar 10, 2025
  72. 12/12 hash: stop depending on `the_repository` in `null_oid()`Patrick Steinhardt, Mar 10, 2025
  73. Elijah NewrenMar 10, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.