Skip to content

Commit

Permalink
Rename Blob.ContentAsText() as Blob.GetContentText()
Browse files Browse the repository at this point in the history
  • Loading branch information
Aimeast authored and nulltoken committed Oct 27, 2013
1 parent da32029 commit 2e201d5
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/AttributesFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private static void AssertNormalization(Repository repo, string filename, bool s
var blob = repo.Lookup<Blob>(entry.Id);
Assert.NotNull(blob);

Assert.Equal(!shouldHaveBeenNormalized, blob.ContentAsText().Contains("\r"));
Assert.Equal(!shouldHaveBeenNormalized, blob.GetContentText().Contains("\r"));
}

private static void CreateAttributesFile(Repository repo)
Expand Down
10 changes: 5 additions & 5 deletions LibGit2Sharp.Tests/BlobFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void CanGetBlobAsText()
{
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");

var text = blob.ContentAsText();
var text = blob.GetContentText();

Assert.Equal("hey there\n", text);
}
Expand All @@ -30,7 +30,7 @@ public void CanGetBlobAsFilteredText()
{
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");

var text = blob.ContentAsText(new FilteringOptions("foo.txt"));
var text = blob.GetContentText(new FilteringOptions("foo.txt"));

ConfigurationEntry<bool> autocrlf = repo.Config.Get<bool>("core.autocrlf");

Expand Down Expand Up @@ -70,13 +70,13 @@ public void CanGetBlobAsTextWithVariousEncodings(string encodingName, int expect
var blob = (Blob)commit.Tree[bomFile].Target;
Assert.Equal(expectedContentBytes, blob.Content.Length);

var textDetected = blob.ContentAsText();
var textDetected = blob.GetContentText();
Assert.Equal(content, textDetected);

var text = blob.ContentAsText(encoding);
var text = blob.GetContentText(encoding);
Assert.Equal(content, text);

var utf7Chars = blob.ContentAsText(Encoding.UTF7).Select(c => ((int)c).ToString("X2")).ToArray();
var utf7Chars = blob.GetContentText(Encoding.UTF7).Select(c => ((int)c).ToString("X2")).ToArray();
Assert.Equal(expectedUtf7Chars, string.Join(" ", utf7Chars));
}
}
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp.Tests/CommitFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ public void CanDirectlyAccessABlobOfTheCommit()
var blob = commit["1/branch_file.txt"].Target as Blob;
Assert.NotNull(blob);

Assert.Equal("hi\n", blob.ContentAsText());
Assert.Equal("hi\n", blob.GetContentText());
}
}

Expand Down Expand Up @@ -694,7 +694,7 @@ public void CanCommitALittleBit()
private static void AssertBlobContent(TreeEntry entry, string expectedContent)
{
Assert.Equal(TreeEntryTargetType.Blob, entry.TargetType);
Assert.Equal(expectedContent, ((Blob)(entry.Target)).ContentAsText());
Assert.Equal(expectedContent, ((Blob)(entry.Target)).GetContentText());
}

private static void AddCommitToRepo(string path)
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/ObjectDatabaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void CanCreateABlobIntoTheDatabaseOfABareRepository()

Assert.NotNull(blob);
Assert.Equal("dc53d4c6b8684c21b0b57db29da4a2afea011565", blob.Sha);
Assert.Equal("I'm a new file\n", blob.ContentAsText());
Assert.Equal("I'm a new file\n", blob.GetContentText());

var fetchedBlob = repo.Lookup<Blob>(blob.Id);
Assert.Equal(blob, fetchedBlob);
Expand Down
32 changes: 31 additions & 1 deletion LibGit2Sharp/BlobExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,37 @@ public static class BlobExtensions
/// <param name="blob">The blob for which the content will be returned.</param>
/// <param name="encoding">The encoding of the text. (default: detected or UTF8)</param>
/// <returns>Blob content as text.</returns>
[Obsolete("This method will be removed in the next release. Please use one of the GetContentText() overloads instead.")]
public static string ContentAsText(this Blob blob, Encoding encoding = null)
{
return GetContentText(blob, encoding);
}

/// <summary>
/// Gets the blob content as it would be checked out to the
/// working directory, decoded with the specified encoding,
/// or according to byte order marks, with UTF8 as fallback,
/// if <paramref name="encoding"/> is null.
/// </summary>
/// <param name="blob">The blob for which the content will be returned.</param>
/// <param name="filteringOptions">Parameter controlling content filtering behavior</param>
/// <param name="encoding">The encoding of the text. (default: detected or UTF8)</param>
/// <returns>Blob content as text.</returns>
[Obsolete("This method will be removed in the next release. Please use one of the GetContentText() overloads instead.")]
public static string ContentAsText(this Blob blob, FilteringOptions filteringOptions, Encoding encoding = null)
{
return GetContentText(blob, filteringOptions, encoding);
}

/// <summary>
/// Gets the blob content decoded with the specified encoding,
/// or according to byte order marks, with UTF8 as fallback,
/// if <paramref name="encoding"/> is null.
/// </summary>
/// <param name="blob">The blob for which the content will be returned.</param>
/// <param name="encoding">The encoding of the text. (default: detected or UTF8)</param>
/// <returns>Blob content as text.</returns>
public static string GetContentText(this Blob blob, Encoding encoding = null)
{
Ensure.ArgumentNotNull(blob, "blob");

Expand All @@ -38,7 +68,7 @@ public static string ContentAsText(this Blob blob, Encoding encoding = null)
/// <param name="filteringOptions">Parameter controlling content filtering behavior</param>
/// <param name="encoding">The encoding of the text. (default: detected or UTF8)</param>
/// <returns>Blob content as text.</returns>
public static string ContentAsText(this Blob blob, FilteringOptions filteringOptions, Encoding encoding = null)
public static string GetContentText(this Blob blob, FilteringOptions filteringOptions, Encoding encoding = null)
{
Ensure.ArgumentNotNull(blob, "blob");
Ensure.ArgumentNotNull(filteringOptions, "filteringOptions");
Expand Down

0 comments on commit 2e201d5

Please sign in to comment.