8000 Move git_reference to the template · vrkcse2011/libgit2sharp@5762938 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5762938

Browse files
committed
Move git_reference to the template
1 parent c05ee27 commit 5762938
< 10000 button data-component="IconButton" type="button" data-testid="expand-file-tree-button" aria-expanded="false" aria-controls="diff_file_tree" data-analytics-opt-out="true" class="prc-Button-ButtonBase-c50BI d-md-none position-relative fgColor-muted prc-Button-IconButton-szpyj" data-loading="false" data-no-visuals="true" data-size="medium" data-variant="invisible" aria-describedby=":Rab6lab:-loading-announcement" aria-labelledby="expand-button-file-tree-button">

10 files changed

+167
-104
lines changed

LibGit2Sharp/BranchCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public virtual void Remove(Branch branch)
199199
{
200200
Ensure.ArgumentNotNull(branch, "branch");
201201

202-
using (GitReferenceHandle referencePtr = repo.Refs.RetrieveReferencePtr(branch.CanonicalName))
202+
using (ReferenceHandle referencePtr = repo.Refs.RetrieveReferencePtr(branch.CanonicalName))
203203
{
204204
Proxy.git_branch_delete(referencePtr);
205205
}
@@ -267,7 +267,7 @@ public virtual Branch Rename(Branch branch, string newName, bool allowOverwrite)
267267
branch.FriendlyName);
268268
}
269269

270-
using (GitReferenceHandle referencePtr = repo.Refs.RetrieveReferencePtr(Reference.LocalBranchPrefix + branch.FriendlyName))
270+
using (ReferenceHandle referencePtr = repo.Refs.RetrieveReferencePtr(Reference.LocalBranchPrefix + branch.FriendlyName))
271271
{
272272
using (Proxy.git_branch_move(referencePtr, newName, allowOverwrite))
273273
{ }

LibGit2Sharp/Core/Handles/GitReferenceHandle.cs

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

LibGit2Sharp/Core/Handles/Objects.cs

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,27 @@ namespace LibGit2Sharp.Core
66

77
internal unsafe class TreeEntryHandle : IDisposable
88
{
9-
internal git_tree_entry* Handle { get; private set; }
9+
git_tree_entry* ptr;
10+
internal git_tree_entry* Handle
11+
{
12+
get
13+
{
14+
return ptr;
15+
}
16+
}
17+
1018
bool owned;
1119
bool disposed;
1220

1321
public unsafe TreeEntryHandle(git_tree_entry* handle, bool owned)
1422
{
15-
this.Handle = handle;
23+
this.ptr = handle;
24+
this.owned = owned;
25+
}
26+
27+
public unsafe TreeEntryHandle(IntPtr ptr, bool owned)
28+
{
29+
this.ptr = (git_tree_entry*) ptr.ToPointer();
1630
this.owned = owned;
1731
}
1832

@@ -21,13 +35,22 @@ public unsafe TreeEntryHandle(git_tree_entry* handle, bool owned)
2135
Dispose(false);
2236
}
2337

38+
internal bool IsNull
39+
{
40+
get
41+
{
42+
return ptr == null;
43+
}
44+
}
45+
46+
2447
void Dispose(bool disposing)
2548
{
2649
if (!disposed)
2750
{
2851
if (owned)
2952
{
30-
NativeMethods.git_tree_entry_free(Handle);
53+
NativeMethods.git_tree_entry_free(ptr);
3154
}
3255
}
3356

@@ -39,4 +62,64 @@ public void Dispose()
3962
Dispose(true);
4063
}
4164
}
65+
66+
internal unsafe class ReferenceHandle : IDisposable
67+
{
68+
git_reference* ptr;
69+
internal git_reference* Handle
70+
{
71+
get
72+
{
73+
return ptr;
74+
}
75+
}
76+
77+
bool owned;
78+
bool disposed;
79+
80+
public unsafe ReferenceHandle(git_reference* handle, bool owned)
81+
{
82+
this.ptr = handle;
83+
this.owned = owned;
84+
}
85+
86+
public unsafe ReferenceHandle(IntPtr ptr, bool owned)
87+
{
88+
this.ptr = (git_reference*) ptr.ToPointer();
89+
this.owned = owned;
90+
}
91+
92+
~ReferenceHandle()
93+
{
94+
Dispose(false);
95+
}
96+
97+
internal bool IsNull
98+
{
99+
get
100+
{
101+
return ptr == null;
102+
}
103+
}
104+
105+
106+
void Dispose(bool disposing)
107+
{
108+
if (!disposed)
109+
{
110+
if (owned)
111+
{
112+
NativeMethods.git_reference_free(ptr);
113+
}
114+
}
115+
116+
disposed = true;
117+
}
118+
119+
public void Dispose()
120+
{
121+
Dispose(true);
122+
}
123+
}
124+
42125
}

LibGit2Sharp/Core/Handles/Objects.tt

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,40 @@ namespace LibGit2Sharp.Core
1313
<#
1414
var cNames = new[] {
1515
"git_tree_entry",
16+
"git_reference",
1617
};
1718

1819
var csNames = new[] {
19-
"TreeEntryHandle"
20+
"TreeEntryHandle",
21+
"ReferenceHandle",
2022
};
2123

2224
for (var i = 0; i < cNames.Length; i++)
2325
{
2426
#>
2527
internal unsafe class <#= csNames[i] #> : IDisposable
2628
{
27-
internal <#= cNames[i] #>* Handle { get; private set; }
29+
<#= cNames[i] #>* ptr;
30+
internal <#= cNames[i] #>* Handle
31+
{
32+
get
33+
{
34+
return ptr;
35+
}
36+
}
37+
2838
bool owned;
2939
bool disposed;
3040

3141
public unsafe <#= csNames[i] #>(<#= cNames[i] #>* handle, bool owned)
3242
{
33-
this.Handle = handle;
43+
this.ptr = handle;
44+
this.owned = owned;
45+
}
46+
47+
public unsafe <#= csNames[i] #>(IntPtr ptr, bool owned)
48+
{
49+
this.ptr = (<#= cNames[i] #>*) ptr.ToPointer();
3450
this.owned = owned;
3551
}
3652

@@ -39,13 +55,22 @@ for (var i = 0; i < cNames.Length; i++)
3955
Dispose(false);
4056
}
4157

58+
internal bool IsNull
59+
{
60+
get
61+
{
62+
return ptr == null;
63+
}
64+
}
65+
66+
4267
void Dispose(bool disposing)
4368
{
4469
if (!disposed)
4570
{
4671
if (owned)
4772
{
48-
NativeMethods.<#= cNames[i] #>_free(Handle);
73+
NativeMethods.<#= cNames[i] #>_free(ptr);
4974
}
5075
}
5176

@@ -57,6 +82,7 @@ for (var i = 0; i < cNames.Length; i++)
5782
Dispose(true);
5883
}
5984
}
85+
6086
<#
6187
}
6288
#>

0 commit comments

Comments
 (0)
0