Skip to content

Commit 1edb104

Browse files
authored
Revert "dotnet nuget why reports requested as well as resolved versions (#7017)" (#7212)
This reverts commit 1a85f19.
1 parent b8bbe4b commit 1edb104

28 files changed

Lines changed: 963 additions & 859 deletions

File tree

src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Why/DependencyGraphFinder.cs

Lines changed: 227 additions & 124 deletions
Large diffs are not rendered by default.

src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Why/DependencyGraphPrinter.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Collections.Generic;
88
using System.Linq;
99
using NuGet.Shared;
10-
using NuGet.Versioning;
1110
using Spectre.Console;
1211
using Spectre.Console.Rendering;
1312

@@ -97,19 +96,7 @@ private static void PrintDependencyGraphPerFramework(List<string> frameworks, Li
9796

9897
private static IRenderable GetNodeText(DependencyNode node, string targetPackage)
9998
{
100-
string text;
101-
102-
if (node is PackageNode pkgNode)
103-
{
104-
string resolved = pkgNode.ResolvedVersion.OriginalVersion ?? pkgNode.ResolvedVersion.ToString();
105-
string requested = pkgNode.RequestedVersion.ToString("f", VersionRangeFormatter.Instance);
106-
text = $"{node.Id}@{resolved} ({requested})";
107-
}
108-
else
109-
{
110-
text = node.Id;
111-
}
112-
99+
string text = $"{node.Id} (v{node.Version})";
113100
Style? style = node.Id.Equals(targetPackage, StringComparison.OrdinalIgnoreCase)
114101
? new Style(foreground: TargetPackageColor)
115102
: null;

src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/Why/DependencyNode.cs

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,76 +5,49 @@
55

66
using System;
77
using System.Collections.Generic;
8-
using System.Linq;
9-
using NuGet.Versioning;
8+
using NuGet.Shared;
109

1110
namespace NuGet.CommandLine.XPlat.Commands.Why
1211
{
1312
/// <summary>
1413
/// Represents a node in the package dependency graph.
1514
/// </summary>
16-
internal abstract record DependencyNode(string Id, HashSet<DependencyNode> Children)
15+
internal class DependencyNode
1716
{
18-
public abstract bool Equals(DependencyNode? other);
17+
public string Id { get; set; }
18+
public string Version { get; set; }
19+
public HashSet<DependencyNode> Children { get; set; }
1920

20-
public abstract override int GetHashCode();
21-
}
22-
23-
/// <summary>
24-
/// Represents a project node in the dependency graph.
25-
/// </summary>
26-
internal record ProjectNode(string Id, HashSet<DependencyNode> Children)
27-
: DependencyNode(Id, Children)
28-
{
29-
public virtual bool Equals(ProjectNode? other)
21+
public DependencyNode(string id, string version)
3022
{
31-
if (other == null)
32-
return false;
33-
34-
return string.Equals(Id, other.Id, StringComparison.OrdinalIgnoreCase)
35-
&& Children.SetEquals(other.Children);
23+
Id = id ?? throw new ArgumentNullException(nameof(id));
24+
Version = version ?? throw new ArgumentNullException(nameof(version));
25+
Children = new HashSet<DependencyNode>(new DependencyNodeComparer());
3626
}
3727

3828
public override int GetHashCode()
3929
{
40-
var hash = new HashCode();
41-
hash.Add(Id, StringComparer.OrdinalIgnoreCase);
42-
foreach (var child in Children.OrderBy(c => c.Id, StringComparer.OrdinalIgnoreCase))
43-
{
44-
hash.Add(child);
45-
}
46-
return hash.ToHashCode();
30+
var hashCodeCombiner = new HashCodeCombiner();
31+
hashCodeCombiner.AddObject(Id);
32+
hashCodeCombiner.AddObject(Version);
33+
hashCodeCombiner.AddUnorderedSequence(Children);
34+
return hashCodeCombiner.CombinedHash;
4735
}
4836
}
4937

50-
/// <summary>
51-
/// Represents a package node in the dependency graph.
52-
/// </summary>
53-
internal record PackageNode(string Id, NuGetVersion ResolvedVersion, VersionRange RequestedVersion, HashSet<DependencyNode> Children)
54-
: DependencyNode(Id, Children)
38+
internal class DependencyNodeComparer : IEqualityComparer<DependencyNode>
5539
{
56-
public virtual bool Equals(PackageNode? other)
40+
public bool Equals(DependencyNode? x, DependencyNode? y)
5741
{
58-
if (other == null)
42+
if (x == null || y == null)
5943
return false;
6044

61-
return string.Equals(Id, other.Id, StringComparison.OrdinalIgnoreCase)
62-
&& ResolvedVersion.Equals(other.ResolvedVersion)
63-
&& RequestedVersion.Equals(other.RequestedVersion)
64-
&& Children.SetEquals(other.Children);
45+
return string.Equals(x.Id, y.Id, StringComparison.CurrentCultureIgnoreCase);
6546
}
6647

67-
public override int GetHashCode()
48+
public int GetHashCode(DependencyNode obj)
6849
{
69-
var hash = new HashCode();
70-
hash.Add(Id, StringComparer.OrdinalIgnoreCase);
71-
hash.Add(ResolvedVersion);
72-
hash.Add(RequestedVersion);
73-
foreach (var child in Children.OrderBy(c => c.Id, StringComparer.OrdinalIgnoreCase))
74-
{
75-
hash.Add(child);
76-
}
77-
return hash.ToHashCode();
50+
return obj.Id.GetHashCode();
7851
}
7952
}
8053
}

src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.Designer.cs

Lines changed: 2 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.resx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,4 @@ Do not translate "PackageVersion"</comment>
11681168
<comment>{0} = package ID
11691169
{1} = comma-separated list of all configured sources </comment>
11701170
</data>
1171-
<data name="WhyCommand_Error_InconsistentAssetsFile" xml:space="preserve">
1172-
<value>Internal error: Assets file is inconsistent</value>
1173-
</data>
11741171
</root>

src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.cs.xlf

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
33
<file datatype="xml" source-language="en" target-language="cs" original="../Strings.resx">
44
<body>
@@ -1481,11 +1481,6 @@ Hledání porovnává řetězce bez rozlišování malých a velkých písmen po
14811481
<target state="translated">Nepovedlo se spustit příkaz dotnet nuget why. {0}</target>
14821482
<note>{0} - Exception mssage</note>
14831483
</trans-unit>
1484-
<trans-unit id="WhyCommand_Error_InconsistentAssetsFile">
1485-
<source>Internal error: Assets file is inconsistent</source>
1486-
<target state="translated">Vnitřní chyba: Soubor prostředků není konzistentní</target>
1487-
<note />
1488-
</trans-unit>
14891484
<trans-unit id="WhyCommand_Error_InvalidAssetsFile_WithProject">
14901485
<source>The file '{0}' does not appear to be a NuGet assets file. Please run restore for project '{1}' before running this command.</source>
14911486
<target state="translated">Zdá se, že soubor {0} není souborem prostředků NuGet. Před spuštěním tohoto příkazu prosím spusťte obnovení projektu {1}.</target>

src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.de.xlf

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
33
<file datatype="xml" source-language="en" target-language="de" original="../Strings.resx">
44
<body>
@@ -1481,11 +1481,6 @@ Bei der Suche handelt es sich um einen ungültigen Zeichenfolgenvergleich mit de
14811481
<target state="translated">"dotnet nuget why" kann nicht ausgeführt werden. {0}</target>
14821482
<note>{0} - Exception mssage</note>
14831483
</trans-unit>
1484-
<trans-unit id="WhyCommand_Error_InconsistentAssetsFile">
1485-
<source>Internal error: Assets file is inconsistent</source>
1486-
<target state="translated">Interner Fehler: Die Assets-Datei ist inkonsistent.</target>
1487-
<note />
1488-
</trans-unit>
14891484
<trans-unit id="WhyCommand_Error_InvalidAssetsFile_WithProject">
14901485
<source>The file '{0}' does not appear to be a NuGet assets file. Please run restore for project '{1}' before running this command.</source>
14911486
<target state="translated">Die Datei „{0}“ scheint keine NuGet-Ressourcendatei zu sein. Führen Sie die Wiederherstellung für das Projekt „{1}“ aus, bevor Sie diesen Befehl ausführen.</target>

src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.es.xlf

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
33
<file datatype="xml" source-language="en" target-language="es" original="../Strings.resx">
44
<body>
@@ -1481,11 +1481,6 @@ La búsqueda es una comparación de cadenas que no diferencia mayúsculas de min
14811481
<target state="translated">No se puede ejecutar "dotnet nuget why". {0}</target>
14821482
<note>{0} - Exception mssage</note>
14831483
</trans-unit>
1484-
<trans-unit id="WhyCommand_Error_InconsistentAssetsFile">
1485-
<source>Internal error: Assets file is inconsistent</source>
1486-
<target state="translated">Error interno: el archivo de recursos es incoherente</target>
1487-
<note />
1488-
</trans-unit>
14891484
<trans-unit id="WhyCommand_Error_InvalidAssetsFile_WithProject">
14901485
<source>The file '{0}' does not appear to be a NuGet assets file. Please run restore for project '{1}' before running this command.</source>
14911486
<target state="translated">El archivo "{0}" no parece ser un archivo de recursos de NuGet. Ejecute la restauración del proyecto "{1}" antes de ejecutar este comando.</target>

src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.fr.xlf

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
33
<file datatype="xml" source-language="en" target-language="fr" original="../Strings.resx">
44
<body>
@@ -1481,11 +1481,6 @@ La recherche est une comparaison de chaînes qui ne respecte pas la casse à l
14811481
<target state="translated">Impossible d’exécuter « dotnet nuget why ». {0}</target>
14821482
<note>{0} - Exception mssage</note>
14831483
</trans-unit>
1484-
<trans-unit id="WhyCommand_Error_InconsistentAssetsFile">
1485-
<source>Internal error: Assets file is inconsistent</source>
1486-
<target state="translated">Erreur interne : le fichier des ressources est incohérent</target>
1487-
<note />
1488-
</trans-unit>
14891484
<trans-unit id="WhyCommand_Error_InvalidAssetsFile_WithProject">
14901485
<source>The file '{0}' does not appear to be a NuGet assets file. Please run restore for project '{1}' before running this command.</source>
14911486
<target state="translated">Le fichier «{0}» ne semble pas être un fichier de ressources NuGet. Veuillez exécuter la restauration pour l projet « {1} » avant d’exécuter cette commande.</target>

src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.it.xlf

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
33
<file datatype="xml" source-language="en" target-language="it" original="../Strings.resx">
44
<body>
@@ -1481,11 +1481,6 @@ La ricerca viene eseguita in un confronto di stringhe senza distinzione tra maiu
14811481
<target state="translated">Non è possibile eseguire 'dotnet nuget why'. {0}</target>
14821482
<note>{0} - Exception mssage</note>
14831483
</trans-unit>
1484-
<trans-unit id="WhyCommand_Error_InconsistentAssetsFile">
1485-
<source>Internal error: Assets file is inconsistent</source>
1486-
<target state="translated">Errore interno: il file di asset non è coerente</target>
1487-
<note />
1488-
</trans-unit>
14891484
<trans-unit id="WhyCommand_Error_InvalidAssetsFile_WithProject">
14901485
<source>The file '{0}' does not appear to be a NuGet assets file. Please run restore for project '{1}' before running this command.</source>
14911486
<target state="translated">Il file '{0}' non sembra essere un file di asset NuGet. Eseguire il ripristino per il progetto '{1}' prima di eseguire questo comando.</target>

0 commit comments

Comments
 (0)