Skip to content

Commit d3622c3

Browse files
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+
internalunsafeclassStatusListHandle:IDisposable
284+
{
285+
git_status_list*ptr;
286+
internalgit_status_list*Handle
287+
{
288+
get
289+
{
290+
returnptr;
291+
}
292+
}
293+
294+
boolowned;
295+
booldisposed;
296+
297+
publicunsafeStatusListHandle(git_status_list*handle,boolowned)
298+
{
299+
this.ptr=handle;
300+
this.owned=owned;
301+
}
302+
303+
publicunsafeStatusListHandle(IntPtrptr,boolowned)
304+
{
305+
this.ptr=(git_status_list*)ptr.ToPointer();
306+
this.owned=owned;
307+
}
308+
309+
~StatusListHandle()
310+
{
311+
Dispose(false);
312+
}
313+
314+
internalboolIsNull
315+
{
316+
get
317+
{
318+
returnptr==null;
319+
}
320+
}
321+
322+
internalIntPtrAsIntPtr()
323+
{
324+
returnnewIntPtr(ptr);
325+
}
326+
327+
voidDispose(booldisposing)
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+
publicvoidDispose()
342+
{
343+
Dispose(true);
344+
}
345+
346+
publicstaticimplicitoperatorgit_status_list*(StatusListHandlehandle)
347+
{
348+
returnhandle.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
internalstaticexternunsafeintgit_status_list_new(
1537-
outStatusListSafeHandlegit_status_list,
1537+
outgit_status_list*git_status_list,
15381538
git_repository*repo,
15391539
GitStatusOptionsoptions);
15401540

15411541
[DllImport(libgit2)]
1542-
internalstaticexternintgit_status_list_entrycount(
1543-
StatusListSafeHandlestatusList);
1542+
internalstaticexternunsafeintgit_status_list_entrycount(
1543+
git_status_list*statusList);
15441544

15451545
[DllImport(libgit2)]
15461546
internalstaticexternunsafegit_status_entry*git_status_byindex(
1547-
StatusListSafeHandlelist,
1547+
git_status_list*list,
15481548
UIntPtridx);
15491549

15501550
[DllImport(libgit2)]
1551-
internalstaticexternvoidgit_status_list_free(
1552-
IntPtrstatusList);
1551+
internalstaticexternunsafevoidgit_status_list_free(
1552+
git_status_list*statusList);
15531553

15541554
[DllImport(libgit2)]
15551555
internalstaticexternvoidgit_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
internalstructgit_reference{}
77
internalstructgit_refspec{}
88
internalstructgit_repository{}
9+
internalstructgit_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
returnstatus;
28342834
}
28352835

2836-
publicstaticunsafeStatusListSafeHandlegit_status_list_new(RepositoryHandlerepo,GitStatusOptionsoptions)
2836+
publicstaticunsafeStatusListHandlegit_status_list_new(RepositoryHandlerepo,GitStatusOptionsoptions)
28372837
{
2838-
StatusListSafeHandlehandle;
2839-
intres=NativeMethods.git_status_list_new(outhandle,repo,options);
2838+
git_status_list*ptr;
2839+
intres=NativeMethods.git_status_list_new(outptr,repo,options);
28402840
Ensure.ZeroResult(res);
2841-
returnhandle;
2841+
returnnewStatusListHandle(ptr,true);
28422842
}
28432843

2844-
publicstaticintgit_status_list_entrycount(StatusListSafeHandlelist)
2844+
publicstaticunsafeintgit_status_list_entrycount(StatusListHandlelist)
28452845
{
28462846
intres=NativeMethods.git_status_list_entrycount(list);
28472847
Ensure.Int32Result(res);
28482848
returnres;
28492849
}
28502850

2851-
publicstaticunsafegit_status_entry*git_status_byindex(StatusListSafeHandlelist,longidx)
2851+
publicstaticunsafegit_status_entry*git_status_byindex(StatusListHandlelist,longidx)
28522852
{
28532853
returnNativeMethods.git_status_byindex(list,(UIntPtr)idx);
28542854
}
28552855

2856-
publicstaticvoidgit_status_list_free(IntPtrstatusList)
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
<CompileInclude="RefSpecDirection.cs" />
159159
<CompileInclude="Core\GitStatusEntry.cs" />
160160
<CompileInclude="Core\GitStatusOptions.cs" />
161-
<CompileInclude="Core\Handles\StatusListSafeHandle.cs" />
162161
<CompileInclude="RenameDetails.cs" />
163162
<CompileInclude="RevertResult.cs" />
164163
<CompileInclude="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=newList<StatusEntry>();
5959

6060
using(GitStatusOptionscoreOptions=CreateStatusOptions(options??newStatusOptions()))
61-
using(StatusListSafeHandlelist=Proxy.git_status_list_new(repo.Handle,coreOptions))
61+
using(StatusListHandlelist=Proxy.git_status_list_new(repo.Handle,coreOptions))
6262
{
6363
intcount=Proxy.git_status_list_entrycount(list);
6464

0 commit comments

Comments
(0)