8000 Stop sorting collections · gitextensions/libgit2sharp@678b268 · GitHub
[go: up one dir, main page]

Skip to content

Commit 678b268

Browse files
dahlbyknulltoken
authored andcommitted
Stop sorting collections
1 parent b265bfc commit 678b268

13 files changed

+53
-61
lines changed

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Linq;
45
using LibGit2Sharp.Tests.TestHelpers;
@@ -183,7 +184,7 @@ public void CanListAllBranches()
183184
{
184185
using (var repo = new Repository(BareTestRepoPath))
185186
{
186-
Assert.Equal(expectedBranches, repo 341A .Branches.Select(b => b.Name).ToArray());
187+
Assert.Equal(expectedBranches, SortedBranches(repo.Branches, b => b.Name));
187188

188189
Assert.Equal(5, repo.Branches.Count());
189190
}
@@ -204,9 +205,8 @@ public void CanListBranchesWithRemoteAndLocalBranchWithSameShortName()
204205
"diff-test-cases", "i-do-numbers", "logo", "master", "origin/master", "track-local",
205206
};
206207

207-
Assert.Equal(expectedWdBranches, repo.Branches
208-
.Where(b => !b.IsRemote)
209-
.Select(b => b.Name).ToArray());
208+
Assert.Equal(expectedWdBranches,
209+
SortedBranches(repo.Branches.Where(b => !b.IsRemote), b => b.Name));
210210
}
211211
}
212212

@@ -222,7 +222,7 @@ public void CanListAllBranchesWhenGivenWorkingDir()
222222
"origin/test"
223223
};
224224

225-
Assert.Equal(expectedWdBranches, repo.Branches.Select(b => b.Name).ToArray());
225+
Assert.Equal(expectedWdBranches, SortedBranches(repo.Branches, b => b.Name));
226226
}
227227
}
228228

@@ -244,7 +244,8 @@ public void CanListAllBranchesIncludingRemoteRefs()
244244
new { Name = "origin/packed-test", Sha = "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", IsRemote = true },
245245
new { Name = "origin/test", Sha = "e90810b8df3e80c413d903f631643c716887138d", IsRemote = true },
246246
};
247-
Assert.Equal(expectedBranchesIncludingRemoteRefs, repo.Branches.Select(b => new { b.Name, b.Tip.Sha, b.IsRemote }).ToArray());
247+
Assert.Equal(expectedBranchesIncludingRemoteRefs,
248+
SortedBranches(repo.Branches, b => new { b.Name, b.Tip.Sha, b.IsRemote }));
248249
}
249250
}
250251

@@ -811,5 +812,10 @@ public void RemoteBranchesDoNotTrackAnything()
811812
}
812813
}
813814
}
815+
816+
private static T[] SortedBranches<T>(IEnumerable<Branch> branches, Func<Branch, T> selector)
817+
{
818+
return branches.OrderBy(b => b.CanonicalName, StringComparer.Ordinal).Select(selector).ToArray();
819+
}
814820
}
815821
}

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,10 @@ private static void CanEnumerateCommitsFromATag(Func<Tag, object> transformer)
347347
public void CanEnumerateAllCommits()
348348
{
349349
AssertEnumerationOfCommits(
350-
repo => new Filter { Since = repo.Refs },
350+
repo => new Filter
351+
{
352+
Since = repo.Refs.OrderBy(r => r.CanonicalName, StringComparer.Ordinal),
353+
},
351354
new[]
352355
{
353356
"44d5d18", "bb65291", "532740a", "503a16f", "3dfd6fd",

LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public void CanCompareACommitTreeAgainstATreeWithNoCommonAncestor()
125125

126126
Assert.Equal("readme.txt", changes.Deleted.Single().Path);
127127
Assert.Equal(new[] { "1.txt", subBranchFilePath, "README", "branch_file.txt", "deleted_staged_file.txt", "deleted_unstaged_file.txt", "modified_staged_file.txt", "modified_unstaged_file.txt", "new.txt" },
128-
changes.Added.Select(x => x.Path));
128+
changes.Added.Select(x => x.Path).OrderBy(p => p, StringComparer.Ordinal).ToArray());
129129

130130
Assert.Equal(9, changes.LinesAdded);
131131
Assert.Equal(2, changes.LinesDeleted);

LibGit2Sharp.Tests/IndexFixture.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public void CanEnumerateIndex()
4040
{
4141
using (var repo = new Repository(StandardTestRepoPath))
4242
{
43-
Assert.Equal(expectedEntries, repo.Index.Select(e => e.Path).ToArray());
43+
Assert.Equal(expectedEntries,
44+
repo.Index.Select(e => e.Path).OrderBy(p => p, StringComparer.Ordinal).ToArray());
4445
}
4546
}
4647

LibGit2Sharp.Tests/NoteFixture.cs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using LibGit2Sharp.Core;
45
using LibGit2Sharp.Core.Compat;
@@ -61,19 +62,19 @@ public void CanRetrieveNotesFromAGitObject()
6162
var notes = repo.Notes[new ObjectId("4a202b346bb0fb0db7eff3cffeb3c70babbd2045")];
6263

6364
Assert.NotNull(notes);
64-
Assert.Equal(3, notes.Count());
65-
Assert.Equal(expectedMessages, notes.Select(n => n.Message));
65+
Assert.Equal(expectedMessages, SortedNotes(notes, n => n.Message));
6666
}
6767
}
6868

