зеркало из https://github.com/github/libgit2sharp.git
Slight OdbBackendFixture refactoring
This commit is contained in:
Родитель
8d9fdc9ad3
Коммит
5264090d3c
|
@ -171,8 +171,11 @@ namespace LibGit2Sharp.Tests
|
||||||
|
|
||||||
MockGitObject gitObject;
|
MockGitObject gitObject;
|
||||||
|
|
||||||
if (m_objectIdToContent.TryGetValue(oid, out gitObject))
|
if (!m_objectIdToContent.TryGetValue(oid, out gitObject))
|
||||||
{
|
{
|
||||||
|
return (int) ReturnCode.GIT_ENOTFOUND;
|
||||||
|
}
|
||||||
|
|
||||||
data = Allocate(gitObject.Length);
|
data = Allocate(gitObject.Length);
|
||||||
|
|
||||||
foreach (var chunk in gitObject.Data)
|
foreach (var chunk in gitObject.Data)
|
||||||
|
@ -185,25 +188,22 @@ namespace LibGit2Sharp.Tests
|
||||||
return (int)ReturnCode.GIT_OK;
|
return (int)ReturnCode.GIT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)ReturnCode.GIT_ENOTFOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int ReadPrefix(byte[] shortOid, int len, out byte[] oid, out Stream data, out ObjectType objectType)
|
public override int ReadPrefix(byte[] shortOid, int len, out byte[] oid, out Stream data, out ObjectType objectType)
|
||||||
{
|
{
|
||||||
oid = null;
|
oid = null;
|
||||||
data = null;
|
data = null;
|
||||||
objectType = default(ObjectType);
|
objectType = default(ObjectType);
|
||||||
|
|
||||||
MockGitObject gitObjectAlreadyFound = null;
|
ObjectId matchingKey = null;
|
||||||
|
|
||||||
foreach (MockGitObject gitObject in m_objectIdToContent.Values)
|
foreach (ObjectId objectId in m_objectIdToContent.Keys)
|
||||||
{
|
{
|
||||||
bool match = true;
|
bool match = true;
|
||||||
|
|
||||||
int length = len >> 1;
|
int length = len >> 1;
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
if (gitObject.ObjectId.RawId[i] != shortOid[i])
|
if (objectId.RawId[i] != shortOid[i])
|
||||||
{
|
{
|
||||||
match = false;
|
match = false;
|
||||||
break;
|
break;
|
||||||
|
@ -212,7 +212,7 @@ namespace LibGit2Sharp.Tests
|
||||||
|
|
||||||
if (match && ((len & 1) == 1))
|
if (match && ((len & 1) == 1))
|
||||||
{
|
{
|
||||||
var a = gitObject.ObjectId.RawId[length] >> 4;
|
var a = objectId.RawId[length] >> 4;
|
||||||
var b = shortOid[length] >> 4;
|
var b = shortOid[length] >> 4;
|
||||||
|
|
||||||
if (a != b)
|
if (a != b)
|
||||||
|
@ -226,32 +226,31 @@ namespace LibGit2Sharp.Tests
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null != gitObjectAlreadyFound)
|
if (matchingKey != null)
|
||||||
{
|
{
|
||||||
return (int)ReturnCode.GIT_EAMBIGUOUS;
|
return (int)ReturnCode.GIT_EAMBIGUOUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
gitObjectAlreadyFound = gitObject;
|
matchingKey = objectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null != gitObjectAlreadyFound)
|
if (matchingKey == null)
|
||||||
{
|
{
|
||||||
oid = gitObjectAlreadyFound.ObjectId.RawId;
|
return (int)ReturnCode.GIT_ENOTFOUND;
|
||||||
objectType = gitObjectAlreadyFound.ObjectType;
|
|
||||||
|
|
||||||
data = Allocate(gitObjectAlreadyFound.Length);
|
|
||||||
|
|
||||||
foreach (var chunk in gitObjectAlreadyFound.Data)
|
|
||||||
{
|
|
||||||
data.Write(chunk, 0, chunk.Length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ret = Read(matchingKey, out data, out objectType);
|
||||||
|
|
||||||
|
if (ret != (int)ReturnCode.GIT_OK)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
oid = matchingKey.RawId;
|
||||||
|
|
||||||
return (int)ReturnCode.GIT_OK;
|
return (int)ReturnCode.GIT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)ReturnCode.GIT_ENOTFOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Write(ObjectId oid, Stream dataStream, long length, ObjectType objectType)
|
public override int Write(ObjectId oid, Stream dataStream, long length, ObjectType objectType)
|
||||||
{
|
{
|
||||||
var buffer = ReadBuffer(dataStream, length);
|
var buffer = ReadBuffer(dataStream, length);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче