tree-diff: drop list-tail argument to diff_tree_paths()

The internals of the path diffing code, including ll_diff_tree_paths(), all take an extra combine_diff_path parameter which they use as the tail of a list of results, appending any new entries to it. The public-facing diff_tree_paths() takes the same argument, but it just makes the callers more awkward. They always start with a clean list, and have to set up a fake head struct to pass in. Let's keep the public API clean by always returning a new list. That keeps the fake struct as an implementation detail of tree-diff.c. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jan 9, 2025 at 03:51 UTC a5c4e31af9b8b8fb362472ce3a1ec404df0da032
3 files changed +12 -13
combine-diff.c
+3 -6
@@ -1428,22 +1428,19 @@ static struct combine_diff_path *find_paths_multitree(
1428 {
1429 int i, nparent = parents->nr;
1430 const struct object_id **parents_oid;
1431 - struct combine_diff_path paths_head;
1431 + struct combine_diff_path *paths;
1432 struct strbuf base;
1433
1434 ALLOC_ARRAY(parents_oid, nparent);
1435 for (i = 0; i < nparent; i++)
1436 parents_oid[i] = &parents->oid[i];
1437
1438 - /* fake list head, so worker can assume it is non-NULL */
1439 - paths_head.next = NULL;
1440 -
1438 strbuf_init(&base, PATH_MAX);
1442 - diff_tree_paths(&paths_head, oid, parents_oid, nparent, &base, opt);
1439 + paths = diff_tree_paths(oid, parents_oid, nparent, &base, opt);
1440
1441 strbuf_release(&base);
1442 free(parents_oid);
1446 - return paths_head.next;
1443 + return paths;
1444 }
1445
1446 static int match_objfind(struct combine_diff_path *path,
diff.h
+1 -1
@@ -462,7 +462,7 @@ const char *diff_line_prefix(struct diff_options *);
462 extern const char mime_boundary_leader[];
463
464 struct combine_diff_path *diff_tree_paths(
465 - struct combine_diff_path *p, const struct object_id *oid,
465 + const struct object_id *oid,
466 const struct object_id **parents_oid, int nparent,
467 struct strbuf *base, struct diff_options *opt);
468 void diff_tree_oid(const struct object_id *old_oid,
tree-diff.c
+8 -6
@@ -510,11 +510,14 @@ static struct combine_diff_path *ll_diff_tree_paths(
510 }
511
512 struct combine_diff_path *diff_tree_paths(
513 - struct combine_diff_path *p, const struct object_id *oid,
513 + const struct object_id *oid,
514 const struct object_id **parents_oid, int nparent,
515 struct strbuf *base, struct diff_options *opt)
516 {
517 - p = ll_diff_tree_paths(p, oid, parents_oid, nparent, base, opt, 0);
517 + struct combine_diff_path head, *p;
518 + /* fake list head, so worker can assume it is non-NULL */
519 + head.next = NULL;
520 + p = ll_diff_tree_paths(&head, oid, parents_oid, nparent, base, opt, 0);
521 return p;
522 }
523
@@ -631,14 +634,13 @@ static void ll_diff_tree_oid(const struct object_id *old_oid,
634 const struct object_id *new_oid,
635 struct strbuf *base, struct diff_options *opt)
636 {
634 - struct combine_diff_path phead, *p;
637 + struct combine_diff_path *paths, *p;
638 pathchange_fn_t pathchange_old = opt->pathchange;
639
637 - phead.next = NULL;
640 opt->pathchange = emit_diff_first_parent_only;
639 - diff_tree_paths(&phead, new_oid, &old_oid, 1, base, opt);
641 + paths = diff_tree_paths(new_oid, &old_oid, 1, base, opt);
642
641 - for (p = phead.next; p;) {
643 + for (p = paths; p;) {
644 struct combine_diff_path *pprev = p;
645 p = p->next;
646 free(pprev);