Changed the way we match mappings in NameToInternalName, modified and added new testcases #199
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.
Closes #198.
The new mapping match method is more robust than the previous one. It is described in detail below. We also provide more detailed explanations on what went wrong when adding a file to source control.
Matching mappings
For every mapping we have we can compute a composite score that describes how strong the match is. There are 3 main factors that need to be considered here.
Path matches
Here we have to check if the path in the
ExternalName
matches the path specified by the mapping.Extension matches
We confirm that the extension of the file in the
ExternalName
is the same as the extension in the mapping.Note: There is a possibility that the extension of some files might be different from the one in the mapping. e.g.
.dfi
files might be exported out as XML files. If the extension does the export, then we export the.dfi
file as-is, so we don't have to worry about this edge case. However, we also do a Load() of the file to try and get theInternalName
directly and that should catch cases like the one in the example.Coverage matches
Composite scores
Based on the match types above we have 12 possible composite scores.
Tie-breaker rules
If we need a tie-breaker, we consider a specfic match to be a better match. Specificity, for both Coverage and Path, is defined as being directly proportional to the length of the string. Thus, there are 4 possible scenarios:
We give coverage a higher priority. Note that a file extension has no notion of specificity.
Algorithm
We iterate through all the configured mappings and compute a composite score for each with respect to the
Name
function parameter. We keep track of the best match found up till that point and update it as we get a better match. In case, we get a mapping with the same composite score as the best one yet, we use the tie-breaker rules to resolve the best match. If the best match has a score >= 111, we have found a valid match. Otherwise we have not and provide explanations for what might have gone wrong.