Skip to content

Commit 4c616c2

Browse files
committed
merge-recursive: use subtraction to flip stage
The flip_stage() helper uses a bit-flipping xor to switch between "2" and "3". While clever, this relies on a property of those two numbers that is mostly coincidence. Let's write it as a subtraction; that's more clear and would extend to other numbers if somebody copies the logic. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ee79874 commit 4c616c2

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

merge-recursive.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,12 +1713,11 @@ static char *find_path_for_conflict(struct merge_options *opt,
17131713
}
17141714

17151715
/*
1716-
* Toggle the stage number between "ours" and "theirs" (2 and 3) by flipping
1717-
* the 1-bit.
1716+
* Toggle the stage number between "ours" and "theirs" (2 and 3).
17181717
*/
17191718
static inline int flip_stage(int stage)
17201719
{
1721-
return stage ^ 1;
1720+
return (2 + 3) - stage;
17221721
}
17231722

17241723
static int handle_rename_rename_1to2(struct merge_options *opt,

0 commit comments

Comments
 (0)