Slight OdbBackendFixture refactoring

This commit is contained in:
nulltoken 2013-09-08 12:46:05 +02:00
Родитель 8d9fdc9ad3
Коммит 5264090d3c
1 изменённых файлов: 30 добавлений и 31 удалений

Просмотреть файл

@ -171,21 +171,21 @@ namespace LibGit2Sharp.Tests
MockGitObject gitObject; MockGitObject gitObject;
if (m_objectIdToContent.TryGetValue(oid, out gitObject)) if (!m_objectIdToContent.TryGetValue(oid, out gitObject))
{ {
data = Allocate(gitObject.Length); return (int) ReturnCode.GIT_ENOTFOUND;
foreach (var chunk in gitObject.Data)
{
data.Write(chunk, 0, chunk.Length);
}
objectType = gitObject.ObjectType;
return (int)ReturnCode.GIT_OK;
} }
return (int)ReturnCode.GIT_ENOTFOUND; data = Allocate(gitObject.Length);
foreach (var chunk in gitObject.Data)
{
data.Write(chunk, 0, chunk.Length);
}
objectType = gitObject.ObjectType;
return (int)ReturnCode.GIT_OK;
} }
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)
@ -194,16 +194,16 @@ namespace LibGit2Sharp.Tests
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,30 +226,29 @@ 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);
}
return (int)ReturnCode.GIT_OK;
} }
return (int)ReturnCode.GIT_ENOTFOUND; int ret = Read(matchingKey, out data, out objectType);
if (ret != (int)ReturnCode.GIT_OK)
{
return ret;
}
oid = matchingKey.RawId;
return (int)ReturnCode.GIT_OK;
} }
public override int Write(ObjectId oid, Stream dataStream, long length, ObjectType objectType) public override int Write(ObjectId oid, Stream dataStream, long length, ObjectType objectType)