Skip to content

Commit 6632bcb

Browse files
peffgitster
authored andcommitted
tree-diff: simplify emit_path() list management
In emit_path() we may append a new combine_diff_path entry to our list, decide that we don't want it (because opt->pathchange() told us so) and then roll it back. Between the addition and the rollback, it doesn't matter if it's in the list or not (no functions can even tell, since it's a singly-linked list and we pass around just the tail entry). So it's much simpler to just wait until opt->pathchange() tells us whether to keep it, and either attach it (or free it) then. We do still have to allocate it up front since it's that struct itself which is passed to the pathchange callback. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d8baf08 commit 6632bcb

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

tree-diff.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,12 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *tail,
177177

178178
if (emitthis) {
179179
int keep;
180-
struct combine_diff_path *pprev = tail, *p;
180+
struct combine_diff_path *p;
181181

182182
strbuf_add(base, path, pathlen);
183183
p = combine_diff_path_new(base->buf, base->len, mode,
184184
oid ? oid : null_oid(),
185185
nparent);
186-
tail->next = p;
187-
tail = p;
188186
strbuf_setlen(base, old_baselen);
189187

190188
for (i = 0; i < nparent; ++i) {
@@ -220,10 +218,11 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *tail,
220218
if (opt->pathchange)
221219
keep = opt->pathchange(opt, p);
222220

223-
if (!keep) {
221+
if (keep) {
222+
tail->next = p;
223+
tail = p;
224+
} else {
224225
free(p);
225-
pprev->next = NULL;
226-
tail = pprev;
227226
}
228227
}
229228

0 commit comments

Comments
 (0)