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

[PATCHv3 0/7] git describe blob

From
Stefan Beller <sbeller@google.com>
Date
Nov 2, 2017, 19:41 UTC
Message-ID
<20171102194148.2124-1-sbeller@google.com>
In-Reply-To
<20171031211852.13001-1-sbeller@google.com>
Thanks for the discussion on v2[1].
Interdiff is below, just fixing minor things.

We'll keep the original algorithm for now, deferring an improvement on the algorithm front towards a future developer.

Thanks, Stefan

[1] https://public-inbox.org/git/20171031211852.13001-1-sbeller@google.com/
Stefan Beller (7):
  t6120: fix typo in test name
  list-objects.c: factor out traverse_trees_and_blobs
  revision.h: introduce blob/tree walking in order of the commits
  builtin/describe.c: rename `oid` to avoid variable shadowing
  builtin/describe.c: print debug statements earlier
  builtin/describe.c: factor out describe_commit
  builtin/describe.c: describe a blob
 Documentation/git-describe.txt     |  13 +++-
 Documentation/rev-list-options.txt |   5 ++
 builtin/describe.c                 | 125 ++++++++++++++++++++++++++++---------
 list-objects.c                     |  52 +++++++++------
 revision.c                         |   2 +
 revision.h                         |   3 +-
 t/t6100-rev-list-in-order.sh       |  47 ++++++++++++++
 t/t6120-describe.sh                |  17 ++++-
 8 files changed, 214 insertions(+), 50 deletions(-)
 create mode 100755 t/t6100-rev-list-in-order.sh
diff --git c/Documentation/git-describe.txt w/Documentation/git-describe.txt
index 077c3c2193..79ec0be62a 100644
--- c/Documentation/git-describe.txt
+++ w/Documentation/git-describe.txt
@@ -11,7 +11,7 @@ SYNOPSIS
 [verse]
 'git describe' [--all] [--tags] [--contains] [--abbrev=<n>] [<commit-ish>...]
 'git describe' [--all] [--tags] [--contains] [--abbrev=<n>] --dirty[=<mark>]
-'git describe' [<options>] <blob-ish>
+'git describe' [<options>] <blob>
 
 DESCRIPTION
 -----------
diff --git c/builtin/describe.c w/builtin/describe.c
index 382cbae908..cf08bef344 100644
--- c/builtin/describe.c
+++ w/builtin/describe.c
@@ -440,6 +440,7 @@ struct process_commit_data {
 	struct object_id current_commit;
 	struct object_id looking_for;
 	struct strbuf *dst;
+	struct rev_info *revs;
 };
 
 static void process_commit(struct commit *commit, void *data)
@@ -456,6 +457,7 @@ static void process_object(struct object *obj, const char *path, void *data)
 		reset_revision_walk();
 		describe_commit(&pcd->current_commit, pcd->dst);
 		strbuf_addf(pcd->dst, ":%s", path);
+		pcd->revs->max_count = 0;
 	}
 }
 