6969
[Fact]
7070
public void CanGetListOfNotesNamespaces()
7171
{
72-
var expectedNamespaces = new[] { "commits", "answer", "answer2" };
72+
var expectedNamespaces = new[] { "answer", "answer2", "commits", };
7373

7474
using (var repo = new Repository(BareTestRepoPath))
7575
{
76-
Assert.Equal(expectedNamespaces, repo.Notes.Namespaces);
76+
Assert.Equal(expectedNamespaces,
77+
repo.Notes.Namespaces.OrderBy(n => n, StringComparer.Ordinal).ToArray());
7778
Assert.Equal(repo.Notes.DefaultNamespace, repo.Notes.Namespaces.First());
7879
}
7980
}
@@ -105,12 +106,12 @@ public void CanAccessNotesFromACommit()
105106
{
106107
var commit = repo.Lookup<Commit>("4a202b346bb0fb0db7eff3cffeb3c70babbd2045");
107108

108-
Assert.Equal(expectedNamespaces, commit.Notes.Select(n => n.Message));
109+
Assert.Equal(expectedNamespaces, SortedNotes(commit.Notes, n => n.Message));
109110

110111
// Make sure that Commit.Notes is not refreshed automatically
111112
repo.Notes.Add(commit.Id, "I'm batman!\n", signatureNullToken, signatureYorah, "batmobile");
112113

113-
Assert.Equal(expectedNamespaces, commit.Notes.Select(n => n.Message));
114+
Assert.Equal(expectedNamespaces, SortedNotes(commit.Notes, m => m.Message));
114115
}
115116
}
116117

@@ -228,16 +229,26 @@ public void RemovingANonExistingNoteDoesntThrow()
228229
[Fact]
229230
public void CanRetrieveTheListOfNotesForAGivenNamespace()
230231
{
231-
var expectedNotes = new[] { new Tuple<string, string>("1a550e416326cdb4a8e127a04dd69d7a01b11cf4", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045"),
232-
new Tuple<string, string>("272a41cf2b22e57f2bc5bf6ef37b63568cd837e4", "8496071c1b46c854b31185ea97743be6a8774479") };
232+
var expectedNotes = new[]
233+
{
234+
new { Blob = "272a41cf2b22e57f2bc5bf6ef37b63568cd837e4", Target = "8496071c1b46c854b31185ea97743be6a8774479" },
235+
new { Blob = "1a550e416326cdb4a8e127a04dd69d7a01b11cf4", Target = "4a202b346bb0fb0db7eff3cffeb3c70babbd2045" },
236+
};
233237

234238
using (var repo = new Repository(BareTestRepoPath))
235239
{
236-
Assert.Equal(expectedNotes, repo.Notes["commits"].Select(n => new Tuple<string, string>(n.BlobId.Sha, n.TargetObjectId.Sha)).ToArray());
240+
Assert.Equal(expectedNotes,
241+
SortedNotes(repo.Notes["commits"], n => new { Blob = n.BlobId.Sha, Target = n.TargetObjectId.Sha }));
237242

238243
Assert.Equal("commits", repo.Notes.DefaultNamespace);
239-
Assert.Equal(expectedNotes, repo.Notes.Select(n => new Tuple<string, string>(n.BlobId.Sha, n.TargetObjectId.Sha)).ToArray());
244+
Assert.Equal(expectedNotes,
245+
SortedNotes(repo.Notes, n => new { Blob = n.BlobId.Sha, Target = n.TargetObjectId.Sha }));
240246
}
241247
}
248+
249+
private static T[] SortedNotes<T>(IEnumerable<Note> notes, Func<Note, T> selector)
250+
{
251+
return notes.OrderBy(n => n.Message, StringComparer.Ordinal).Select(selector).ToArray();
252+
}
242253
}
243254
}

