8000 Get rid of StatusListSafeHandle · vrkcse2011/libgit2sharp@d3622c3 · GitHub
[go: up one dir, main page]

Skip to content

Commit d3622c3

Browse files 8000
committed
Get rid of StatusListSafeHandle
1 parent 4c5c088 commit d3622c3

File tree

8 files changed

+85
-30
lines changed

8 files changed

+85
-30
lines changed

LibGit2Sharp/Core/Handles/Objects.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,73 @@ public void Dispose()
280280
}
281281
}
282282

283+
internal unsafe class StatusListHandle : IDisposable
284+
{
285+
git_status_list* ptr;
286+
internal git_status_list* Handle
287+
{
288+
get
289+
{
290+
return ptr;
291+
}
292+
}
293+
294+
bool owned;
295+
bool disposed;
296+
297+
public unsafe StatusListHandle(git_status_list* handle, bool owned)
298+
{
299+
this.ptr = handle;
300+
this.owned = owned;
301+
}
302+
303+
public unsafe StatusListHandle(IntPtr ptr, bool owned)
304+
{
305+
this.ptr = (git_status_list*) ptr.ToPointer();
306+
this.owned = owned;
307+
}
308+
309+
~StatusListHandle()
310+
{
311+
Dispose(false);
312+
}
313+
314+
internal bool IsNull
315+
{
316+
get
317+
{
318+
return ptr == null;
319+
}
320+
}
321+
322+
internal IntPtr AsIntPtr()
323+
{
324+
return new IntPtr(ptr);
325+
}
326+
327+
void Dispose(bool disposing)
328+
{
329+
if (!disposed)
330+
{
331+
if (owned)
332+
{
333+
NativeMethods.git_status_list_free(ptr);
334+
ptr = null;
335+
}
336+
}
337+
338+
disposed = true;
339+
}
340+
341+
public void Dispose()
342+
{
343+
Dispose(true);
344+
}
345+
346+
public static implicit operator git_status_list*(StatusListHandle handle)
347+
{
348+
return handle.Handle;
349+
}
350+
}
351+
283352
}

LibGit2Sharp/Core/Handles/Objects.tt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ var cNames = new[] {
1616
"git_reference",
1717
"git_repository",
1818
"git_signature",
19+
"git_status_list",
1920
};
2021

2122
var csNames = new[] {
2223
"TreeEntryHandle",
2324
"ReferenceHandle",
2425
"RepositoryHandle",
2526
"SignatureHandle",
27+
"StatusListHandle",
2628
};
2729

2830
for (var i = 0; i < cNames.Length; i++)

LibGit2Sharp/Core/Handles/StatusListSafeHandle.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,22 +1534,22 @@ internal static extern unsafe int git_status_file(
15341534

15351535
[DllImport(libgit2)]
15361536
internal static extern unsafe int git_status_list_new(
1537-
out StatusListSafeHandle git_status_list,
1537+
out git_status_list* git_status_list,
15381538
git_repository* repo,
15391539
GitStatusOptions options);
15401540

15411541
[DllImport(libgit2)]
1542-
internal static extern int git_status_list_entrycount(
1543-
StatusListSafeHandle statusList);
1542+
internal static extern unsafe int git_status_list_entrycount(
1543+
git_status_list* statusList);
15441544

15451545
[DllImport(libgit2)]
15461546
internal static extern unsafe git_status_entry* git_status_byindex(
1547-
StatusListSafeHandle list,
1547+
git_status_list* list,
15481548
UIntPtr idx);
15491549

15501550
[DllImport(libgit2)]
1551-
internal static extern void git_status_list_free(
1552-
IntPtr statusList);
1551+
internal static extern unsafe void git_status_list_free(
1552+
git_status_list* statusList);
15531553

15541554
[DllImport(libgit2)]
15551555
internal static extern void git_strarray_free(

LibGit2Sharp/Core/Opaques.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ internal struct git_tree_entry {}
66
internal struct git_reference { }
77
internal struct git_refspec {}
88
internal struct git_repository {}
9+
internal struct git_status_list {}
910
}
1011

LibGit2Sharp/Core/Proxy.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2833,31 +2833,26 @@ public static unsafe FileStatus git_status_file(RepositoryHandle repo, FilePath
28332833
return status;
28342834
}
28352835

2836-
public static unsafe StatusListSafeHandle git_status_list_new(RepositoryHandle repo, GitStatusOptions options)
2836+
public static unsafe StatusListHandle git_status_list_new(RepositoryHandle repo, GitStatusOptions options)
28372837
{
2838-
StatusListSafeHandle handle;
2839-
int res = NativeMethods.git_status_list_new(out handle, repo, options);
2838+
git_status_list* ptr;
2839+
int res = NativeMethods.git_status_list_new(out ptr, repo, options);
28402840
Ensure.ZeroResult(res);
2841-
return handle;
2841+
return new StatusListHandle(ptr, true);
28422842
}
28432843

2844-
public static int git_status_list_entrycount(StatusListSafeHandle list)
2844+
public static unsafe int git_status_list_entrycount(StatusListHandle list)
28452845
{
28462846
int res = NativeMethods.git_status_list_entrycount(list);
28472847
Ensure.Int32Result(res);
28482848
return res;
28492849
}
28502850

2851-
public static unsafe git_status_entry* git_status_byindex(StatusListSafeHandle list, long idx)
2851+
public static unsafe git_status_entry* git_status_byindex(StatusListHandle list, long idx)
28522852
{
28532853
return NativeMethods.git_status_byindex(list, (UIntPtr)idx);
28542854
}
28552855

2856-
public static void git_status_list_free(IntPtr statusList)
2857-
{
2858-
NativeMethods.git_status_list_free(statusList);
2859-
}
2860-
28612856
#endregion
28622857

28632858
#region git_submodule_

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@
158158
<Compile Include="RefSpecDirection.cs" />
159159
<Compile Include="Core\GitStatusEntry.cs" />
160160
<Compile Include="Core\GitStatusOptions.cs" />
161-
<Compile Include="Core\Handles\StatusListSafeHandle.cs" />
162161
<Compile Include="RenameDetails.cs" />
163162
<Compile Include="RevertResult.cs" />
164163
<Compile Include="RevertOptions.cs" />

LibGit2Sharp/RepositoryStatus.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ internal unsafe RepositoryStatus(Repository repo, StatusOptions options)
5858
statusEntries = new List<StatusEntry>();
5959

6060
using (GitStatusOptions coreOptions = CreateStatusOptions(options ?? new StatusOptions()))
61-
using (StatusListSafeHandle list = Proxy.git_status_list_new(repo.Handle, coreOptions))
61+
using (StatusListHandle list = Proxy.git_status_list_new(repo.Handle, coreOptions))
6262
{
6363
int count = Proxy.git_status_list_entrycount(list);
6464

0 commit comments

Comments
 (0)
0