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

[PATCH 2/2] Fix ranges with git-show

From
Thomas Rast <trast@student.ethz.ch>
Date
Jun 19, 2012, 20:04 UTC
Message-ID
<a598bb8c20221679e295caa743197c86219eda68.1340136145.git.trast@student.ethz.ch>
In-Reply-To
<d3e839101b031a7208e74a0b6e22d343d5a093e9.1340136145.git.trast@student.ethz.ch>

As explained in the previous commit, git-show's DWIM walking mode fails with ranges where propagating the UNINTERESTING marks is needed for correctness.

To fix this issue, use a new strategy for of dealing with commits: handle everything else first, then pass all commits to a single revision walker "in bulk". This keeps the UNINTERESTING commits and correctly shows all ranges.

Sadly we can use this only when actually walking. In other cases, such as 'git show A B', it would seem more important to keep the order of the objects shown consistent with the command line. There are no such guarantees when running the walker with several commits (even in no-walk mode), so we still feed them one by one.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 builtin/log.c   | 16 ++++++++++++----
 t/t7007-show.sh |  2 +-
 2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/builtin/log.c b/builtin/log.c
index 4f1b42a..26f6c01 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -444,6 +444,7 @@ static void show_rev_tweak_rev(struct rev_info *rev, struct setup_revision_opt *
 int cmd_show(int argc, const char **argv, const char *prefix)
 {
 	struct rev_info rev;
+	struct object_array commits = {0};
 	struct object_array_entry *objects;
 	struct setup_revision_opt opt;
 	struct pathspec match_all;
@@ -505,15 +506,22 @@ int cmd_show(int argc, const char **argv, const char *prefix)
 			rev.shown_one = 1;
 			break;
 		case OBJ_COMMIT:
-			rev.pending.nr = rev.pending.alloc = 0;
-			rev.pending.objects = NULL;
-			add_object_array(o, name, &rev.pending);
-			ret = cmd_log_walk(&rev);
+			add_object_array(o, name, &commits);
+			if (rev.no_walk) {
+				rev.pending = commits;
+				ret = cmd_log_walk(&rev);
+				commits.nr = commits.alloc = 0;
+				commits.objects = NULL;
+			}
 			break;
 		default:
 			ret = error(_("Unknown type: %d"), o->type);
 		}
 	}
+	if (!ret && commits.nr) {
+		rev.pending = commits;
+		ret = cmd_log_walk(&rev);
+	}
 	free(objects);
 	return ret;
 }
diff --git a/t/t7007-show.sh b/t/t7007-show.sh
index 1c43963..3936ff7 100755
--- a/t/t7007-show.sh
+++ b/t/t7007-show.sh
@@ -57,7 +57,7 @@ EOF
 	test_cmp expect actual.filtered
 '
 
-test_expect_failure 'showing a range walks (Y shape, ^ last)' '
+test_expect_success 'showing a range walks (Y shape, ^ last)' '
 	cat >expect <<EOF &&
 commit $(git rev-parse main3)
 commit $(git rev-parse main2)
-- 
1.7.11.266.g2b10bc0
Previous: Thomas RastNext: Junio C Hamano
Message 2 of 7 in “Demonstrate git-show is broken with ranges”
  1. 1/2 Demonstrate git-show is broken with rangesThomas Rast, Jun 19, 2012
  2. 2/2 Fix ranges with git-showThomas Rast, Jun 19, 2012
  3. Junio C HamanoJun 19, 2012
  4. Junio C HamanoJun 19, 2012
  5. Junio C HamanoJun 19, 2012
  6. Thomas RastJun 20, 2012
  7. Junio C HamanoJun 20, 2012

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.