Skip to content

Commit 2b318aa

Browse files
Denton-Lgitster
authored andcommitted
rebase: refactor can_fast_forward into goto tower
Before, can_fast_forward was written with an if-else statement. However, in the future, we may be adding more termination cases which would lead to deeply nested if statements. Refactor to use a goto tower so that future cases can be easily inserted. Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c9efc21 commit 2b318aa

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

builtin/rebase.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,20 +1264,25 @@ static int can_fast_forward(struct commit *onto, struct object_id *head_oid,
12641264
struct object_id *merge_base)
12651265
{
12661266
struct commit *head = lookup_commit(the_repository, head_oid);
1267-
struct commit_list *merge_bases;
1268-
int res;
1267+
struct commit_list *merge_bases = NULL;
1268+
int res = 0;
12691269

12701270
if (!head)
1271-
return 0;
1271+
goto done;
12721272

12731273
merge_bases = get_merge_bases(onto, head);
1274-
if (merge_bases && !merge_bases->next) {
1275-
oidcpy(merge_base, &merge_bases->item->object.oid);
1276-
res = oideq(merge_base, &onto->object.oid);
1277-
} else {
1274+
if (!merge_bases || merge_bases->next) {
12781275
oidcpy(merge_base, &null_oid);
1279-
res = 0;
1276+
goto done;
12801277
}
1278+
1279+
oidcpy(merge_base, &merge_bases->item->object.oid);
1280+
if (!oideq(merge_base, &onto->object.oid))
1281+
goto done;
1282+
1283+
res = 1;
1284+
1285+
done:
12811286
free_commit_list(merge_bases);
12821287
return res && is_linear_history(onto, head);
12831288
}

0 commit comments

Comments
 (0)