-
Notifications
You must be signed in to change notification settings - Fork 101
Add -M/--find-renames option and blame.renames config to control rename detection #755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: vfs-2.49.0
Are you sure you want to change the base?
Changes from 2 commits
6aaf59e
47687ca
b90bbeb
6db5ed9
8df9781
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1423,10 +1423,17 @@ static struct blame_origin *find_rename(struct repository *r, | |
struct blame_origin *porigin = NULL; | ||
struct diff_options diff_opts; | ||
int i; | ||
extern int rename_detection_mode; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this won't work. You declared it as Instead, you have to introduce a new attribute in |
||
|
||
repo_diff_setup(r, &diff_opts); | ||
diff_opts.flags.recursive = 1; | ||
diff_opts.detect_rename = DIFF_DETECT_RENAME; | ||
/* | ||
* Use rename_detection_mode if specified, otherwise default to DIFF_DETECT_RENAME | ||
* For mode values > 0 and < 100, use it as similarity threshold | ||
*/ | ||
diff_opts.detect_rename = (rename_detection_mode == 0) ? 0 : | ||
(rename_detection_mode > 0) ? | ||
rename_detection_mode : DIFF_DETECT_RENAME; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only place where you actually use |
||
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT; | ||
diff_opts.single_follow = origin->path; | ||
diff_setup_done(&diff_opts); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/bin/sh | ||
|
||
test_description='git blame rename detection control' | ||
|
||
. ./test-lib.sh | ||
|
||
test_expect_success 'setup test file rename with content changes' ' | ||
git init && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do study other |
||
echo abc >1.txt && | ||
echo def >>1.txt && | ||
echo ghi >>1.txt && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
git add . && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
git commit -m "Initial commit" && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to prefix this with |
||
|
||
git mv 1.txt 2.txt && | ||
echo abc >2.txt && | ||
echo 123 >>2.txt && | ||
echo ghi >>2.txt && | ||
git add . && | ||
git commit -m "Rename+edit together" | ||
' | ||
|
||
# This test confirms that by default, git blame follows partial-file renames | ||
test_expect_success 'git blame follows inexact renames by default' ' | ||
FIXED_1=$(git rev-parse --short HEAD^) && | ||
FIXED_2=$(git rev-parse --short HEAD) && | ||
|
||
git blame 2.txt >output && | ||
grep "$FIXED_1" output | grep -q abc && | ||
grep "$FIXED_2" output | grep -q 123 && | ||
grep "$FIXED_1" output | grep -q ghi | ||
' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is too focused, and unnecessary. We really only need to verify that |
||
|
||
# This test confirms that --no-find-renames or -M0 turns off rename detection | ||
test_expect_success 'git blame can disable rename detection' ' | ||
git blame --no-find-renames 2.txt >output && | ||
! grep -q 1.txt output | ||
' | ||
|
||
# This test confirms that -M100 only follows exact renames | ||
test_expect_success 'git blame can restrict to exact renames' ' | ||
git blame -M100 2.txt >output && | ||
! grep -q 1.txt output | ||
' | ||
|
||
# This test checks that blame.renames config works | ||
test_expect_success 'blame.renames=false disables rename detection' ' | ||
git -c blame.renames=false blame 2.txt >output && | ||
! grep -q 1.txt output | ||
' | ||
|
||
# This test checks that -M with a score works | ||
test_expect_success 'git blame with similarity score follows renames above threshold' ' | ||
# Must follow 1.txt->2.txt rename for abc which are identical | ||
git blame -M70 2.txt >output && | ||
grep "$FIXED_1" output | grep -q abc && | ||
# Should not follow for others below threshold | ||
grep "$FIXED_2" output | grep -q 123 && | ||
grep "$FIXED_2" output | grep -q ghi | ||
' | ||
|
||
# This test checks that -M overrides blame.renames | ||
test_expect_success '-M overrides blame.renames config' ' | ||
# Using blame.renames=false but -M60 | ||
git -c blame.renames=false blame -M60 2.txt >output && | ||
grep "$FIXED_1" output | grep -q abc && | ||
# The rest would be below 60% threshold | ||
grep "$FIXED_2" output | grep -q 123 && | ||
grep "$FIXED_2" output | grep -q ghi | ||
' | ||
|
||
# This test checks that blame.renames with a score works | ||
test_expect_success 'blame.renames with score controls rename threshold' ' | ||
# Set threshold at 70%, abc is identical so above threshold | ||
git -c blame.renames=70 blame 2.txt >output && | ||
grep "$FIXED_1" output | grep -q abc && | ||
# Other lines below threshold | ||
grep "$FIXED_2" output | grep -q 123 && | ||
grep "$FIXED_2" output | grep -q ghi | ||
' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those are waaaaay too many test cases for the job. All you need to do is to run In fact, I highly suspect that this single test case that you need to add for this entire PR would find a much nicer home in one of the existing |
||
|
||
test_done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you cannot do that. The existing
-M
option is not about whole-file rename detection, therefore we cannot reuse that, and my instructions regarding-M
are moot.You have to introduce a new
--find-renames
option instead.