git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Matt Hunter <m@lfurio.us>
Date
Mar 30, 2025, 05:49 UTC
Message-ID
<20250330055809.1019090-1-m@lfurio.us>

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>
---
Patch applies to the current maint branch (git v2.49.0).

I made a best guess at what the most logical home for this test case should be, so please let me know if somewhere else is preferred. All tests pass when this is cherry-picked to seen. There is only a minor conflict, as a few different tests have appeared in this same spot.

 revision.c               |  2 ++
 t/t6000-rev-list-misc.sh | 12 ++++++++++++
 2 files changed, 14 insertions(+)
diff --git a/revision.c b/revision.c
index c4390f0938..e045445bc3 100644
--- a/revision.c
+++ b/revision.c
@@ -2488,10 +2488,12 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 			die(_("options '%s' and '%s' cannot be used together"),
 			    "--left-only", "--right-only/--cherry");
 		revs->left_only = 1;
+		revs->limited = 1;
 	} else if (!strcmp(arg, "--right-only")) {
 		if (revs->left_only)
 			die(_("options '%s' and '%s' cannot be used together"), "--right-only", "--left-only");
 		revs->right_only = 1;
+		revs->limited = 1;
 	} else if (!strcmp(arg, "--cherry")) {
 		if (revs->left_only)
 			die(_("options '%s' and '%s' cannot be used together"), "--cherry", "--left-only");
diff --git a/t/t6000-rev-list-misc.sh b/t/t6000-rev-list-misc.sh
index 6289a2e8b0..58f1f746e0 100755
--- a/t/t6000-rev-list-misc.sh
+++ b/t/t6000-rev-list-misc.sh
@@ -182,4 +182,16 @@ test_expect_success 'rev-list --unpacked' '
 	test_cmp expect actual
 '
 
+test_expect_success 'rev-list one-sided unrelated symmetric diff' '
+	test_tick &&
+	git commit --allow-empty -m xyz &&
+	git branch cmp &&
+	git rebase --force-rebase --root &&
+
+	git rev-list --left-only  HEAD...cmp >head &&
+	git rev-list --right-only HEAD...cmp >cmp  &&
+
+	test $(comm -12 <(sort head) <(sort cmp) | wc -l) = "0"
+'
+
 test_done

base-commit: 683c54c999c301c2cd6f715c411407c413b1d84e
-- 
2.49.0
Next: Johannes Sixt
Message 1 of 9 in “revision: fix --left/right-only use with unrelated histories”
  1. revision: fix --left/right-only use with unrelated historiesMatt Hunter, Mar 30, 2025
  2. Johannes SixtMar 30, 2025
  3. Junio C HamanoApr 1, 2025
  4. Phillip WoodMar 30, 2025
  5. Matt HunterMar 30, 2025
  6. phillip.wood123@gmail.comApr 2, 2025
  7. Matt HunterApr 4, 2025
  8. revision: fix --left/right-only use with unrelated historiesMatt Hunter, Mar 30, 2025
  9. Junio C HamanoApr 11, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.