Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2013-05-01 00:02:18 +0400
committernulltoken <emeric.fermas@gmail.com>2013-05-03 22:06:34 +0400
commitd6c74d2f7438597efaffd43320422f3d1ac509de (patch)
tree3723760be80a54aef91eecb0dfed93d5fc3a51ca
parent82a8d05417dc804c114376140be94ae69e3c5af4 (diff)
Deploy ObjectType to OdbBackend
Sadly, this is a breaking change as there's no way to allow a migration path through the use of an [Obsolete] attribute.
-rw-r--r--LibGit2Sharp.Tests/OdbBackendFixture.cs22
-rw-r--r--LibGit2Sharp/GitObjectType.cs21
-rw-r--r--LibGit2Sharp/OdbBackend.cs30
3 files changed, 49 insertions, 24 deletions
diff --git a/LibGit2Sharp.Tests/OdbBackendFixture.cs b/LibGit2Sharp.Tests/OdbBackendFixture.cs
index 7420c2f4..0f4a93d1 100644
--- a/LibGit2Sharp.Tests/OdbBackendFixture.cs
+++ b/LibGit2Sharp.Tests/OdbBackendFixture.cs
@@ -52,10 +52,10 @@ namespace LibGit2Sharp.Tests
}
}
- public override int Read(byte[] oid, out Stream data, out GitObjectType objectType)
+ public override int Read(byte[] oid, out Stream data, out ObjectType objectType)
{
data = null;
- objectType = GitObjectType.Bad;
+ objectType = default(ObjectType);
MockGitObject gitObject;
@@ -72,11 +72,11 @@ namespace LibGit2Sharp.Tests
return GIT_ENOTFOUND;
}
- public override int ReadPrefix(byte[] shortOid, out byte[] oid, out Stream data, out GitObjectType objectType)
+ public override int ReadPrefix(byte[] shortOid, out byte[] oid, out Stream data, out ObjectType objectType)
{
oid = null;
data = null;
- objectType = GitObjectType.Bad;
+ objectType = default(ObjectType);
MockGitObject gitObjectAlreadyFound = null;
@@ -120,7 +120,7 @@ namespace LibGit2Sharp.Tests
return GIT_ENOTFOUND;
}
- public override int Write(byte[] oid, Stream dataStream, long length, GitObjectType objectType, out byte[] finalOid)
+ public override int Write(byte[] oid, Stream dataStream, long length, ObjectType objectType, out byte[] finalOid)
{
using (var sha1 = new SHA1CryptoServiceProvider())
{
@@ -152,7 +152,7 @@ namespace LibGit2Sharp.Tests
return GIT_OK;
}
- public override int WriteStream(long length, GitObjectType objectType, out OdbBackendStream stream)
+ public override int WriteStream(long length, ObjectType objectType, out OdbBackendStream stream)
{
stream = new MockOdbBackendStream(this, objectType, length);
@@ -174,7 +174,7 @@ namespace LibGit2Sharp.Tests
#region Unimplemented
- public override int ReadHeader(byte[] oid, out int length, out GitObjectType objectType)
+ public override int ReadHeader(byte[] oid, out int length, out ObjectType objectType)
{
throw new NotImplementedException();
}
@@ -195,7 +195,7 @@ namespace LibGit2Sharp.Tests
private class MockOdbBackendStream : OdbBackendStream
{
- public MockOdbBackendStream(MockOdbBackend backend, GitObjectType objectType, long length)
+ public MockOdbBackendStream(MockOdbBackend backend, ObjectType objectType, long length)
: base(backend)
{
m_type = objectType;
@@ -287,7 +287,7 @@ namespace LibGit2Sharp.Tests
private byte[] m_buffer;
- private readonly GitObjectType m_type;
+ private readonly ObjectType m_type;
private readonly long m_length;
private readonly HashAlgorithm m_hash;
@@ -307,7 +307,7 @@ namespace LibGit2Sharp.Tests
private class MockGitObject
{
- public MockGitObject(byte[] objectId, GitObjectType objectType, byte[] data)
+ public MockGitObject(byte[] objectId, ObjectType objectType, byte[] data)
{
if (objectId.Length != 20)
{
@@ -320,7 +320,7 @@ namespace LibGit2Sharp.Tests
}
public byte[] ObjectId;
- public GitObjectType ObjectType;
+ public ObjectType ObjectType;
public byte[] Data;
public int Length
diff --git a/LibGit2Sharp/GitObjectType.cs b/LibGit2Sharp/GitObjectType.cs
index 2b03cb5e..024943e3 100644
--- a/LibGit2Sharp/GitObjectType.cs
+++ b/LibGit2Sharp/GitObjectType.cs
@@ -77,5 +77,26 @@ namespace LibGit2Sharp
throw new InvalidOperationException(string.Format("Cannot map {0} to a TreeEntryTargetType.", type));
}
}
+
+ public static ObjectType ToObjectType(this GitObjectType type)
+ {
+ switch (type)
+ {
+ case GitObjectType.Commit:
+ return ObjectType.Commit;
+
+ case GitObjectType.Tree:
+ return ObjectType.Tree;
+
+ case GitObjectType.Blob:
+ return ObjectType.Blob;
+
+ case GitObjectType.Tag:
+ return ObjectType.Tag;
+
+ default:
+ throw new InvalidOperationException(string.Format("Cannot map {0} to a ObjectType.", type));
+ }
+ }
}
}
diff --git a/LibGit2Sharp/OdbBackend.cs b/LibGit2Sharp/OdbBackend.cs
index 995b61a5..5a204869 100644
--- a/LibGit2Sharp/OdbBackend.cs
+++ b/LibGit2Sharp/OdbBackend.cs
@@ -55,7 +55,7 @@ namespace LibGit2Sharp
/// </summary>
public abstract int Read(byte[] oid,
out Stream data,
- out GitObjectType objectType);
+ out ObjectType objectType);
/// <summary>
/// Requests that this backend read an object. The object ID may not be complete (may be a prefix).
@@ -63,14 +63,14 @@ namespace LibGit2Sharp
public abstract int ReadPrefix(byte[] shortOid,
out byte[] oid,
out Stream data,
- out GitObjectType objectType);
+ out ObjectType objectType);
/// <summary>
/// Requests that this backend read an object's header (length and object type) but not its contents.
/// </summary>
public abstract int ReadHeader(byte[] oid,
out int length,
- out GitObjectType objectType);
+ out ObjectType objectType);
/// <summary>
/// Requests that this backend write an object to the backing store. The backend may need to compute the object ID
@@ -79,7 +79,7 @@ namespace LibGit2Sharp
public abstract int Write(byte[] oid,
Stream dataStream,
long length,
- GitObjectType objectType,
+ ObjectType objectType,
out byte[] finalOid);
/// <summary>
@@ -93,7 +93,7 @@ namespace LibGit2Sharp
/// the data in chunks.
/// </summary>
public abstract int WriteStream(long length,
- GitObjectType objectType,
+ ObjectType objectType,
out OdbBackendStream stream);
/// <summary>
@@ -210,7 +210,7 @@ namespace LibGit2Sharp
if (odbBackend != null)
{
Stream dataStream = null;
- GitObjectType objectType;
+ ObjectType objectType;
try
{
@@ -227,7 +227,7 @@ namespace LibGit2Sharp
}
len_p = new UIntPtr((ulong)memoryStream.Capacity);
- type_p = objectType;
+ type_p = objectType.ToGitObjectType();
memoryStream.Seek(0, SeekOrigin.Begin);
buffer_p = new IntPtr(memoryStream.PositionPointer);
@@ -271,7 +271,7 @@ namespace LibGit2Sharp
{
byte[] oid;
Stream dataStream = null;
- GitObjectType objectType;
+ ObjectType objectType;
try
{
@@ -294,7 +294,7 @@ namespace LibGit2Sharp
out_oid.Id = oid;
len_p = new UIntPtr((ulong)memoryStream.Capacity);
- type_p = objectType;
+ type_p = objectType.ToGitObjectType();
memoryStream.Seek(0, SeekOrigin.Begin);
buffer_p = new IntPtr(memoryStream.PositionPointer);
@@ -332,7 +332,7 @@ namespace LibGit2Sharp
if (odbBackend != null)
{
int length;
- GitObjectType objectType;
+ ObjectType objectType;
try
{
@@ -341,7 +341,7 @@ namespace LibGit2Sharp
if (0 == toReturn)
{
len_p = new UIntPtr((uint)length);
- type_p = objectType;
+ type_p = objectType.ToGitObjectType();
}
return toReturn;
@@ -364,6 +364,8 @@ namespace LibGit2Sharp
{
OdbBackend odbBackend = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend;
+ ObjectType objectType = type.ToObjectType();
+
if (odbBackend != null &&
len.ToUInt64() < long.MaxValue)
{
@@ -373,7 +375,7 @@ namespace LibGit2Sharp
{
byte[] finalOid;
- int toReturn = odbBackend.Write(oid.Id, stream, (long)len.ToUInt64(), type, out finalOid);
+ int toReturn = odbBackend.Write(oid.Id, stream, (long)len.ToUInt64(), objectType, out finalOid);
if (0 == toReturn)
{
@@ -402,6 +404,8 @@ namespace LibGit2Sharp
OdbBackend odbBackend = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend;
+ ObjectType objectType = type.ToObjectType();
+
if (odbBackend != null &&
length.ToUInt64() < long.MaxValue)
{
@@ -409,7 +413,7 @@ namespace LibGit2Sharp
try
{
- int toReturn = odbBackend.WriteStream((long)length.ToUInt64(), type, out stream);
+ int toReturn = odbBackend.WriteStream((long)length.ToUInt64(), objectType, out stream);
if (0 == toReturn)
{