-
Notifications
You must be signed in to change notification settings - Fork 80
Add --path filter to darc vmr diff
#6145
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
Changes from all commits
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -124,7 +124,10 @@ private async Task<int> FullVmrDiffAsync(Repo repo, Repo vmr) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| (NativePath tmpRepo, NativePath tmpVmr, string mapping) = await PrepareReposAsync(repo, vmr, tmpPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| IReadOnlyCollection<string> exclusionFilters = await GetDiffFilters(vmr.Remote, vmr.Ref, mapping); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return await GenerateDiff(tmpRepo, tmpVmr, vmr.Ref, exclusionFilters); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| IReadOnlyCollection<string> allFilters = _options.Paths.Any() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? [.. _options.Paths.Select(p => p.Replace('\\', '/')), .. exclusionFilters] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| : exclusionFilters; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return await GenerateDiff(tmpRepo, tmpVmr, vmr.Ref, allFilters); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| finally | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -772,6 +775,16 @@ private async Task<int> FileTreeDiffAsync(Repo sourceRepo, Repo vmrRepo, bool fr | |||||||||||||||||||||||||||||||||||||||||||||||||||
| ProcessVmrOnlyFiles(filesOnlyInVmr, fileDifferences, directoriesToProcess, fromRepoDirection); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (_options.Paths.Any()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| var normalizedPaths = _options.Paths | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| .Select(p => "/" + p.TrimStart('/', '\\').Replace('\\', '/')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| .ToList(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| fileDifferences = fileDifferences | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
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. so we essentially do a full diff and filter it?
Member
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. Right. Yeah, that would make it run much faster. @copilot can you make this change?
Member
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. rip |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| .Where(kv => normalizedPaths.Any(p => kv.Key.StartsWith(p, StringComparison.OrdinalIgnoreCase))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+783
to
+784
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| fileDifferences = fileDifferences | |
| .Where(kv => normalizedPaths.Any(p => kv.Key.StartsWith(p, StringComparison.OrdinalIgnoreCase))) | |
| var pathComparison = OperatingSystem.IsWindows() | |
| ? StringComparison.OrdinalIgnoreCase | |
| : StringComparison.Ordinal; | |
| bool PathMatchesFilter(string filePath, string filterPath) | |
| { | |
| // Both filePath and filterPath are expected to be normalized to use '/' and start with '/' | |
| if (filePath.Equals(filterPath, pathComparison)) | |
| { | |
| return true; | |
| } | |
| if (!filterPath.EndsWith("/", StringComparison.Ordinal)) | |
| { | |
| filterPath += "/"; | |
| } | |
| return filePath.StartsWith(filterPath, pathComparison); | |
| } | |
| fileDifferences = fileDifferences | |
| .Where(kv => normalizedPaths.Any(p => PathMatchesFilter(kv.Key, p))) |
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.
--pathnormalization differs between full diff and name-only modes. Here only backslashes are replaced, but leading '/', './', or '' aren’t trimmed like they are inFileTreeDiffAsync, which can make--path /src/foobehave differently depending on--name-only. Consider centralizing path normalization (trim leading separators/"./", replace '\' with '/', and ignore/throw on empty/whitespace entries) and using it in both modes before buildingallFilters.