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

[PATCH] name-rev: test showing failure with non-monotonic commit dates

From
Jacob Keller <jacob.e.keller@intel.com>
Date
Feb 14, 2022, 21:01 UTC
Message-ID
<20220214210136.1532574-1-jacob.e.keller@intel.com>
From: Jacob Keller <jacob.keller@gmail.com>

If a commit in a sequence of linear history has a non-monotonically increasing commit timestamp, git name-rev will not properly name the commit.

However, if you use --annotate-stdin then the commit does actually get picked up and named properly.

Analyzing the source, it appears to be caused by the cutoff logic which is some sort of heuristic which relies on monotonically increasing commit dates.

This seems like the cutoff using commit date is some sort of heuristic which reduces the cost of describing something.. but --annotate-stdin and --all don't use it.

In the example setup I could do:
echo "<commit id>" | git name-rev --annotate-stdin

and get the expected result without the cutoff logic, and it seems at least on small repositories to be as fast as the normal attempt, except it produces accurate results.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
---
 t/t6120-describe.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh
index 9781b92aeddf..e9f897e42591 100755
--- a/t/t6120-describe.sh
+++ b/t/t6120-describe.sh
@@ -488,6 +488,68 @@ test_expect_success 'name-rev covers all conditions while looking at parents' '
 	)
 '
 
+# A-B-C-D-E-main
+#
+# Where C has a non-monotonically increasing commit timestamp w.r.t. other
+# commits
+test_expect_success 'non-monotonic commit dates setup' '
+	git init non-monotonic &&
+	(
+		cd non-monotonic &&
+
+		echo A >file &&
+		git add file &&
+		GIT_COMMITTER_DATE="2020-01-01 18:00" git commit -m A &&
+
+		echo B >file &&
+		git add file &&
+		GIT_COMMITTER_DATE="2020-01-02 18:00" git commit -m B &&
+
+		echo C >file &&
+		git add file &&
+		GIT_COMMITTER_DATE="2005-01-01 18:00" git commit -m C &&
+
+		echo D >file &&
+		git add file &&
+		GIT_COMMITTER_DATE="2020-01-04 18:00" git commit -m D &&
+
+		echo E >file &&
+		git add file &&
+		GIT_COMMITTER_DATE="2020-01-05 18:00" git commit -m E
+	)
+'
+
+test_expect_failure 'name-rev commit timestamp prevents naming commits' '
+	(
+		cd non-monotonic &&
+
+		B=$(git rev-parse main~3) &&
+
+		echo "$B main~3" >expect &&
+		git name-rev $B >actual &&
+
+		test_cmp expect actual
+	)
+'
+
+test_expect_success 'name-rev --all works with non-monotonic' '
+	(
+		cd non-monotonic &&
+
+		cat >expect <<EOF &&
+main
+main~1
+main~2
+main~3
+main~4
+EOF
+
+		git log --pretty=%H | git name-rev --annotate-stdin --name-only >actual &&
+
+		test_cmp expect actual
+	)
+'
+
 #               B
 #               o
 #                \
-- 
2.35.1.129.gb80121027d12
Next: Junio C Hamano
Message 1 of 10 in “name-rev: test showing failure with non-monotonic commit dates”
  1. name-rev: test showing failure with non-monotonic commit datesJacob Keller, Feb 14, 2022
  2. Junio C HamanoFeb 14, 2022
  3. Jacob KellerFeb 14, 2022
  4. Derrick StoleeFeb 15, 2022
  5. Keller, Jacob EFeb 15, 2022
  6. Junio C HamanoFeb 16, 2022
  7. Jacob KellerFeb 27, 2022
  8. Johannes SchindelinMar 9, 2022
  9. Ævar Arnfjörð BjarmasonFeb 15, 2022
  10. Keller, Jacob EFeb 16, 2022

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.