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

Re: [PATCH v2 01/13] hash: add an algo member to struct object_id

From
Matheus Tavares Bernardino <matheus.bernardino@usp.br>
Date
May 7, 2021, 13:58 UTC
Message-ID
<CAHd-oW4N7GB=E6hFc4GAD-b+1QzTR9+hL-hDXwAQkuss4Y4Ddw@mail.gmail.com>
In-Reply-To
<20210426010301.1093562-2-sandals@crustytoothpaste.net>
Hi, brian

On Sun, Apr 25, 2021 at 10:03 PM brian m. carlson <sandals@crustytoothpaste.net> wrote:

Show 5 quoted lines
>
> Now that we're working with multiple hash algorithms in the same repo,
> it's best if we label each object ID with its algorithm so we can
> determine how to format a given object ID. Add a member called algo to
> struct object_id.

In parallel-checkout.c:send_one_item(), I used hashcpy() instead of oidcpy() to prepare the packet data that is sent to the checkout workers through a pipe.

I avoided oidcpy() because it would copy the whole GIT_MAX_RAWSZ bytes, and the last part could be uninitialized, leading to a Valgrind warning about passing uninitialized bytes to a write() syscall. There is no real harm in this case, but I wanted to avoid the warning as it might confuse someone trying to debug this code, me included.

The problem with this approach, of course, is that it will not copy the new `algo` field, leaving it as zero for all items. So, what do you think would be best in this situation? Some ideas that came through my mind were:

1. Make oidcpy() only copy `hash_algos[src->algo].rawsz` bytes. (But
then we would probably need to branch in case `src->algo` is zero,
right?)
2. Reintroduce the oid_pad_buffer() function from your v1, and use it
in parallel-checkout.c:send_one_item(), after oidcpy(). This would
then zero out the copied uninitialized bytes (with the cost of one
additional memcpy() per item, but this might be neglectable here).
3. Use oidcpy() as-is, without additional padding, and let Valgrind
warn. This false-positive warn might not be so problematic after all,
and maybe I'm just overthinking things :)
What do you think?

Thanks, Matheus

Previous: brian m. carlsonNext: brian m. carlson
Message 3 of 16 in “SHA-256 / SHA-1 interop, part 1”
  1. 00/13 SHA-256 / SHA-1 interop, part 1brian m. carlson, Apr 26, 2021
  2. 01/13 hash: add an algo member to struct object_idbrian m. carlson, Apr 26, 2021
  3. Matheus Tavares BernardinoMay 7, 2021
  4. brian m. carlsonMay 7, 2021
  5. 03/13 http-push: set algorithm when reading object IDbrian m. carlson, Apr 26, 2021
  6. 06/13 builtin/pack-redundant: avoid casting buffers to struct object_idbrian m. carlson, Apr 26, 2021
  7. 02/13 Always use oidread to read into struct object_idbrian m. carlson, Apr 26, 2021
  8. 07/13 hash: set, copy, and use algo field in struct object_idbrian m. carlson, Apr 26, 2021
  9. 10/13 commit-graph: don't store file hashes as struct object_idbrian m. carlson, Apr 26, 2021
  10. 11/13 builtin/pack-objects: avoid using struct object_id for pack hashbrian m. carlson, Apr 26, 2021
  11. 13/13 hex: print objects using the hash algorithm memberbrian m. carlson, Apr 26, 2021
  12. 04/13 hash: add a function to finalize object IDsbrian m. carlson, Apr 26, 2021
  13. 05/13 Use the final_oid_fn to finalize hashing of object IDsbrian m. carlson, Apr 26, 2021
  14. 08/13 hash: provide per-algorithm null OIDsbrian m. carlson, Apr 26, 2021
  15. 09/13 builtin/show-index: set the algorithm for object IDsbrian m. carlson, Apr 26, 2021
  16. 12/13 hex: default to the_hash_algo on zero algorithm valuebrian m. carlson, Apr 26, 2021

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.