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

Re: [PATCH v2 2/4] Add structure representing hash algorithm

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Oct 29, 2017, 01:36 UTC
Message-ID
<CAPig+cSX_+mN8Pz=0k3xnHRa-Teoq2JrSHe0zQhzJ1NZafXPoQ@mail.gmail.com>
In-Reply-To
<20171028181239.59458-3-sandals@crustytoothpaste.net>

On Sat, Oct 28, 2017 at 2:12 PM, brian m. carlson <sandals@crustytoothpaste.net> wrote:

Show 43 quoted lines
> Since in the future we want to support an additional hash algorithm, add
> a structure that represents a hash algorithm and all the data that must
> go along with it.  Add a constant to allow easy enumeration of hash
> algorithms.  Implement function typedefs to create an abstract API that
> can be used by any hash algorithm, and wrappers for the existing SHA1
> functions that conform to this API.
> [...]
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
> diff --git a/cache.h b/cache.h
> @@ -77,6 +77,61 @@ struct object_id {
> +typedef void (*git_hash_init_fn)(void *ctx);
> +typedef void (*git_hash_update_fn)(void *ctx, const void *in, size_t len);
> +typedef void (*git_hash_final_fn)(unsigned char *hash, void *ctx);
> +
> +struct git_hash_algo {
> +       [...]
> +       /* The hash initialization function. */
> +       git_hash_init_fn init_fn;
> +
> +       /* The hash update function. */
> +       git_hash_update_fn update_fn;
> +
> +       /* The hash finalization function. */
> +       git_hash_final_fn final_fn;
> +       [...]
> +};
> diff --git a/sha1_file.c b/sha1_file.c
> @@ -39,6 +39,49 @@ const struct object_id empty_blob_oid = {
> +static inline void git_hash_sha1_init(void *ctx)
> +{
> +       git_SHA1_Init((git_SHA_CTX *)ctx);
> +}
> +
> +static inline void git_hash_sha1_update(void *ctx, const void *data, size_t len)
> +{
> +       git_SHA1_Update((git_SHA_CTX *)ctx, data, len);
> +}
> +
> +static inline void git_hash_sha1_final(unsigned char *hash, void *ctx)
> +{
> +       git_SHA1_Final(hash, (git_SHA_CTX *)ctx);
> +}
Why 'inline' if you only ever take the addresses of these functions?
Show 16 quoted lines
> +const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
> +       [...]
> +       {
> +               "sha-1",
> +               /* "sha1", big-endian */
> +               0x73686131,
> +               sizeof(git_SHA_CTX),
> +               GIT_SHA1_RAWSZ,
> +               GIT_SHA1_HEXSZ,
> +               git_hash_sha1_init,
> +               git_hash_sha1_update,
> +               git_hash_sha1_final,
> +               &empty_tree_oid,
> +               &empty_blob_oid,
> +       },
> +};
Previous: brian m. carlsonNext: brian m. carlson
Message 13 of 19 in “Hash Abstraction”
  1. 0/4 Hash Abstractionbrian m. carlson, Oct 28, 2017
  2. 1/4 setup: expose enumerated repo infobrian m. carlson, Oct 28, 2017
  3. Stefan BellerOct 30, 2017
  4. 3/4 Integrate hash algorithm support with repo setupbrian m. carlson, Oct 28, 2017
  5. Eric SunshineOct 29, 2017
  6. brian m. carlsonOct 29, 2017
  7. Eric SunshineOct 29, 2017
  8. brian m. carlsonOct 29, 2017
  9. Junio C HamanoOct 30, 2017
  10. brian m. carlsonOct 30, 2017
  11. Stefan BellerOct 30, 2017
  12. 2/4 Add structure representing hash algorithmbrian m. carlson, Oct 28, 2017
  13. Eric SunshineOct 29, 2017
  14. brian m. carlsonOct 29, 2017
  15. Stefan BellerOct 30, 2017
  16. Brandon WilliamsOct 30, 2017
  17. brian m. carlsonNov 1, 2017
  18. 4/4 Switch empty tree and blob lookups to use hash abstractionbrian m. carlson, Oct 28, 2017
  19. Stefan BellerOct 30, 2017

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.