-
-
Notifications
You must be signed in to change notification settings - Fork 354
fix similarity detection #1535
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
Merged
Merged
fix similarity detection #1535
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,6 +175,7 @@ fn tree_named(repo: &gix::Repository, rev_spec: impl AsRef<str>) -> gix::Tree { | |
} | ||
|
||
mod track_rewrites { | ||
use std::collections::HashMap; | ||
use std::convert::Infallible; | ||
|
||
use gix::{ | ||
|
@@ -398,34 +399,27 @@ mod track_rewrites { | |
// It's like the fixture doesn't get setup correctly. | ||
return Ok(()); | ||
} | ||
|
||
let mut expected = HashMap::<&BStr, (&BStr, u32)>::new(); | ||
expected.insert( | ||
"cli/src/commands/file/chmod.rs".into(), | ||
("cli/src/commands/chmod.rs".into(), 90), | ||
); | ||
expected.insert( | ||
"cli/src/commands/file/print.rs".into(), | ||
("cli/src/commands/cat.rs".into(), 90), | ||
); | ||
expected.insert( | ||
"cli/tests/test_file_chmod_command.rs".into(), | ||
("cli/tests/test_chmod_command.rs".into(), 88), | ||
); | ||
expected.insert( | ||
"cli/tests/test_file_print_command.rs".into(), | ||
("cli/tests/test_cat_command.rs".into(), 77), | ||
); | ||
|
||
let from = tree_named(&repo, "@~1"); | ||
let to = tree_named(&repo, "@"); | ||
|
||
let mut count = 0; | ||
let expected_location = [ | ||
"cli", | ||
"cli/src", | ||
"cli/tests", | ||
"cli/src/commands", | ||
"cli/src/commands/file", | ||
"cli/src/commands/file/print.rs", | ||
"cli/tests/test_file_print_command.rs", | ||
"cli/src/commands/file/chmod.rs", | ||
"cli/src/commands/file/mod.rs", | ||
"cli/tests/test_file_chmod_command.rs", | ||
"CHANGELOG.md", | ||
"cli/src/commands/mod.rs", | ||
"cli/tests/[email protected]", | ||
"cli/tests/runner.rs", | ||
"cli/tests/test_acls.rs", | ||
"cli/tests/test_diffedit_command.rs", | ||
"cli/tests/test_fix_command.rs", | ||
"cli/tests/test_global_opts.rs", | ||
"cli/tests/test_move_command.rs", | ||
"cli/tests/test_new_command.rs", | ||
"cli/tests/test_squash_command.rs", | ||
"cli/tests/test_unsquash_command.rs", | ||
]; | ||
let out = from | ||
.changes()? | ||
.track_path() | ||
|
@@ -441,48 +435,24 @@ mod track_rewrites { | |
.into(), | ||
) | ||
.for_each_to_obtain_tree(&to, |change| -> Result<_, Infallible> { | ||
// TODO: all rewrites here don't match what Git produces right now. | ||
// dbg!(change); | ||
assert_eq!(change.location, expected_location[count]); | ||
match count { | ||
0 | 1 | 2 | 3 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 => { | ||
assert!( | ||
matches!(change.event, Event::Modification { .. }), | ||
"ignore modifications" | ||
); | ||
} | ||
4 => { | ||
assert!(matches!(change.event, Event::Addition { entry_mode, .. } if entry_mode.is_tree())); | ||
assert_eq!(change.location, "cli/src/commands/file"); | ||
} | ||
5 => { | ||
assert_eq!(change.location, "cli/src/commands/file/print.rs"); | ||
assert!(matches!(change.event, Event::Rewrite {source_location, ..} if source_location == "cli/tests/test_cat_command.rs")); | ||
} | ||
6 => { | ||
assert_eq!(change.location, "cli/tests/test_file_print_command.rs"); | ||
assert!(matches!(change.event, Event::Rewrite {source_location, ..} if source_location == "cli/tests/test_chmod_command.rs")); | ||
} | ||
7 => { | ||
assert_eq!(change.location, "cli/src/commands/file/chmod.rs"); | ||
assert!(matches!(change.event, Event::Rewrite {source_location, ..} if source_location == "cli/src/commands/chmod.rs")); | ||
} | ||
8 => { | ||
assert_eq!(change.location, "cli/src/commands/file/mod.rs"); | ||
assert!(matches!(change.event, Event::Rewrite {source_location, ..} if source_location == "cli/src/commands/cat.rs")); | ||
} | ||
9 => { | ||
assert_eq!(change.location, "cli/tests/test_file_chmod_command.rs"); | ||
assert!(matches!(change.event, Event::Rewrite {source_location, ..} if source_location == "cli/tests/test_immutable_commits.rs")); | ||
} | ||
n => unreachable!("unexpected call: {n}"), | ||
}; | ||
count += 1; | ||
if let Event::Rewrite { | ||
source_location, | ||
diff: Some(diff), | ||
.. | ||
} = change.event | ||
{ | ||
// Round to percentage points to avoid floating point error. | ||
let similarity = (diff.similarity * 100.0) as u32; | ||
let v = expected.remove(change.location); | ||
assert_eq!(v, Some((source_location, similarity))); | ||
} | ||
Ok(Default::default()) | ||
})?; | ||
|
||
assert_eq!(expected, HashMap::new()); | ||
let out = out.rewrites.expect("tracking enabled"); | ||
assert_eq!( | ||
out.num_similarity_checks, 8, | ||
out.num_similarity_checks, 21, | ||
"this probably increases once the algorithm improves" | ||
); | ||
assert_eq!( | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.