@matheusbsbs / matheus-bagliano / commits / 4c616c2ba1
Fork 0

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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jan 25, 2020 at 18:57 UTC 4c616c2ba1c176573bd1ae7c4ec3271d1f175448
1 file changed +2 -3
merge-recursive.c
+2 -3
@@ -1713,12 +1713,11 @@ static char *find_path_for_conflict(struct merge_options *opt,
1713 }
1714
1715 /*
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).
1717 */
1718 static inline int flip_stage(int stage)
1719 {
1721 - return stage ^ 1;
1720 + return (2 + 3) - stage;
1721 }
1722
1723 static int handle_rename_rename_1to2(struct merge_options *opt,