Skip to content

Add --path filter to darc vmr diff#6145

Merged
premun merged 2 commits intomainfrom
copilot/let-darc-vmr-diff-certain-files
Apr 1, 2026
Merged

Add --path filter to darc vmr diff#6145
premun merged 2 commits intomainfrom
copilot/let-darc-vmr-diff-certain-files

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 30, 2026

darc vmr diff always diffed the entire repository with no way to scope it to specific paths.

Usage

# Diff only src/libraries
darc vmr diff C:\Path\VMR..https://github.com/dotnet/runtime:main --path src/libraries

# Diff multiple paths
darc vmr diff C:\Path\VMR..https://github.com/dotnet/runtime:main --path src/libraries --path src/coreclr

# Also works with --name-only
darc vmr diff --name-only --path src/libraries

#5572

Copilot AI linked an issue Mar 30, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add option to diff specific paths with darc vmr diff Add --path filter to darc vmr diff Mar 30, 2026
Copilot AI requested a review from premun March 30, 2026 11:27
Copy link
Copy Markdown
Member

@premun premun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, works

@premun premun marked this pull request as ready for review April 1, 2026 14:42
Copilot AI review requested due to automatic review settings April 1, 2026 14:42
@premun premun enabled auto-merge (squash) April 1, 2026 14:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a --path filter to darc vmr diff to allow scoping diffs to one or more subpaths, improving usability when working with large repos/VMRs.

Changes:

  • Introduced --path (multi-valued) option on darc vmr diff.
  • Full diff mode: prepends user-provided pathspecs to the existing exclusion filter list and normalizes path separators.
  • Name-only mode: post-filters computed differences by path prefix and normalizes path separators; updated docs with examples.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/Microsoft.DotNet.Darc/Darc/Options/VirtualMonoRepo/VmrDiffOptions.cs Adds the --path CLI option for scoping diffs.
src/Microsoft.DotNet.Darc/Darc/Operations/VirtualMonoRepo/VmrDiffOperation.cs Applies --path filtering in both full diff and name-only diff modes.
docs/Darc.md Documents --path usage and provides examples.

Comment on lines 126 to +130
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);
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--path normalization differs between full diff and name-only modes. Here only backslashes are replaced, but leading '/', './', or '' aren’t trimmed like they are in FileTreeDiffAsync, which can make --path /src/foo behave 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 building allFilters.

Copilot uses AI. Check for mistakes.
Comment on lines +783 to +784
fileDifferences = fileDifferences
.Where(kv => normalizedPaths.Any(p => kv.Key.StartsWith(p, StringComparison.OrdinalIgnoreCase)))
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name-only --path filter uses StartsWith, which can over-match sibling paths (e.g., --path src/lib would also include src/libraries). If the intention is to treat --path as a directory/file boundary (like git pathspecs), consider matching either exact path or prefix followed by '/' (and normalize any trailing slashes). Also consider whether OrdinalIgnoreCase is desired on case-sensitive platforms; using an OS-dependent comparison would better mirror git behavior.

Suggested change
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)))

Copilot uses AI. Check for mistakes.
var normalizedPaths = _options.Paths
.Select(p => "/" + p.TrimStart('/', '\\').Replace('\\', '/'))
.ToList();
fileDifferences = fileDifferences
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we essentially do a full diff and filter it?
Prob doesn't really matter but in theory we could not search the files that are not on the provided paths too

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rip

@premun premun merged commit 3e348fa into main Apr 1, 2026
13 of 16 checks passed
@premun premun deleted the copilot/let-darc-vmr-diff-certain-files branch April 1, 2026 15:12
Copilot stopped work on behalf of premun due to an error April 1, 2026 15:12
Copilot AI requested a review from premun April 1, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Let darc vmr diff diff just certain files

5 participants