Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dd9d358

Browse files
committed
Make OdbBackend Read[Prefix]() return UnmanagedMemoryStream
1 parent e24b4d0 commit dd9d358

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

LibGit2Sharp.Tests/OdbBackendFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ protected override OdbBackendOperations SupportedOperations
240240
}
241241
}
242242

243-
public override int Read(ObjectId oid, out Stream data, out ObjectType objectType)
243+
public override int Read(ObjectId oid, out UnmanagedMemoryStream data, out ObjectType objectType)
244244
{
245245
data = null;
246246
objectType = default(ObjectType);
@@ -264,7 +264,7 @@ public override int Read(ObjectId oid, out Stream data, out ObjectType objectTyp
264264
return (int)ReturnCode.GIT_OK;
265265
}
266266

267-
public override int ReadPrefix(string shortSha, out ObjectId id, out Stream data, out ObjectType objectType)
267+
public override int ReadPrefix(string shortSha, out ObjectId id, out UnmanagedMemoryStream data, out ObjectType objectType)
268268
{
269269
id = null;
270270
data = null;

LibGit2Sharp/OdbBackend.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected abstract OdbBackendOperations SupportedOperations
3838
/// </summary>
3939
/// <param name="bytes">Number of bytes to allocate</param>
4040
/// <returns>An Stream for you to write to and then return. Do not dispose this object before returning it.</returns>
41-
protected unsafe Stream Allocate(long bytes)
41+
protected unsafe UnmanagedMemoryStream Allocate(long bytes)
4242
{
4343
if (bytes < 0 ||
4444
(UIntPtr.Size == sizeof(int) && bytes > int.MaxValue))
@@ -56,7 +56,7 @@ protected unsafe Stream Allocate(long bytes)
5656
/// </summary>
5757
public abstract int Read(
5858
ObjectId id,
59-
out Stream data,
59+
out UnmanagedMemoryStream data,
6060
out ObjectType objectType);
6161

6262
/// <summary>
@@ -65,7 +65,7 @@ public abstract int Read(
6565
public abstract int ReadPrefix(
6666
string shortSha,
6767
out ObjectId oid,
68-
out Stream data,
68+
out UnmanagedMemoryStream data,
6969
out ObjectType objectType);
7070

7171
/// <summary>
@@ -242,21 +242,18 @@ private unsafe static int Read(
242242
return (int)GitErrorCode.Error;
243243
}
244244

245-
Stream dataStream = null;
245+
UnmanagedMemoryStream memoryStream = null;
246246

247247
try
248248
{
249249
ObjectType objectType;
250-
int toReturn = odbBackend.Read(new ObjectId(oid), out dataStream, out objectType);
250+
int toReturn = odbBackend.Read(new ObjectId(oid), out memoryStream, out objectType);
251251

252252
if (toReturn != 0)
253253
{
254254
return toReturn;
255255
}
256256

257-
// Caller is expected to give us back a stream created with the Allocate() method.
258-
var memoryStream = dataStream as UnmanagedMemoryStream;
259-
260257
if (memoryStream == null)
261258
{
262259
return (int)GitErrorCode.Error;
@@ -276,9 +273,9 @@ private unsafe static int Read(
276273
}
277274
finally
278275
{
279-
if (dataStream != null)
276+
if (memoryStream != null)
280277
{
281-
dataStream.Dispose();
278+
memoryStream.Dispose();
282279
}
283280
}
284281

@@ -305,7 +302,7 @@ private unsafe static int ReadPrefix(
305302
return (int)GitErrorCode.Error;
306303
}
307304

308-
Stream dataStream = null;
305+
UnmanagedMemoryStream memoryStream = null;
309306

310307
try
311308
{
@@ -314,16 +311,13 @@ private unsafe static int ReadPrefix(
314311
ObjectId oid;
315312
ObjectType objectType;
316313

317-
int toReturn = odbBackend.ReadPrefix(shortSha, out oid, out dataStream, out objectType);
314+
int toReturn = odbBackend.ReadPrefix(shortSha, out oid, out memoryStream, out objectType);
318315

319316
if (toReturn != 0)
320317
{
321318
return toReturn;
322319
}
323320

324-
// Caller is expected to give us back a stream created with the Allocate() method.
325-
var memoryStream = dataStream as UnmanagedMemoryStream;
326-
327321
if (memoryStream == null)
328322
{
329323
return (int)GitErrorCode.Error;
@@ -343,9 +337,9 @@ private unsafe static int ReadPrefix(
343337
}
344338
finally
345339
{
346-
if (null != dataStream)
340+
if (memoryStream != null)
347341
{
348-
dataStream.Dispose();
342+
memoryStream.Dispose();
349343
}
350344
}
351345

0 commit comments

Comments
 (0)