Skip to content
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

Use OrdinalIgnoreCase for all Source and Package source mapping implementation #4264

Merged
merged 11 commits into from
Oct 1, 2021

Conversation

erdembayar
Copy link
Contributor

@erdembayar erdembayar commented Sep 14, 2021

Bug

Fixes: NuGet/Home#11182
Fixes: NuGet/Home#11241

Regression? Last working version:

Description

@kartheekp-ms noticed we have inconsistent use of string comparison approach, after discussion we decided to use OrdinalIgnoreCase only for "Source and package source mapping", after my current changes I don't see any breaking or big difference after this change.

nuget.config used for my manual testing:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="encyclopaedia" value="https://api.nuget.org/v3/index.json" />
    <add key="Encyclopaedia"  value="C:\Users\xxxx\1111" />
    <add key="encyclopædia" value="C:\Users\xxxx\2222" />
    <add key="Encyclopædia" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/vssdk/nuget/v3/index.json" />
  </packageSources>
</configuration>

I didn't do changes in following places due to breaking/unwanted change:

In Apex tests I moved create nuget.config part before solution create action.

PR Checklist

  • PR has a meaningful title

  • PR has a linked issue.

  • Described changes

  • Tests

    • Automated tests added
    • OR
    • Test exception
    • OR
    • N/A
  • Documentation

    • Documentation PR or issue filled
    • OR
    • N/A