@@ -463,7 +465,7 @@ static void describe_blob(struct object_id oid, struct strbuf *dst)
 {
 	struct rev_info revs;
 	struct argv_array args = ARGV_ARRAY_INIT;
-	struct process_commit_data pcd = { null_oid, oid, dst};
+	struct process_commit_data pcd = { null_oid, oid, dst, &revs};
 
 	argv_array_pushl(&args, "internal: The first arg is not parsed",
 		"--all", "--reflog", /* as many starting points as possible */
@@ -497,14 +499,12 @@ static void describe(const char *arg, int last_one)
 		die(_("Not a valid object name %s"), arg);
 	cmit = lookup_commit_reference_gently(&oid, 1);
 
-	if (cmit) {
+	if (cmit)
 		describe_commit(&oid, &sb);
-	} else {
-		if (lookup_blob(&oid))
-			describe_blob(oid, &sb);
-		else
-			die(_("%s is neither a commit nor blob"), arg);
-	}
+	else if (lookup_blob(&oid))
+		describe_blob(oid, &sb);
+	else
+		die(_("%s is neither a commit nor blob"), arg);
 
 	puts(sb.buf);
 
diff --git c/list-objects.c w/list-objects.c
index 03438e5a8b..07a92f35fe 100644
--- c/list-objects.c
+++ w/list-objects.c
@@ -184,13 +184,13 @@ static void add_pending_tree(struct rev_info *revs, struct tree *tree)
 }
 
 static void traverse_trees_and_blobs(struct rev_info *revs,
-				     struct strbuf *base_path,
+				     struct strbuf *base,
 				     show_object_fn show_object,
 				     void *data)
 {
 	int i;
 
-	assert(base_path->len == 0);
+	assert(base->len == 0);
 
 	for (i = 0; i < revs->pending.nr; i++) {
 		struct object_array_entry *pending = revs->pending.objects + i;
@@ -208,12 +208,12 @@ static void traverse_trees_and_blobs(struct rev_info *revs,
 			path = "";
 		if (obj->type == OBJ_TREE) {
 			process_tree(revs, (struct tree *)obj, show_object,
-				     base_path, path, data);
+				     base, path, data);
 			continue;
 		}
 		if (obj->type == OBJ_BLOB) {
 			process_blob(revs, (struct blob *)obj, show_object,
-				     base_path, path, data);
+				     base, path, data);
 			continue;
 		}
 		die("unknown pending object %s (%s)",
diff --git c/t/t6100-rev-list-in-order.sh w/t/t6100-rev-list-in-order.sh
index 651666979b..d4d539b0da 100755
--- c/t/t6100-rev-list-in-order.sh
+++ w/t/t6100-rev-list-in-order.sh
@@ -1,21 +1,22 @@
 #!/bin/sh
 
-test_description='miscellaneous rev-list tests'
+test_description='rev-list testing in-commit-order'
 
 . ./test-lib.sh
 
-
-test_expect_success 'setup' '
+test_expect_success 'rev-list --in-commit-order' '
 	for x in one two three four
 	do
 		echo $x >$x &&
 		git add $x &&
-		git commit -m "add file $x"
+		git commit -m "add file $x" ||
+		return 1
 	done &&
 	for x in four three
 	do
 		git rm $x &&
-		git commit -m "remove $x"
+		git commit -m "remove $x" ||
+		return 1
 	done &&
 	git rev-list --in-commit-order --objects HEAD >actual.raw &&
 	cut -c 1-40 >actual <actual.raw &&
@@ -32,9 +33,9 @@ test_expect_success 'setup' '
 		HEAD~2^{tree}
 		HEAD~2^{tree}:four
 		HEAD~3^{commit}
-		# HEAD~3^{tree} skipped
+		# HEAD~3^{tree} skipped, same as HEAD~1^{tree}
 		HEAD~4^{commit}
-		# HEAD~4^{tree} skipped
+		# HEAD~4^{tree} skipped, same as HEAD^{tree}
 		HEAD~5^{commit}
 		HEAD~5^{tree}
 	EOF
diff --git c/t/t6120-describe.sh w/t/t6120-describe.sh
index fd329f173a..aec6ed192d 100755
--- c/t/t6120-describe.sh
+++ w/t/t6120-describe.sh
@@ -319,7 +319,7 @@ test_expect_success 'describe a blob at a tag' '
 	test_cmp expect actual
 '
 
-test_expect_success 'describe a surviving blob' '
+test_expect_success 'describe a blob with commit-ish' '
 	git commit --allow-empty -m "empty commit" &&
 	git describe HEAD:file >actual &&
 	grep unique-file-1-g actual
Previous: Junio C HamanoNext: Stefan Beller
Message 94 of 110 in “git-describe <blob> ?”
  1. 0/3 git-describe <blob> ?Stefan Beller, Oct 28, 2017
  2. 1/3 list-objects.c: factor out traverse_trees_and_blobsStefan Beller, Oct 28, 2017
  3. 2/3 revision.h: introduce blob/tree walking in order of the commitsStefan Beller, Oct 28, 2017
  4. Johannes SchindelinOct 28, 2017
  5. Stefan BellerOct 29, 2017
  6. Stefan BellerOct 29, 2017
  7. Junio C HamanoOct 29, 2017
  8. 3/3 builtin/describe: describe blobsStefan Beller, Oct 28, 2017
  9. Johannes SchindelinOct 28, 2017
  10. Jacob KellerOct 28, 2017
  11. Stefan BellerOct 29, 2017
  12. Kevin DaudtOct 29, 2017
  13. Johannes SchindelinOct 29, 2017
  14. Johannes SchindelinOct 28, 2017
  15. Stefan BellerOct 29, 2017
  16. Johannes SchindelinOct 28, 2017
  17. 0/7 git-describe <blob>Stefan Beller, Oct 31, 2017
  18. 1/7 list-objects.c: factor out traverse_trees_and_blobsStefan Beller, Oct 31, 2017
  19. Junio C HamanoOct 31, 2017
  20. 5/7 builtin/describe.c: factor out describe_commitStefan Beller, Oct 31, 2017
  21. 4/7 builtin/describe.c: print debug statements earlierStefan Beller, Oct 31, 2017
  22. Junio C HamanoOct 31, 2017
  23. Stefan BellerOct 31, 2017
  24. 6/7 builtin/describe.c: describe a blobStefan Beller, Oct 31, 2017
  25. Junio C HamanoOct 31, 2017
  26. Stefan BellerOct 31, 2017
  27. Junio C HamanoNov 1, 2017
  28. Stefan BellerNov 1, 2017
  29. Junio C HamanoNov 2, 2017
  30. Junio C HamanoNov 2, 2017
  31. Philip OakleyNov 4, 2017
  32. Junio C HamanoNov 5, 2017
  33. Philip OakleyNov 6, 2017
  34. Stefan BellerNov 9, 2017
  35. Philip OakleyNov 10, 2017
  36. Junio C HamanoNov 10, 2017
  37. 0/1 describe a blob: with better docsStefan Beller, Nov 10, 2017
  38. builtin/describe.c: describe a blobStefan Beller, Nov 10, 2017
  39. Junio C HamanoNov 13, 2017
  40. Stefan BellerNov 14, 2017
  41. Philip OakleyNov 20, 2017
  42. Philip OakleyNov 20, 2017
  43. Junio C HamanoNov 1, 2017
  44. 7/7 t6120: fix typo in test nameStefan Beller, Oct 31, 2017
  45. Junio C HamanoNov 1, 2017
  46. Stefan BellerNov 1, 2017
  47. Junio C HamanoNov 2, 2017
  48. 3/7 builtin/describe.c: rename `oid` to avoid variable shadowingStefan Beller, Oct 31, 2017
  49. Jacob KellerOct 31, 2017
  50. 2/7 revision.h: introduce blob/tree walking in order of the commitsStefan Beller, Oct 31, 2017
  51. Junio C HamanoOct 31, 2017
  52. Stefan BellerOct 31, 2017
  53. 0/7 git describe blobStefan Beller, Oct 31, 2017
  54. 1/7 list-objects.c: factor out traverse_trees_and_blobsStefan Beller, Oct 31, 2017
  55. Junio C HamanoNov 1, 2017
  56. 4/7 builtin/describe.c: print debug statements earlierStefan Beller, Oct 31, 2017
  57. Eric SunshineOct 31, 2017
  58. 7/7 t6120: fix typo in test nameStefan Beller, Oct 31, 2017
  59. 2/7 revision.h: introduce blob/tree walking in order of the commitsStefan Beller, Oct 31, 2017
  60. Junio C HamanoNov 1, 2017
  61. Johannes SchindelinNov 1, 2017
  62. Junio C HamanoNov 1, 2017
  63. Stefan BellerNov 1, 2017
  64. Johannes SchindelinNov 1, 2017
  65. Stefan BellerNov 1, 2017
  66. Johannes SchindelinNov 1, 2017
  67. Stefan BellerNov 1, 2017
  68. Johannes SchindelinNov 1, 2017
  69. Jeff KingNov 1, 2017
  70. Johannes SchindelinNov 1, 2017
  71. Junio C HamanoNov 2, 2017
  72. 6/7 builtin/describe.c: describe a blobStefan Beller, Oct 31, 2017
  73. Eric SunshineOct 31, 2017
  74. Stefan BellerNov 1, 2017
  75. Junio C HamanoNov 1, 2017
  76. Johannes SchindelinNov 1, 2017
  77. Stefan BellerNov 1, 2017
  78. Jacob KellerNov 1, 2017
  79. Johannes SchindelinNov 1, 2017
  80. Stefan BellerNov 1, 2017
  81. Johannes SchindelinNov 1, 2017
  82. Stefan BellerNov 1, 2017
  83. Jacob KellerNov 2, 2017
  84. Junio C HamanoNov 3, 2017
  85. Jacob KellerNov 3, 2017
  86. Junio C HamanoNov 3, 2017
  87. Andreas SchwabNov 2, 2017
  88. Stefan BellerNov 2, 2017
  89. Johannes SchindelinNov 3, 2017
  90. Stefan BellerNov 1, 2017
  91. 3/7 builtin/describe.c: rename `oid` to avoid variable shadowingStefan Beller, Oct 31, 2017
  92. 5/7 builtin/describe.c: factor out describe_commitStefan Beller, Oct 31, 2017
  93. Junio C HamanoNov 1, 2017
  94. 0/7 git describe blobStefan Beller, Nov 2, 2017
  95. 1/7 t6120: fix typo in test nameStefan Beller, Nov 2, 2017
  96. 2/7 list-objects.c: factor out traverse_trees_and_blobsStefan Beller, Nov 2, 2017
  97. 3/7 revision.h: introduce blob/tree walking in order of the commitsStefan Beller, Nov 2, 2017
  98. Jonathan TanNov 14, 2017
  99. 6/7 builtin/describe.c: factor out describe_commitStefan Beller, Nov 2, 2017
  100. 5/7 builtin/describe.c: print debug statements earlierStefan Beller, Nov 2, 2017
  101. Jonathan TanNov 14, 2017
  102. Stefan BellerNov 14, 2017
  103. 7/7 builtin/describe.c: describe a blobStefan Beller, Nov 2, 2017
  104. Jonathan TanNov 14, 2017
  105. Stefan BellerNov 14, 2017
  106. Jonathan TanNov 14, 2017
  107. 4/7 builtin/describe.c: rename `oid` to avoid variable shadowingStefan Beller, Nov 2, 2017
  108. Jacob KellerNov 3, 2017
  109. Junio C HamanoNov 3, 2017
  110. Stefan BellerNov 3, 2017

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.