LibGit2Sharp.Tests/ReferenceFixture.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public void CanListAllReferencesEvenCorruptedOnes()
283283
{
284284
CreateCorruptedDeadBeefHead(repo.Info.Path);
285285

286-
Assert.Equal(expectedRefs, repo.Refs.Select(r => r.CanonicalName).ToArray());
286+
Assert.Equal(expectedRefs, SortedRefs(repo, r => r.CanonicalName));
287287

288288
Assert.Equal(13, repo.Refs.Count());
289289
}
@@ -685,5 +685,10 @@ public void CanTellIfAReferenceIsValid(string refname, bool expectedResult)
685685
Assert.Equal(expectedResult, repo.Refs.IsValidName(refname));
686686
}
687687
}
688+
689+
private static T[] SortedRefs<T>(IRepository repo, Func<Reference, T> selector)
690+
{
691+
return repo.Refs.OrderBy(r => r.CanonicalName, StringComparer.Ordinal).Select(selector).ToArray();
692+
}
688693
}
689694
}

LibGit2Sharp.Tests/ResetHeadFixture.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ public void HardResetUpdatesTheContentOfTheWorkingDirectory()
188188
using (var repo = new Repository(clone.DirectoryPath))
189189
{
190190
var names = new DirectoryInfo(repo.Info.WorkingDirectory).GetFileSystemInfos().Select(fsi => fsi.Name).ToList();
191-
names.Sort(StringComparer.Ordinal);
192191

193192
File.Delete(Path.Combine(repo.Info.WorkingDirectory, "README"));
194193
File.WriteAllText(Path.Combine(repo.Info.WorkingDirectory, "WillNotBeRemoved.txt"), "content\n");

LibGit2Sharp.Tests/TagFixture.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ public void CanListTags()
589589
{
590590
using (var repo = new Repository(BareTestRepoPath))
591591
{
592-
Assert.Equal(expectedTags, repo.Tags.Select(t => t.Name).ToArray());
592+
Assert.Equal(expectedTags, SortedTags(repo.Tags, t => t.Name));
593593

594594
Assert.Equal(4, repo.Tags.Count());
595595
}
@@ -608,21 +608,6 @@ public void CanListAllTagsInAEmptyRepository()
608608
}
609609
}
610610

611-
[Fact]
612-
// Ported from cgit (https://github.com/git/git/blob/1c08bf50cfcf924094eca56c2486a90e2bf1e6e2/t/t7004-tag.sh#L165)
613-
public void ListAllTagsShouldOutputThemInAnOrderedWay()
614-
{
615-
using (var repo = new Repository(BareTestRepoPath))
616-
{
617-
List<string> tagNames = repo.Tags.Select(t => t.Name).ToList();
618-
619-
List<string> sortedTags = expectedTags.ToList();
620-
sortedTags.Sort();
621-
622-
Assert.Equal(sortedTags, tagNames);
623-
}
624-
}
625-
626611
[Fact]
627612
public void CanLookupALightweightTag()
628613
{
@@ -693,5 +678,10 @@ public void LookupNullTagNameThrows()
693678
Assert.Throws<ArgumentNullException>(() => { Tag t = repo.Tags[null]; });
694679
}
695680
}
681+
682+
private static T[] SortedTags<T>(IEnumerable<Tag> tags, Func<Tag, T> selector)
683+
{
684+
return tags.OrderBy(t => t.CanonicalName, StringComparer.Ordinal).Select(selector).ToArray();
685+
}
696686
}
697687
}

LibGit2Sharp/BranchCollection.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ public virtual IEnumerator<Branch> GetEnumerator()
9393
{
9494
return Proxy.git_branch_foreach(repo.Handle, GitBranchType.GIT_BRANCH_LOCAL | GitBranchType.GIT_BRANCH_REMOTE, branchToCanoncialName)
9595
.Select(n => this[n])
96-
.OrderBy(b => b.CanonicalName, StringComparer.Ordinal)
9796
.GetEnumerator();
9897
}
9998

LibGit2Sharp/Core/Proxy.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,6 @@ public static IList<string> BuildListOf(UnSafeNativeMethods.git_strarray strArra
21302130
list.Add(name);
21312131
}
21322132

2133-
list.Sort(StringComparer.Ordinal);
21342133
return list;
21352134
}
21362135
finally

0 commit comments

Comments
 (0)
0