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

[PATCH v2 1/3] combine-diff: zero memory used for callback filepairs

From
Toon Claes <toon@iotcl.com>
Date
Aug 7, 2025, 20:52 UTC
Message-ID
<20250807-toon-max-depth-v2-1-50b7e5c81665@iotcl.com>
In-Reply-To
<20250807-toon-max-depth-v2-0-50b7e5c81665@iotcl.com>
From: Jeff King <peff@peff.net>

In commit 25e5e2bf85 (combine-diff: support format_callback, 2011-08-19), the combined-diff code learned how to make a multi-sourced `diff_filepair` to pass to a diff callback. When we create each filepair, we do not bother to fill in many of the fields, because they would make no sense (e.g. there can be no rename score or broken_pair flag because we do not go through the diffcore filters). However, we did not even bother to zero them, leading to random values. Let's make sure everything is blank with xcalloc(), just as the regular diff code does.

We would potentially want to set the `status` flag to something non-zero, but it is not clear to what. Possibly a new DIFF_STATUS_COMBINED would make sense, as this is not strictly a modification, nor does it fit any other category.

Since it is not yet clear what callers would want, this patch simply leaves it as `0`, the same empty flag that is seen when `diffcore_std` is not used at all.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Toon Claes <toon@iotcl.com>
---
 combine-diff.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/combine-diff.c b/combine-diff.c
index 4ea2dc93c4..3878faabe7 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -1315,7 +1315,7 @@ static struct diff_filepair *combined_pair(struct combine_diff_path *p,
 	struct diff_filepair *pair;
 	struct diff_filespec *pool;
 
-	pair = xmalloc(sizeof(*pair));
+	CALLOC_ARRAY(pair, 1);
 	CALLOC_ARRAY(pool, st_add(num_parent, 1));
 	pair->one = pool + 1;
 	pair->two = pool;
-- 
2.50.1.327.g047016eb4a
Previous: Toon ClaesNext: Toon Claes
Message 12 of 16 in “Teach git-diff-tree(1) option --max-depth”
  1. 0/3 Teach git-diff-tree(1) option --max-depthToon Claes, Jul 29, 2025
  2. 1/3 combine-diff: zero memory used for callback filepairsToon Claes, Jul 29, 2025
  3. 2/3 within_depth: fix return for empty pathToon Claes, Jul 29, 2025
  4. Patrick SteinhardtJul 30, 2025
  5. Toon ClaesAug 6, 2025
  6. Patrick SteinhardtAug 7, 2025
  7. 3/3 diff: teach tree-diff a max-depth parameterToon Claes, Jul 29, 2025
  8. Patrick SteinhardtJul 30, 2025
  9. Toon ClaesAug 6, 2025
  10. Patrick SteinhardtAug 7, 2025
  11. 0/3 Teach git-diff-tree(1) option --max-depthToon Claes, Aug 7, 2025
  12. 1/3 combine-diff: zero memory used for callback filepairsToon Claes, Aug 7, 2025
  13. 2/3 within_depth: fix return for empty pathToon Claes, Aug 7, 2025
  14. 3/3 diff: teach tree-diff a max-depth parameterToon Claes, Aug 7, 2025
  15. Junio C HamanoAug 14, 2025
  16. Patrick SteinhardtAug 15, 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.