@@ -754,7 +754,7 @@ private ValueTask PopulateSourceRepoListAsync(IReadOnlyCollection<PackageSourceM
{
SelectedSource = PackageSources
// if the old active source still exists. Keep it as the active source.
.FirstOrDefault(i => StringComparer.CurrentCultureIgnoreCase.Equals(i.SourceName, selectedSourceName))
Copy link
Contributor Author

@erdembayar erdembayar Sep 14, 2021

Choose a reason for hiding this comment

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

This one decides current active source.

@@ -810,7 +810,7 @@ public string[] GetAvailableProjects()
safeAndDisplayName.Add(displayName);
}
// Sort with respect to the DisplayName
var sortedDisplayNames = safeAndDisplayName.OrderBy(i => i.Item2, StringComparer.CurrentCultureIgnoreCase).ToArray();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm reverting this one, because it's working project names, not related to source.

@@ -708,7 +708,7 @@ private void UpdateActiveSource(string activePackageSource)
else
{
var s = _packageSources.FirstOrDefault(
p => StringComparer.CurrentCultureIgnoreCase.Equals(p, activePackageSource));
Copy link
Contributor Author

@erdembayar erdembayar Sep 14, 2021

Choose a reason for hiding this comment

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

This one let user to choose between encyclopaedia and encyclopædia sources.
UI rendering not working correctly so created follow up issue NuGet/Home#11235

@@ -145,7 +145,7 @@ public bool Equals(PackageSource other)
return false;
}

return Name.Equals(other.Name, StringComparison.CurrentCultureIgnoreCase) &&
Copy link
Contributor Author

@erdembayar erdembayar Sep 14, 2021

Choose a reason for hiding this comment

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

After this change search is done on both encyclopaedia and encyclopædia sources as separate sources.

Copy link
Member

Choose a reason for hiding this comment

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

Were they treated the same before this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks it was not, so I'll revert changes here.
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverting because it's already doing Source compare with StringComparison.OrdinalIgnoreCase. Here actually Source is more important than Name.

@@ -107,7 +107,7 @@ public static bool IsHttpSource(string source, PackageSourceProvider packageSour
}

var packageSource = packageSourceProvider.LoadPackageSources()
.FirstOrDefault(p => p.Name.Equals(source, StringComparison.CurrentCultureIgnoreCase));
Copy link
Contributor Author

@erdembayar erdembayar Sep 15, 2021

Choose a reason for hiding this comment

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

This IsHttpSource method not used anywhere in our code, maybe we can remove it later.

@@ -64,7 +64,7 @@ public IEnumerable<PackageSource> DefaultPackageSources
// In a SettingValue representing a package source, the Key represents the name of the package source and the Value its source
_defaultPackageSources.Add(new PackageSource(source.GetValueAsPath(),
source.Key,
isEnabled: !disabledPackageSources.Any(p => p.Key.Equals(source.Key, StringComparison.CurrentCultureIgnoreCase)),
Copy link
Contributor Author

@erdembayar erdembayar Sep 15, 2021

Choose a reason for hiding this comment

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

It's about adding default sources from NuGetDefaults.config which exist on C:\Program Files (x86)\NuGet path on Windows. https://docs.microsoft.com/en-us/nuget/consume-packages/configuring-nuget-behavior
Looks not popular feature, not sure how relevant now days.
Maybe we deprecate this one in the future?

@@ -158,8 +158,8 @@ private static void AddDefaultPackageSources(List<PackageSource> loadedPackageSo

foreach (var packageSource in defaultPackageSources)
{
var sourceMatching = loadedPackageSources.Any(p => p.Source.Equals(packageSource.Source, StringComparison.CurrentCultureIgnoreCase));
Copy link
Contributor Author

@erdembayar erdembayar Sep 15, 2021

Choose a reason for hiding this comment

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

Related to https://github.com/NuGet/NuGet.Client/pull/4264/files#r708797119 on PMUI.
Looks not really relevant anymore.

@@ -302,8 +302,8 @@ private PackageSource GetPackageSource(string key, Dictionary<string, IndexedPac

foreach (var packageSource in _configurationDefaultSources)
{
var isSourceMatch = loadedPackageSources.Any(p => p.Source.Equals(packageSource.Source, StringComparison.CurrentCultureIgnoreCase));
Copy link
Contributor Author

@erdembayar erdembayar Sep 15, 2021

Choose a reason for hiding this comment

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

Related to https://github.com/NuGet/NuGet.Client/pull/4264/files#r708797119 for nuget.exe.
Triggered for nuget sources Add -Name "MyServer" -Source \\myserver\packages (https://docs.microsoft.com/en-us/nuget/reference/cli-reference/cli-ref-sources).
Looks not really relevant anymore.

@@ -48,7 +48,7 @@ public bool Equals(PackageSourceContextInfo other)
return false;
}

return Name.Equals(other.Name, StringComparison.CurrentCultureIgnoreCase) &&
Copy link
Contributor Author

@erdembayar erdembayar Sep 15, 2021

Choose a reason for hiding this comment

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

After this change search both encyclopaedia and encyclopædia sources as separate sources.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one also looks irrelevant change, reverting because it's already doing Source compare with StringComparison.OrdinalIgnoreCase. Here actually Source is more important than Name.

@@ -416,7 +416,7 @@ private TryUpdateSourceResults TryUpdateSource()
return TryUpdateSourceResults.NotUpdated;
}

if (selectedPackageSource.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase) && selectedPackageSource.Source.Equals(source, StringComparison.OrdinalIgnoreCase))
Copy link
Contributor Author

@erdembayar erdembayar Sep 15, 2021

Choose a reason for hiding this comment

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

I decided not to make this change in this file, revert the changes. It brings some unwanted side effects, if update existing source encyclopaedia with Encyclopædia on PMUI then save it creates duplicate entrees in nuget.config file.
Problem is when saving it check existing using packagesource key but due existing key entry following code it assumes above 2 are different hence creates another entry instead of updating it. Related to bdb3d6f#r709649975

@@ -425,7 +425,7 @@ private TryUpdateSourceResults TryUpdateSource()

// check to see if name has already been added
// also make sure it's not the same as the aggregate source ('All')
bool hasName = sourcesList.Any(ps => ps != selectedPackageSource && string.Equals(name, ps.Name, StringComparison.CurrentCultureIgnoreCase));
Copy link
Contributor Author

@erdembayar erdembayar Sep 15, 2021

Choose a reason for hiding this comment

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

I decided not to make this change in this file, revert the changes. It brings some unwanted side effects, if update existing source encyclopaedia with Encyclopædia on PMUI then save it creates duplicate entrees in nuget.config file.
Problem is when saving it check existing using packagesource key but due existing key entry following code it assumes above 2 are different hence creates another entry instead of updating it. Related to bdb3d6f#r709649975

@@ -77,8 +77,8 @@ public override bool Equals(object other)
return true;
}

return string.Equals(Key, source.Key, StringComparison.Ordinal) &&
Copy link
Contributor Author

@erdembayar erdembayar Sep 15, 2021

Choose a reason for hiding this comment

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

I decided to revert this change. For below input:

  <packageSources>
    <clear />
    <add key="encyclopaedia" value="C:\Users\eryondon\Desktop\NamespaceTestPackages\PublicRepository" />
    <add key="Encyclopaedia" value="https://api.nuget.org/v3/index.json" />
  </packageSources>

Before this change:
image

After this change:
image

Please note source url is quite different and looks breaking change experience for end user.

This reverts commit bdb3d6f.
@erdembayar erdembayar marked this pull request as ready for review September 16, 2021 00:20
@erdembayar erdembayar requested a review from a team as a code owner September 16, 2021 00:20

// Create nuget.config with Package namespace filtering rules before project is created.
CommonUtility.CreateConfigurationFile(Path.Combine(solutionDirectory, "NuGet.config"), $@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key=""ExternalRepository"" value=""{externalRepositoryPath}"" />
<add key=""PrivateRepository"" value=""{privateRepositoryPath}"" />
<add key=""encyclopaedia"" value=""{externalRepositoryPath}"" />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test "encyclopaedia" and "encyclopædia" sources used together doesn't crash VS PMUI setting.

@erdembayar
Copy link
Contributor Author

@NuGet/nuget-client
Please review.

Copy link
Member

@nkolev92 nkolev92 left a comment

Choose a reason for hiding this comment

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

The fact that there's so many culture comparison gives me a pause about the impact this change could have.

@@ -145,7 +145,7 @@ public bool Equals(PackageSource other)
return false;
}

return Name.Equals(other.Name, StringComparison.CurrentCultureIgnoreCase) &&
Copy link
Member

Choose a reason for hiding this comment

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

Were they treated the same before this change?

@@ -22,7 +23,7 @@ public void UpdateModel(IItemLoaderState loaderState)
PackageSearchStatus = Convert(loaderState.LoadingStatus);
ItemsFound = loaderState.ItemsCount;

var convertedList = new System.Collections.SortedList();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make VS stop crashing NuGet/Home#11241

@erdembayar erdembayar force-pushed the dev-eryondon-11182 branch 2 times, most recently from 1ab4aed to 29583e2 Compare October 1, 2021 02:12
@erdembayar erdembayar merged commit 6cf7a6e into dev Oct 1, 2021
@erdembayar erdembayar deleted the dev-eryondon-11182 branch October 1, 2021 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants