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

Re: [PATCH 2/7] reftable: explicitly handle hash format IDs

From
Justin Tobler <jltobler@gmail.com>
Date
Nov 7, 2024, 23:11 UTC
Message-ID
<yvdvlf45g4ahqa3uey4zj4evissv2tfkwiy5o3e3vbqtwmc7o4@utqagwvv6yhe>
In-Reply-To
<c1bd8e2b3c4c524a21f68e822812e41179827e4d.1729677003.git.ps@pks.im>
On 24/10/23 11:55AM, Patrick Steinhardt wrote:
Show 14 quoted lines
> diff --git a/reftable/basics.h b/reftable/basics.h
> index 7aa46d7c30d..86141602e74 100644
> --- a/reftable/basics.h
> +++ b/reftable/basics.h
> @@ -150,4 +150,11 @@ int common_prefix_size(struct reftable_buf *a, struct reftable_buf *b);
>  
>  int hash_size(uint32_t id);
>  
> +/*
> + * Format IDs that identify the hash function used by a reftable. Note that
> + * these constants end up on disk and thus mustn't change.
> + */
> +#define REFTABLE_FORMAT_ID_SHA1   ((uint32_t) 0x73686131)
> +#define REFTABLE_FORMAT_ID_SHA256 ((uint32_t) 0x73323536)

This context is provided in the comments for `GIT_*_FORMAT_ID`, but now that they being decoupled it might be nice to mention here that they stand for "sha1" and "s256" respectively.

Show 25 quoted lines
> +
>  #endif
> diff --git a/reftable/reader.c b/reftable/reader.c
> index 90dc950b577..64eb6938efe 100644
> --- a/reftable/reader.c
> +++ b/reftable/reader.c
> @@ -109,16 +109,18 @@ static int parse_footer(struct reftable_reader *r, uint8_t *footer,
>  	if (r->version == 1) {
>  		r->hash_id = GIT_SHA1_FORMAT_ID;
>  	} else {
> -		r->hash_id = get_be32(f);
> -		switch (r->hash_id) {
> -		case GIT_SHA1_FORMAT_ID:
> +		switch (get_be32(f)) {
> +		case REFTABLE_FORMAT_ID_SHA1:
> +			r->hash_id = GIT_SHA1_FORMAT_ID;
>  			break;
> -		case GIT_SHA256_FORMAT_ID:
> +		case REFTABLE_FORMAT_ID_SHA256:
> +			r->hash_id = GIT_SHA256_FORMAT_ID;
>  			break;
>  		default:
>  			err = REFTABLE_FORMAT_ERROR;
>  			goto done;
>  		}

Instead of directly mapping `hash_id` to `GIT_*_FORMAT_ID`, we use the newly defined constants to map to the corresponding format. As an internal identifier, the format ID can now be freely changed without risk of affecting how on-disk reftable headers are parsed. Makes sense to me and seems like a good change.

-Justin
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 5 of 43 in “reftable: stop using Git subsystems”
  1. 0/7 reftable: stop using Git subsystemsPatrick Steinhardt, Oct 23, 2024
  2. 1/7 reftable/system: move "dir.h" to its only userPatrick Steinhardt, Oct 23, 2024
  3. Eric SunshineOct 24, 2024
  4. 2/7 reftable: explicitly handle hash format IDsPatrick Steinhardt, Oct 23, 2024
  5. Justin ToblerNov 7, 2024
  6. 3/7 reftable/system: stop depending on "hash.h"Patrick Steinhardt, Oct 23, 2024
  7. Justin ToblerNov 8, 2024
  8. Patrick SteinhardtNov 8, 2024
  9. 4/7 reftable/stack: stop using `fsync_component()` directlyPatrick Steinhardt, Oct 23, 2024
  10. Justin ToblerNov 8, 2024
  11. Patrick SteinhardtNov 8, 2024
  12. 5/7 reftable/system: provide thin wrapper for tempfile subsystemPatrick Steinhardt, Oct 23, 2024
  13. 6/7 reftable/stack: drop only use of `get_locked_file_path()`Patrick Steinhardt, Oct 23, 2024
  14. 7/7 reftable/system: provide thin wrapper for lockfile subsystemPatrick Steinhardt, Oct 23, 2024
  15. 0/7 reftable: stop using Git subsystemsPatrick Steinhardt, Nov 8, 2024
  16. 1/7 reftable/system: move "dir.h" to its only userPatrick Steinhardt, Nov 8, 2024
  17. 2/7 reftable: explicitly handle hash format IDsPatrick Steinhardt, Nov 8, 2024
  18. karthik nayakNov 18, 2024
  19. 3/7 reftable/system: stop depending on "hash.h"Patrick Steinhardt, Nov 8, 2024
  20. Junio C HamanoNov 12, 2024
  21. karthik nayakNov 18, 2024
  22. 4/7 reftable/stack: stop using `fsync_component()` directlyPatrick Steinhardt, Nov 8, 2024
  23. karthik nayakNov 18, 2024
  24. Patrick SteinhardtNov 18, 2024
  25. 5/7 reftable/system: provide thin wrapper for tempfile subsystemPatrick Steinhardt, Nov 8, 2024
  26. karthik nayakNov 18, 2024
  27. karthik nayakNov 18, 2024
  28. 6/7 reftable/stack: drop only use of `get_locked_file_path()`Patrick Steinhardt, Nov 8, 2024
  29. 7/7 reftable/system: provide thin wrapper for lockfile subsystemPatrick Steinhardt, Nov 8, 2024
  30. Justin ToblerNov 8, 2024
  31. Junio C HamanoNov 11, 2024
  32. karthik nayakNov 18, 2024
  33. Patrick SteinhardtNov 18, 2024
  34. 0/7 reftable: stop using Git subsystemsPatrick Steinhardt, Nov 18, 2024
  35. 1/7 reftable/system: move "dir.h" to its only userPatrick Steinhardt, Nov 18, 2024
  36. 2/7 reftable: explicitly handle hash format IDsPatrick Steinhardt, Nov 18, 2024
  37. 3/7 reftable/system: stop depending on "hash.h"Patrick Steinhardt, Nov 18, 2024
  38. 4/7 reftable/stack: stop using `fsync_component()` directlyPatrick Steinhardt, Nov 18, 2024
  39. 5/7 reftable/system: provide thin wrapper for tempfile subsystemPatrick Steinhardt, Nov 18, 2024
  40. 6/7 reftable/stack: drop only use of `get_locked_file_path()`Patrick Steinhardt, Nov 18, 2024
  41. 7/7 reftable/system: provide thin wrapper for lockfile subsystemPatrick Steinhardt, Nov 18, 2024
  42. karthik nayakNov 19, 2024
  43. Junio C HamanoNov 20, 2024

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.