Skip to content
This repository was archived by the owner on Feb 3, 2023. It is now read-only.

Commit 92048f9

Browse files
committed
Obsolete Tree.Trees and Tree.Blobs properties
Relying on this properties would trigger multiple enumerations of the Tree entries. Exposing them is quite misleading for the consumer.
1 parent fa1f266 commit 92048f9

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,8 @@ public void CanGeneratePredictableObjectShas()
721721
Tree tree = commit.Tree;
722722
Assert.Equal("2b297e643c551e76cfa1f93810c50811382f9117", tree.Sha);
723723

724-
Blob blob = tree.Blobs.Single();
724+
GitObject blob = tree.Single().Target;
725+
Assert.IsAssignableFrom<Blob>(blob);
725726
Assert.Equal("9daeafb9864cf43055ae93beb0afd6c7d144bfa4", blob.Sha);
726727
}
727728
}

LibGit2Sharp.Tests/DiffBlobToBlobFixture.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public void ComparingABlobAgainstItselfReturnsNoDifference()
1313
{
1414
using (var repo = new Repository(StandardTestRepoPath))
1515
{
16-
Blob blob = repo.Head.Tip.Tree.Blobs.First();
16+
var blob = repo.Lookup<Blob>("7909961");
1717

1818
ContentChanges changes = repo.Diff.Compare(blob, blob);
1919

@@ -78,7 +78,7 @@ public void CanCompareATextualBlobAgainstABinaryBlob()
7878
{
7979
Blob binBlob = CreateBinaryBlob(repo);
8080

81-
Blob blob = repo.Head.Tip.Tree.Blobs.First();
81+
var blob = repo.Lookup<Blob>("7909961");
8282

8383
ContentChanges changes = repo.Diff.Compare(blob, binBlob);
8484

@@ -94,7 +94,7 @@ public void CanCompareABlobAgainstANullBlob()
9494
{
9595
using (var repo = new Repository(StandardTestRepoPath))
9696
{
97-
Blob blob = repo.Head.Tip.Tree.Blobs.First();
97+
var blob = repo.Lookup<Blob>("7909961");
9898

9999
ContentChanges changes = repo.Diff.Compare(null, blob);
100100

LibGit2Sharp.Tests/TagFixture.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,7 @@ public void CanAddATagPointingToABlob()
356356
string path = CloneBareTestRepo();
357357
using (var repo = new Repository(path))
358358
{
359-
Commit headCommit = repo.Head.Tip;
360-
Blob blob = headCommit.Tree.Blobs.First();
359+
var blob = repo.Lookup<Blob>("a823312");
361360

362361
Tag tag = repo.ApplyTag("blob-tag", blob.Sha);
363362
Assert.NotNull(tag);

LibGit2Sharp.Tests/TreeFixture.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System.Collections.Generic;
2+
using System.IO;
23
using System.Linq;
34
using LibGit2Sharp.Tests.TestHelpers;
45
using Xunit;
@@ -54,7 +55,13 @@ public void CanEnumerateBlobs()
5455
using (var repo = new Repository(BareTestRepoPath))
5556
{
5657
var tree = repo.Lookup<Tree>(sha);
57-
Assert.Equal(3, tree.Blobs.Count());
58+
59+
IEnumerable<Blob> blobs = tree
60+
.Where(e => e.TargetType == TreeEntryTargetType.Blob)
61+
.Select(e => e.Target)
62+
.Cast<Blob>();
63+
64+
Assert.Equal(3, blobs.Count());
5865
}
5966
}
6067

@@ -64,7 +71,13 @@ public void CanEnumerateSubTrees()
6471
using (var repo = new Repository(BareTestRepoPath))
6572
{
6673
var tree = repo.Lookup<Tree>(sha);
67-
Assert.Equal(1, tree.Trees.Count());
74+
75+
IEnumerable<Tree> subTrees = tree
76+
.Where(e => e.TargetType == TreeEntryTargetType.Tree)
77+
.Select(e => e.Target)
78+
.Cast<Tree>();
79+
80+
Assert.Equal(1, subTrees.Count());
6881
}
6982
}
7083

LibGit2Sharp/Tree.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections;
1+
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34
using System.Diagnostics;
45
using System.Globalization;
@@ -71,6 +72,7 @@ private TreeEntry RetrieveFromPath(FilePath relativePath)
7172
/// <summary>
7273
/// Gets the <see cref = "Tree" />s immediately under this <see cref = "Tree" />.
7374
/// </summary>
75+
[Obsolete("This property will be removed in the next release.")]
7476
public virtual IEnumerable<Tree> Trees
7577
{
7678
get
@@ -85,6 +87,7 @@ public virtual IEnumerable<Tree> Trees
8587
/// <summary>
8688
/// Gets the <see cref = "Blob" />s immediately under this <see cref = "Tree" />.
8789
/// </summary>
90+
[Obsolete("This property will be removed in the next release.")]
8891
public virtual IEnumerable<Blob> Blobs
8992
{
9093
get

0 commit comments

Comments
 (0)