diff --git a/docs/Darc.md b/docs/Darc.md index e78b8763ef..db0e8ac99e 100644 --- a/docs/Darc.md +++ b/docs/Darc.md @@ -3255,9 +3255,13 @@ darc vmr reset invalid-format Diffs the VMR and the product repositories. Outputs the diff to stdout or saves it to a patch file (or multiple if patch > 1 GB), if --output-path is provided. If input repos are not local, they'll be cloned locally and cleaned up afterwards, so the command might not be instant. +Use `--path` to limit the diff to specific paths within the repository. This option can be specified multiple times. + **Sample** ``` darc vmr diff C:\Path\VMR..https://github.com/dotnet/runtime:main +darc vmr diff C:\Path\VMR..https://github.com/dotnet/runtime:main --path src/libraries +darc vmr diff C:\Path\VMR..https://github.com/dotnet/runtime:main --path src/libraries --path src/coreclr ``` diff --git a/src/Microsoft.DotNet.Darc/Darc/Operations/VirtualMonoRepo/VmrDiffOperation.cs b/src/Microsoft.DotNet.Darc/Darc/Operations/VirtualMonoRepo/VmrDiffOperation.cs index 44f0d7d2e4..c6a42df817 100644 --- a/src/Microsoft.DotNet.Darc/Darc/Operations/VirtualMonoRepo/VmrDiffOperation.cs +++ b/src/Microsoft.DotNet.Darc/Darc/Operations/VirtualMonoRepo/VmrDiffOperation.cs @@ -124,7 +124,10 @@ private async Task FullVmrDiffAsync(Repo repo, Repo vmr) (NativePath tmpRepo, NativePath tmpVmr, string mapping) = await PrepareReposAsync(repo, vmr, tmpPath); IReadOnlyCollection exclusionFilters = await GetDiffFilters(vmr.Remote, vmr.Ref, mapping); - return await GenerateDiff(tmpRepo, tmpVmr, vmr.Ref, exclusionFilters); + IReadOnlyCollection 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 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 + .Where(kv => normalizedPaths.Any(p => kv.Key.StartsWith(p, StringComparison.OrdinalIgnoreCase))) + .ToDictionary(kv => kv.Key, kv => kv.Value); + } + foreach (var difference in fileDifferences.Values.OrderBy(v => v)) { Console.WriteLine(difference); diff --git a/src/Microsoft.DotNet.Darc/Darc/Options/VirtualMonoRepo/VmrDiffOptions.cs b/src/Microsoft.DotNet.Darc/Darc/Options/VirtualMonoRepo/VmrDiffOptions.cs index ae683f9720..e8941a90cc 100644 --- a/src/Microsoft.DotNet.Darc/Darc/Options/VirtualMonoRepo/VmrDiffOptions.cs +++ b/src/Microsoft.DotNet.Darc/Darc/Options/VirtualMonoRepo/VmrDiffOptions.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Collections.Generic; using CommandLine; using Microsoft.DotNet.Darc.Operations.VirtualMonoRepo; @@ -28,4 +29,9 @@ internal class VmrDiffOptions : VmrCommandLineOptions "Only list names of differing files and directories. " + "Listed differences are prefixed with +, - or * for addition, removal or differing content.")] public bool NameOnly { get; set; } + + [Option("path", Required = false, HelpText = + "Paths to include in the diff. When specified, only differences in these paths will be shown. " + + "Can be specified multiple times to include multiple paths.")] + public IEnumerable Paths { get; set; } = []; }