Skip to content

Commit a5c4e31

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 69f6dea commit a5c4e31

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

combine-diff.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,22 +1428,19 @@ static struct combine_diff_path *find_paths_multitree(
14281428
{
14291429
int i, nparent = parents->nr;
14301430
const struct object_id **parents_oid;
1431-
struct combine_diff_path paths_head;
1431+
struct combine_diff_path *paths;
14321432
struct strbuf base;
14331433

14341434
ALLOC_ARRAY(parents_oid, nparent);
14351435
for (i = 0; i < nparent; i++)
14361436
parents_oid[i] = &parents->oid[i];
14371437

1438-
/* fake list head, so worker can assume it is non-NULL */
1439-
paths_head.next = NULL;
1440-
14411438
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);
14431440

14441441
strbuf_release(&base);
14451442
free(parents_oid);
1446-
return paths_head.next;
1443+
return paths;
14471444
}
14481445

14491446
static int match_objfind(struct combine_diff_path *path,

diff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ const char *diff_line_prefix(struct diff_options *);
462462
extern const char mime_boundary_leader[];
463463

464464
struct combine_diff_path *diff_tree_paths(
465-
struct combine_diff_path *p, const struct object_id *oid,
465+
const struct object_id *oid,
466466
const struct object_id **parents_oid, int nparent,
467467
struct strbuf *base, struct diff_options *opt);
468468
void diff_tree_oid(const struct object_id *old_oid,

tree-diff.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,14 @@ static struct combine_diff_path *ll_diff_tree_paths(
510510
}
511511

512512
struct combine_diff_path *diff_tree_paths(
513-
struct combine_diff_path *p, const struct object_id *oid,
513+
const struct object_id *oid,
514514
const struct object_id **parents_oid, int nparent,
515515
struct strbuf *base, struct diff_options *opt)
516516
{
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);
518521
return p;
519522
}
520523

@@ -631,14 +634,13 @@ static void ll_diff_tree_oid(const struct object_id *old_oid,
631634
const struct object_id *new_oid,
632635
struct strbuf *base, struct diff_options *opt)
633636
{
634-
struct combine_diff_path phead, *p;
637+
struct combine_diff_path *paths, *p;
635638
pathchange_fn_t pathchange_old = opt->pathchange;
636639

637-
phead.next = NULL;
638640
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);
640642

641-
for (p = phead.next; p;) {
643+
for (p = paths; p;) {
642644
struct combine_diff_path *pprev = p;
643645
p = p->next;
644646
free(pprev);

0 commit comments

Comments
 (0)