]> git.ipfire.org Git - thirdparty/git.git/commitdiff
merge-recursive: use subtraction to flip stage
authorJunio C Hamano <gitster@pobox.com>
Sat, 25 Jan 2020 23:57:45 +0000 (18:57 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Jan 2020 19:17:41 +0000 (11:17 -0800)
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>
merge-recursive.c

index e6aedd3cab7427e13986fa102a4c56b092b73182..aee1769a7ac344c0d0fed681588efce4c09df564 100644 (file)
@@ -1713,12 +1713,11 @@ static char *find_path_for_conflict(struct merge_options *opt,
 }
 
 /*
- * Toggle the stage number between "ours" and "theirs" (2 and 3) by flipping
- * the 1-bit.
+ * Toggle the stage number between "ours" and "theirs" (2 and 3).
  */
 static inline int flip_stage(int stage)
 {
-       return stage ^ 1;
+       return (2 + 3) - stage;
 }
 
 static int handle_rename_rename_1to2(struct merge_options *opt,