Skip to content

XML Warnings #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions LibGit2Sharp/Blob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ internal Blob(Repository repo, ObjectId id)
/// </summary>
public int Size { get; set; }

/// <summary>
/// Gets the blob content in a <see cref="byte" /> array.
/// </summary>
public byte[] Content
{
get
Expand All @@ -38,6 +41,9 @@ public byte[] Content
}
}

/// <summary>
/// Gets the blob content in a <see cref="Stream" />.
/// </summary>
public Stream ContentStream
{
get
Expand All @@ -53,11 +59,19 @@ public Stream ContentStream
}
}

/// <summary>
/// Gets the blob content decoded as UTF-8.
/// </summary>
/// <returns></returns>
public string ContentAsUtf8()
{
return Encoding.UTF8.GetString(Content);
}

/// <summary>
/// Gets the blob content decoded as Unicode.
/// </summary>
/// <returns></returns>
public string ContentAsUnicode()
{
return Encoding.Unicode.GetString(Content);
Expand Down
40 changes: 40 additions & 0 deletions LibGit2Sharp/Changes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Text;

namespace LibGit2Sharp
{
/// <summary>
/// Base class for changes.
/// </summary>
public abstract class Changes
{
private readonly StringBuilder patchBuilder = new StringBuilder();

internal void AppendToPatch(string patch)
{
patchBuilder.Append(patch);
}

/// <summary>
/// The number of lines added.
/// </summary>
public int LinesAdded { get; internal set; }

/// <summary>
/// The number of lines deleted.
/// </summary>
public int LinesDeleted { get; internal set; }

/// <summary>
/// The patch corresponding to these changes.
/// </summary>
public string Patch
{
get { return patchBuilder.ToString(); }
}

/// <summary>
/// Determines if at least one side of the comparison holds binary content.
/// </summary>
public bool IsBinaryComparison { get; protected set; }
}
}
51 changes: 6 additions & 45 deletions LibGit2Sharp/ContentChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@ namespace LibGit2Sharp
/// <summary>
/// Holds the changes between two <see cref = "Blob" />s.
/// </summary>
public class ContentChanges
public class ContentChanges : Changes
{
private readonly StringBuilder patchBuilder = new StringBuilder();

protected ContentChanges()
{
}

internal ContentChanges(Repository repo, Blob oldBlob, Blob newBlob, GitDiffOptions options)
{
using (var osw1 = new ObjectSafeWrapper(oldBlob.Id, repo))
Expand All @@ -26,29 +20,23 @@ internal ContentChanges(Repository repo, Blob oldBlob, Blob newBlob, GitDiffOpti

private int FileCallback(IntPtr data, GitDiffDelta delta, float progress)
{
IsBinaryComparison = IsBinaryDelta(delta);
IsBinaryComparison = delta.IsBinary();

if (!IsBinaryComparison)
{
return 0;
}

PatchBuilder.Append("Binary content differ\n");
AppendToPatch("Binary content differ\n");

return 0;
}

internal static bool IsBinaryDelta(GitDiffDelta delta)
{
//TODO Fix the interop issue on amd64 and use GitDiffDelta.Binary
return delta.OldFile.Flags.Has(GitDiffFileFlags.GIT_DIFF_FILE_BINARY) || delta.NewFile.Flags.Has(GitDiffFileFlags.GIT_DIFF_FILE_BINARY);
}

private int HunkCallback(IntPtr data, GitDiffDelta delta, GitDiffRange range, IntPtr header, uint headerlen)
{
string decodedContent = Utf8Marshaler.FromNative(header, headerlen);

PatchBuilder.AppendFormat("{0}", decodedContent);
AppendToPatch(decodedContent);
return 0;
}

Expand Down Expand Up @@ -79,36 +67,9 @@ private int LineCallback(IntPtr data, GitDiffDelta delta, GitDiffRange range, Gi
break;
}

PatchBuilder.AppendFormat("{0}{1}", prefix, decodedContent);
AppendToPatch(prefix);
AppendToPatch(decodedContent);
return 0;
}

/// <summary>
/// Determines if at least one of the compared <see cref="Blob"/>s holds some binary content.
/// </summary>
public bool IsBinaryComparison { get; protected set; }

/// <summary>
/// The number of lines added.
/// </summary>
public int LinesAdded { get; internal set; }

/// <summary>
/// The number of lines deleted.
/// </summary>
public int LinesDeleted { get; internal set; }

/// <summary>
/// The patch corresponding to these changes.
/// </summary>
public string Patch
{
get { return patchBuilder.ToString(); }
}

internal StringBuilder PatchBuilder
{
get { return patchBuilder; }
}
}
}
11 changes: 11 additions & 0 deletions LibGit2Sharp/Core/GitDiffExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace LibGit2Sharp.Core
{
internal static class GitDiffExtensions
{
public static bool IsBinary(this GitDiffDelta delta)
{
//TODO Fix the interop issue on amd64 and use GitDiffDelta.Binary
return delta.OldFile.Flags.Has(GitDiffFileFlags.GIT_DIFF_FILE_BINARY) || delta.NewFile.Flags.Has(GitDiffFileFlags.GIT_DIFF_FILE_BINARY);
}
}
}
6 changes: 6 additions & 0 deletions LibGit2Sharp/DiffTarget.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
namespace LibGit2Sharp
{
/// <summary>
/// The target for a diff comparison.
/// </summary>
public enum DiffTarget
{
/// <summary>
/// The repository index.
/// </summary>
Index,
}
}
3 changes: 3 additions & 0 deletions LibGit2Sharp/ICommitCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace LibGit2Sharp
{
/// <summary>
/// A collection of commits in a <see cref = "Repository" />.
/// </summary>
public interface ICommitCollection : IEnumerable<Commit>
{
/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions LibGit2Sharp/IQueryableCommitCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace LibGit2Sharp
{
/// <summary>
/// A collection of commits in a <see cref = "Repository" /> that can be filtered with queries.
/// </summary>
public interface IQueryableCommitCollection : ICommitCollection //TODO: Find a name that's more explicit than IQueryableCommitCollection
{
/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions LibGit2Sharp/LibGit2Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\Debug\LibGit2Sharp.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down Expand Up @@ -58,6 +59,7 @@
<Compile Include="Blob.cs" />
<Compile Include="Branch.cs" />
<Compile Include="BranchCollection.cs" />
<Compile Include="Changes.cs" />
<Compile Include="Commit.cs" />
<Compile Include="CommitCollection.cs" />
<Compile Include="Configuration.cs" />
Expand All @@ -73,6 +75,7 @@
<Compile Include="ChangeKind.cs" />
<Compile Include="Core\GitBranchType.cs" />
<Compile Include="Core\GitDiff.cs" />
<Compile Include="Core\GitDiffExtensions.cs" />
<Compile Include="Core\GitError.cs" />
<Compile Include="Core\GitErrorType.cs" />
<Compile Include="Core\GitNoteData.cs" />
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/ResetOptions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace LibGit2Sharp
{
/// <summary>
/// Specifies the kind of operation that <see cref="Repository.Reset"/> should perform.
/// Specifies the kind of operation that <see cref="Repository.Reset(LibGit2Sharp.ResetOptions, string)"/> should perform.
/// </summary>
public enum ResetOptions
{
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/TreeChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private int PrintCallBack(IntPtr data, GitDiffDelta delta, GitDiffRange range, G
AddFileChange(delta);
}

changes[currentFilePath].PatchBuilder.Append(formattedoutput);
changes[currentFilePath].AppendToPatch(formattedoutput);
fullPatchBuilder.Append(formattedoutput);

return 0;
Expand Down Expand Up @@ -92,7 +92,7 @@ private void AddFileChange(GitDiffDelta delta)
var newOid = new ObjectId(delta.NewFile.Oid);
var oldOid = new ObjectId(delta.OldFile.Oid);

var diffFile = new TreeEntryChanges(newFilePath, newMode, newOid, delta.Status, oldFilePath, oldMode, oldOid, ContentChanges.IsBinaryDelta(delta));
var diffFile = new TreeEntryChanges(newFilePath, newMode, newOid, delta.Status, oldFilePath, oldMode, oldOid, delta.IsBinary());

fileDispatcher[delta.Status](this, diffFile);
changes.Add(diffFile.Path, diffFile);
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/TreeEntryChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace LibGit2Sharp
/// <summary>
/// Holds the changes between two versions of a tree entry.
/// </summary>
public class TreeEntryChanges : ContentChanges
public class TreeEntryChanges : Changes
{
internal TreeEntryChanges(string path, Mode mode, ObjectId oid, ChangeKind status, string oldPath, Mode oldMode, ObjectId oldOid, bool isBinaryComparison)
{
Expand Down