Skip to content

Commit

Permalink
Deprecate Blob.Content
Browse files Browse the repository at this point in the history
  • Loading branch information
Aimeast authored and nulltoken committed Oct 27, 2013
1 parent 2e201d5 commit 71090d3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
16 changes: 1 addition & 15 deletions LibGit2Sharp.Tests/BlobFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void CanGetBlobAsTextWithVariousEncodings(string encodingName, int expect
var commit = repo.Commit("bom", Constants.Signature, Constants.Signature);

var blob = (Blob)commit.Tree[bomFile].Target;
Assert.Equal(expectedContentBytes, blob.Content.Length);
Assert.Equal(expectedContentBytes, blob.GetContentStream().Length);

var textDetected = blob.GetContentText();
Assert.Equal(content, textDetected);
Expand Down Expand Up @@ -101,20 +101,6 @@ public void CanLookUpBlob()
}
}

[Fact]
public void CanReadBlobContent()
{
using (var repo = new Repository(BareTestRepoPath))
{
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
byte[] bytes = blob.Content;
Assert.Equal(10, bytes.Length);

string content = Encoding.UTF8.GetString(bytes);
Assert.Equal("hey there\n", content);
}
}

[Fact]
public void CanReadBlobStream()
{
Expand Down
5 changes: 4 additions & 1 deletion LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,10 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny()
// Recreate the file in the workdir without the executable bit
string fullpath = Path.Combine(repo.Info.WorkingDirectory, file);
File.Delete(fullpath);
File.WriteAllBytes(fullpath, ((Blob)(entry.Target)).Content);
using (var stream = ((Blob)(entry.Target)).GetContentStream())
{
Touch(repo.Info.WorkingDirectory, file, stream);
}

// Unset the local core.filemode, if any.
repo.Config.Unset("core.filemode");
Expand Down
5 changes: 4 additions & 1 deletion LibGit2Sharp.Tests/DiffWorkdirToIndexFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny()
// Recreate the file in the workdir without the executable bit
string fullpath = Path.Combine(repo.Info.WorkingDirectory, file);
File.Delete(fullpath);
File.WriteAllBytes(fullpath, ((Blob)(entry.Target)).Content);
using (var stream = ((Blob)(entry.Target)).GetContentStream())
{
Touch(repo.Info.WorkingDirectory, file, stream);
}

// Unset the local core.filemode, if any.
repo.Config.Unset("core.filemode", ConfigurationLevel.Local);
Expand Down
1 change: 1 addition & 0 deletions LibGit2Sharp/Blob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal Blob(Repository repo, ObjectId id)
/// <summary>
/// Gets the blob content in a <see cref="byte"/> array.
/// </summary>
[Obsolete("This property will be removed in the next release. Please use one of the GetContentStream() overloads instead.")]
public virtual byte[] Content
{
get
Expand Down

0 comments on commit 71090d3

Please sign in to comment.