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

Re: [PATCH 3/5] match-trees: use hashcpy to splice trees

From
Jeff King <peff@peff.net>
Date
Jan 10, 2019, 06:45 UTC
Message-ID
<20190110064520.GC20497@sigill.intra.peff.net>
In-Reply-To
<20190110042551.915769-4-sandals@crustytoothpaste.net>
On Thu, Jan 10, 2019 at 04:25:49AM +0000, brian m. carlson wrote:
Show 23 quoted lines
> When we're splicing trees, we're writing directly from one location into
> a buffer that is exactly the same size as a tree object. If the current
> hash algorithm is SHA-1, we may not have a full 32 (GIT_MAX_RAWSZ) bytes
> available to write, nor would we want to write that many bytes even if
> we did. In a future commit, we'll split out hashcpy to respect
> the_hash_algo while oidcpy uses GIT_MAX_RAWSZ, so convert the oidcpy to
> a hashcpy so we copy the right number of bytes.
> 
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
>  match-trees.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/match-trees.c b/match-trees.c
> index feca48a5fd..b1fbd022d1 100644
> --- a/match-trees.c
> +++ b/match-trees.c
> @@ -224,7 +224,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
>  	} else {
>  		rewrite_with = oid2;
>  	}
> -	oidcpy(rewrite_here, rewrite_with);
> +	hashcpy(rewrite_here->hash, rewrite_with->hash);

Hrm. Our coccinelle patches will want to convert this back to oidcpy(), though I see you drop them in the final patch.

However, I wonder if it points to another mismatch. Isn't the point that we _don't_ actually have "struct object_id"s here? I.e., rewrite_here and rewrite_with should actually be "const unsigned char *" that we happen to know are the_hash_algo->raw_sz?

I think the only reason they are "struct object_id" is because that's what tree_entry_extract() returns. Should we be providing another function to allow more byte-oriented access?

-Peff
Previous: brian m. carlsonNext: brian m. carlson
Message 17 of 41 in “What's cooking in git.git (Jan 2019, #01; Mon, 7)”
  1. Junio C HamanoJan 7, 2019
  2. tg/checkout-no-overlay, was Re: What's cooking in git.git (Jan 2019, #01; Mon, 7)Thomas Gummerer, Jan 8, 2019
  3. Junio C HamanoJan 8, 2019
  4. ag/sequencer-reduce-rewriting-todo Re: What's cooking in git.git (Jan 2019, #01; Mon, 7)Alban Gruin, Jan 8, 2019
  5. sb/more-repo-in-api, was Re: What's cooking in git.git (Jan 2019, #01; Mon, 7)Jonathan Tan, Jan 8, 2019
  6. Junio C HamanoJan 8, 2019
  7. Stefan BellerJan 9, 2019
  8. Martin ÅgrenJan 9, 2019
  9. Martin ÅgrenJan 9, 2019
  10. brian m. carlsonJan 10, 2019
  11. Junio C HamanoJan 10, 2019
  12. Martin ÅgrenJan 10, 2019
  13. 0/5 tree-walk object_id refactorbrian m. carlson, Jan 10, 2019
  14. 1/5 tree-walk: copy object ID before usebrian m. carlson, Jan 10, 2019
  15. 2/5 match-trees: compute buffer offset correctly when splicingbrian m. carlson, Jan 10, 2019
  16. 3/5 match-trees: use hashcpy to splice treesbrian m. carlson, Jan 10, 2019
  17. Jeff KingJan 10, 2019
  18. brian m. carlsonJan 10, 2019
  19. Jeff KingJan 11, 2019
  20. Jeff KingJan 11, 2019
  21. brian m. carlsonJan 14, 2019
  22. Jeff KingJan 14, 2019
  23. 4/5 tree-walk: store object_id in a separate memberbrian m. carlson, Jan 10, 2019
  24. Jeff KingJan 10, 2019
  25. brian m. carlsonJan 10, 2019
  26. 5/5 cache: make oidcpy always copy GIT_MAX_RAWSZ bytesbrian m. carlson, Jan 10, 2019
  27. Jeff KingJan 10, 2019
  28. Jeff KingJan 10, 2019
  29. brian m. carlsonJan 11, 2019
  30. Jeff KingJan 11, 2019
  31. 0/5 tree-walk object_id refactorbrian m. carlson, Jan 15, 2019
  32. 1/5 tree-walk: copy object ID before usebrian m. carlson, Jan 15, 2019
  33. 2/5 match-trees: compute buffer offset correctly when splicingbrian m. carlson, Jan 15, 2019
  34. 4/5 tree-walk: store object_id in a separate memberbrian m. carlson, Jan 15, 2019
  35. 5/5 cache: make oidcpy always copy GIT_MAX_RAWSZ bytesbrian m. carlson, Jan 15, 2019
  36. 3/5 match-trees: use hashcpy to splice treesbrian m. carlson, Jan 15, 2019
  37. Junio C HamanoJan 15, 2019
  38. Jeff KingJan 9, 2019
  39. Junio C HamanoJan 10, 2019
  40. Junio C HamanoJan 10, 2019
  41. Stefan BellerJan 10, 2019

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.