Skip to content

Commit 8371549

Browse files
peffgitster
authored andcommitted
submodule: clarify logic in show_submodule_summary
There are two uses of the "left" and "right" commit variables that make it hard to be sure what values they have (both for the reader, and for gcc, which wrongly complains that they might be used uninitialized). The function starts with a cascading if statement, checking that the input sha1s exist, and finally working up to preparing a revision walk. We only prepare the walk if the cascading conditional did not find any problems, which we check by seeing whether it set the "message" variable or not. It's simpler and more obvious to just add a condition to the end of the cascade. Later, we check the same "message" variable when deciding whether to clear commit marks on the left/right commits; if it is set, we presumably never started the walk. This is wrong, though; we might have started the walk and munged commit flags, only to encounter an error afterwards. We should always clear the flags on left/right if they exist, whether the walk was successful or not. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c9fc441 commit 8371549

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

submodule.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ void show_submodule_summary(FILE *f, const char *path,
261261
const char *del, const char *add, const char *reset)
262262
{
263263
struct rev_info rev;
264-
struct commit *left = left, *right = right;
264+
struct commit *left = NULL, *right = NULL;
265265
const char *message = NULL;
266266
struct strbuf sb = STRBUF_INIT;
267267
int fast_forward = 0, fast_backward = 0;
@@ -275,10 +275,8 @@ void show_submodule_summary(FILE *f, const char *path,
275275
else if (!(left = lookup_commit_reference(one)) ||
276276
!(right = lookup_commit_reference(two)))
277277
message = "(commits not present)";
278-
279-
if (!message &&
280-
prepare_submodule_summary(&rev, path, left, right,
281-
&fast_forward, &fast_backward))
278+
else if (prepare_submodule_summary(&rev, path, left, right,
279+
&fast_forward, &fast_backward))
282280
message = "(revision walker failed)";
283281

284282
if (dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
@@ -302,11 +300,12 @@ void show_submodule_summary(FILE *f, const char *path,
302300
strbuf_addf(&sb, "%s:%s\n", fast_backward ? " (rewind)" : "", reset);
303301
fwrite(sb.buf, sb.len, 1, f);
304302

305-
if (!message) {
303+
if (!message) /* only NULL if we succeeded in setting up the walk */
306304
print_submodule_summary(&rev, f, del, add, reset);
305+
if (left)
307306
clear_commit_marks(left, ~0);
307+
if (right)
308308
clear_commit_marks(right, ~0);
309-
}
310309

311310
strbuf_release(&sb);
312311
}

0 commit comments

Comments
 (0)