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

Re: [PATCH 3/5] pack-write: pass hash_algo to `write_idx_file()`

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 16, 2025, 19:12 UTC
Message-ID
<xmqqjzaur2ry.fsf@gitster.g>
In-Reply-To
<20250116-kn-the-repo-cleanup-v1-3-a2f4c8e1c4c3@gmail.com>

Karthik Nayak via B4 Relay <devnull+karthik.188.gmail.com@kernel.org> writes:

Show 25 quoted lines
> From: Karthik Nayak <karthik.188@gmail.com>
>
> The `write_idx_file()` function uses the global `the_hash_algo` variable
> to access the repository's hash function. To avoid global variable
> usage, pass the hash function from the layers above.
>
> Altough the layers above could have access to the hash function
> internally, simply pass in `the_hash_algo`. This avoids any
> compatibility issues and bubbles up global variable usage to upper
> layers which can be eventually resolved.
> ...
> -void stage_tmp_packfiles(struct strbuf *name_buffer,
> +void stage_tmp_packfiles(const struct git_hash_algo *hash_algo,
> +			 struct strbuf *name_buffer,
>  			 const char *pack_tmp_name,
>  			 struct pack_idx_entry **written_list,
>  			 uint32_t nr_written,
> @@ -561,8 +563,8 @@ void stage_tmp_packfiles(struct strbuf *name_buffer,
>  	if (adjust_shared_perm(pack_tmp_name))
>  		die_errno("unable to make temporary pack file readable");
>  
> -	*idx_tmp_name = (char *)write_idx_file(NULL, written_list, nr_written,
> -					       pack_idx_opts, hash);
> +	*idx_tmp_name = (char *)write_idx_file(hash_algo, NULL, written_list,
> +					       nr_written, pack_idx_opts, hash);

The proposed log message should mention the reason why this stage_tmp_packfiles() function needs to be singled out among many other direct callers of write_idx_file() function.

In other words, ...
Show 11 quoted lines
> @@ -798,8 +798,8 @@ static const char *create_index(void)
>  	if (c != last)
>  		die("internal consistency error creating the index");
>  
> -	tmpfile = write_idx_file(NULL, idx, object_count, &pack_idx_opts,
> -				 pack_data->hash);
> +	tmpfile = write_idx_file(the_hash_algo, NULL, idx, object_count,
> +				 &pack_idx_opts, pack_data->hash);
>  	free(idx);
>  	return tmpfile;
>  }

... this hunk could have made create_index() to take a git_hash_algo object and pass it down to write_idx_file(), while changing all the callers of create_index() pass the_hash_algo, but we did not do so.

But stage_tmp_packfiles() got that treatment. Please tell your readers in the proposed log message what makes it special.

Thanks.
Previous: Karthik NayakNext: Karthik Nayak
Message 13 of 36 in “pack-write: cleanup usage of global variables”
  1. 0/5 pack-write: cleanup usage of global variablesKarthik Nayak via B4 Relay, Jan 16, 2025
  2. 1/5 pack-write: pass hash_algo to `fixup_pack_header_footer()`Karthik Nayak via B4 Relay, Jan 16, 2025
  3. Junio C HamanoJan 16, 2025
  4. 2/5 pack-write: pass repository to `index_pack_lockfile()`Karthik Nayak via B4 Relay, Jan 16, 2025
  5. Junio C HamanoJan 16, 2025
  6. Karthik NayakJan 17, 2025
  7. 4/5 pack-write: pass hash_algo to `write_rev_file()`Karthik Nayak via B4 Relay, Jan 16, 2025
  8. Patrick SteinhardtJan 16, 2025
  9. Junio C HamanoJan 16, 2025
  10. 3/5 pack-write: pass hash_algo to `write_idx_file()`Karthik Nayak via B4 Relay, Jan 16, 2025
  11. Patrick SteinhardtJan 16, 2025
  12. Karthik NayakJan 17, 2025
  13. Junio C HamanoJan 16, 2025
  14. Karthik NayakJan 17, 2025
  15. 5/5 pack-write: pass hash_algo to `write_rev_*()`Karthik Nayak via B4 Relay, Jan 16, 2025
  16. 0/5 pack-write: cleanup usage of global variablesKarthik Nayak, Jan 17, 2025
  17. 1/5 pack-write: pass hash_algo to `fixup_pack_header_footer()`Karthik Nayak, Jan 17, 2025
  18. Toon ClaesJan 17, 2025
  19. Junio C HamanoJan 17, 2025
  20. Karthik NayakJan 19, 2025
  21. 2/5 pack-write: pass repository to `index_pack_lockfile()`Karthik Nayak, Jan 17, 2025
  22. 3/5 pack-write: pass hash_algo to `write_idx_file()`Karthik Nayak, Jan 17, 2025
  23. Toon ClaesJan 17, 2025
  24. Karthik NayakJan 19, 2025
  25. 4/5 pack-write: pass hash_algo to `write_rev_file()`Karthik Nayak, Jan 17, 2025
  26. 5/5 pack-write: pass hash_algo to internal functionsKarthik Nayak, Jan 17, 2025
  27. Patrick SteinhardtJan 17, 2025
  28. Karthik NayakJan 17, 2025
  29. 0/5 pack-write: cleanup usage of global variablesKarthik Nayak, Jan 19, 2025
  30. 1/5 pack-write: pass hash_algo to `fixup_pack_header_footer()`Karthik Nayak, Jan 19, 2025
  31. 2/5 pack-write: pass repository to `index_pack_lockfile()`Karthik Nayak, Jan 19, 2025
  32. 3/5 pack-write: pass hash_algo to `write_idx_file()`Karthik Nayak, Jan 19, 2025
  33. 4/5 pack-write: pass hash_algo to `write_rev_file()`Karthik Nayak, Jan 19, 2025
  34. 5/5 pack-write: pass hash_algo to internal functionsKarthik Nayak, Jan 19, 2025
  35. Patrick SteinhardtJan 24, 2025
  36. Junio C HamanoJan 24, 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.