revision: fix --left/right-only use with unrelated histories

This is a similar fix as 023756f4eb (revision walker: --cherry-pick is a limited operation), but for the --left-only and --right-only options. When computing a symmetric difference between two unrelated histories, no suitable merge base exists, and so no boundary commit is flagged as UNINTERESTING. Previously, we relied on the presence of such boundary to trigger limiting and thus consideration of either "revs->left_only" or "revs->right_only". A number of other entries in the option parser have started including overrides for "revs->limited = 1". Do the same for these options. Signed-off-by: Matt Hunter <m@lfurio.us> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matt Hunter committed Mar 30, 2025 at 07:24 UTC e7ef4be7c25c4968d8c5c51e6e748a1927f67194
2 files changed +17
revision.c
+2
@@ -2488,10 +2488,12 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
2488 die(_("options '%s' and '%s' cannot be used together"),
2489 "--left-only", "--right-only/--cherry");
2490 revs->left_only = 1;
2491 + revs->limited = 1;
2492 } else if (!strcmp(arg, "--right-only")) {
2493 if (revs->left_only)
2494 die(_("options '%s' and '%s' cannot be used together"), "--right-only", "--left-only");
2495 revs->right_only = 1;
2496 + revs->limited = 1;
2497 } else if (!strcmp(arg, "--cherry")) {
2498 if (revs->left_only)
2499 die(_("options '%s' and '%s' cannot be used together"), "--cherry", "--left-only");
t/t6000-rev-list-misc.sh
+15
@@ -182,4 +182,19 @@ test_expect_success 'rev-list --unpacked' '
182 test_cmp expect actual
183 '
184
185 +test_expect_success 'rev-list one-sided unrelated symmetric diff' '
186 + test_tick &&
187 + git commit --allow-empty -m xyz &&
188 + git branch cmp &&
189 + git rebase --force-rebase --root &&
190 +
191 + git rev-list --left-only HEAD...cmp >head &&
192 + git rev-list --right-only HEAD...cmp >cmp &&
193 +
194 + sort head >head.sorted &&
195 + sort cmp >cmp.sorted &&
196 + comm -12 head.sorted cmp.sorted >actual &&
197 + test_line_count = 0 actual
198 +'
199 +
200 test_done