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

[PATCH on en/rename-progress v2] diffcore-rename: make diff-tree -l0 mean -l<large>

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Nov 29, 2017, 20:11 UTC
Message-ID
<20171129201154.192379-1-jonathantanmy@google.com>
In-Reply-To
<20171129183200.178183-1-jonathantanmy@google.com>

In the documentation of diff-tree, it is stated that the -l option "prevents rename/copy detection from running if the number of rename/copy targets exceeds the specified number". The documentation does not mention any special handling for the number 0, but the implementation before commit 9f7e4bfa3b ("diff: remove silent clamp of renameLimit", 2017-11-13) treated 0 as a special value indicating that the rename limit is to be a very large number instead.

The commit 9f7e4bfa3b changed that behavior, treating 0 as 0. Revert this behavior to what it was previously. This allows existing scripts and tools that use "-l0" to continue working. The alternative (to have "-l0" suppress rename detection) is probably much less useful, since users can just refrain from specifying -M and/or -C to have the same effect.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
There are multiple issues with the commit message, so I am sending this
new version out.
v2 is exactly the same as previously, except that the commit message is
changed following Elijah Newren's and Jonathan Nieder's comments.
---
 diffcore-rename.c      |  2 ++
 t/t4001-diff-rename.sh | 15 +++++++++++++++
 2 files changed, 17 insertions(+)
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 9ca0eaec7..245e999fe 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -392,6 +392,8 @@ static int too_many_rename_candidates(int num_create,
 	 *
 	 *    num_create * num_src > rename_limit * rename_limit
 	 */
+	if (rename_limit <= 0)
+		rename_limit = 32767;
 	if ((num_create <= rename_limit || num_src <= rename_limit) &&
 	    ((uint64_t)num_create * (uint64_t)num_src
 	     <= (uint64_t)rename_limit * (uint64_t)rename_limit))
diff --git a/t/t4001-diff-rename.sh b/t/t4001-diff-rename.sh
index 0d1fa45d2..eadf4f624 100755
--- a/t/t4001-diff-rename.sh
+++ b/t/t4001-diff-rename.sh
@@ -230,4 +230,19 @@ test_expect_success 'rename pretty print common prefix and suffix overlap' '
 	test_i18ngrep " d/f/{ => f}/e " output
 '
 
+test_expect_success 'diff-tree -l0 defaults to a big rename limit, not zero' '
+	test_write_lines line1 line2 line3 >myfile &&
+	git add myfile &&
+	git commit -m x &&
+
+	test_write_lines line1 line2 line4 >myotherfile &&
+	git rm myfile &&
+	git add myotherfile &&
+	git commit -m x &&
+
+	git diff-tree -M -l0 HEAD HEAD^ >actual &&
+	# Verify that a rename from myotherfile to myfile was detected
+	grep "myotherfile.*myfile" actual
+'
+
 test_done
-- 
2.15.0.173.g9268cf4a2.dirty
Previous: Jonathan NiederNext: Jonathan Nieder
Message 5 of 7 in “diffcore-rename: make diff-tree -l0 mean -l<large>”
  1. diffcore-rename: make diff-tree -l0 mean -l<large>Jonathan Tan, Nov 29, 2017
  2. Elijah NewrenNov 29, 2017
  3. Jonathan TanNov 29, 2017
  4. Jonathan NiederNov 29, 2017
  5. diffcore-rename: make diff-tree -l0 mean -l<large>Jonathan Tan, Nov 29, 2017
  6. Jonathan NiederNov 29, 2017
  7. Elijah NewrenNov 29, 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.