-
Notifications
You must be signed in to change notification settings - Fork 891
/
ObjectSafeWrapper.cs
43 lines (36 loc) · 1.17 KB
/
ObjectSafeWrapper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using LibGit2Sharp.Core.Handles;
namespace LibGit2Sharp.Core
{
internal class ObjectSafeWrapper : IDisposable
{
private readonly ObjectHandle objectPtr;
public unsafe ObjectSafeWrapper(ObjectId id, RepositoryHandle handle, bool allowNullObjectId = false, bool throwIfMissing = false)
{
Ensure.ArgumentNotNull(handle, "handle");
if (allowNullObjectId && id == null)
{
objectPtr = new ObjectHandle(null, false);
}
else
{
Ensure.ArgumentNotNull(id, "id");
objectPtr = Proxy.git_object_lookup(handle, id, GitObjectType.Any);
}
if (objectPtr == null && throwIfMissing)
{
throw new NotFoundException($"No valid git object identified by '{id}' exists in the repository.");
}
}
public ObjectHandle ObjectPtr => objectPtr;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
objectPtr.SafeDispose();
}
}
}