@@ -85,77 +85,44 @@ public virtual RebaseResult Start(Branch branch, Branch upstream, Branch onto, S
85
85
"A {0} operation is already in progress." , this . repository . Info . CurrentOperation ) ) ;
86
86
}
87
87
88
- ReferenceSafeHandle branchRefPtr = null ;
89
- ReferenceSafeHandle upstreamRefPtr = null ;
90
- ReferenceSafeHandle ontoRefPtr = null ;
91
-
92
- GitAnnotatedCommitHandle annotatedBranchCommitHandle = null ;
93
- GitAnnotatedCommitHandle annotatedUpstreamRefPtrCommitHandle = null ;
94
- GitAnnotatedCommitHandle annotatedOntoRefPtrCommitHandle = null ;
95
-
96
- RebaseSafeHandle rebaseOperationHandle = null ;
97
-
98
- try
88
+ Func < Branch , ReferenceSafeHandle > RefHandleFromBranch = ( Branch b ) =>
99
89
{
100
- branchRefPtr = ( branch == null ) ?
101
- this . repository . Refs . RetrieveReferencePtr ( this . repository . Head . CanonicalName ) :
102
- this . repository . Refs . RetrieveReferencePtr ( branch . CanonicalName ) ;
103
-
104
- upstreamRefPtr = ( upstream == null ) ?
105
- null : this . repository . Refs . RetrieveReferencePtr ( upstream . CanonicalName ) ;
106
-
107
- ontoRefPtr = ( onto == null ) ?
108
- null : this . repository . Refs . RetrieveReferencePtr ( onto . CanonicalName ) ;
109
-
110
- annotatedBranchCommitHandle = ( branchRefPtr == null ) ?
111
- new GitAnnotatedCommitHandle ( ) :
112
- Proxy . git_annotated_commit_from_ref ( this . repository . Handle , branchRefPtr ) ;
90
+ return ( b == null ) ?
91
+ null :
92
+ this . repository . Refs . RetrieveReferencePtr ( b . CanonicalName ) ;
93
+ } ;
113
94
114
- annotatedUpstreamRefPtrCommitHandle = ( upstreamRefPtr == null ) ?
115
- new GitAnnotatedCommitHandle ( ) :
116
- Proxy . git_annotated_commit_from_ref ( this . repository . Handle , upstreamRefPtr ) ;
117
-
118
- annotatedOntoRefPtrCommitHandle = ( ontoRefPtr == null ) ?
95
+ Func < ReferenceSafeHandle , GitAnnotatedCommitHandle > AnnotatedCommitHandleFromRefHandle =
96
+ ( ReferenceSafeHandle refHandle ) =>
97
+ {
98
+ return ( refHandle == null ) ?
119
99
new GitAnnotatedCommitHandle ( ) :
120
- Proxy . git_annotated_commit_from_ref ( this . repository . Handle , ontoRefPtr ) ;
121
-
122
- GitRebaseOptions gitRebaseOptions = new GitRebaseOptions ( )
123
- {
124
- version = 1 ,
125
- } ;
126
-
127
- rebaseOperationHandle = Proxy . git_rebase_init ( this . repository . Handle ,
128
- annotatedBranchCommitHandle ,
129
- annotatedUpstreamRefPtrCommitHandle ,
130
- annotatedOntoRefPtrCommitHandle ,
131
- ref gitRebaseOptions ) ;
100
+ Proxy . git_annotated_commit_from_ref ( this . repository . Handle , refHandle ) ;
101
+ } ;
132
102
133
- RebaseResult rebaseResult =
134
- RebaseOperationImpl . Run ( rebaseOperationHandle ,
135
- this . repository ,
136
- committer ,
137
- options ,
138
- true ) ;
139
- return rebaseResult ;
140
- }
141
- finally
103
+ GitRebaseOptions gitRebaseOptions = new GitRebaseOptions ( )
142
104
{
143
- branchRefPtr . SafeDispose ( ) ;
144
- branchRefPtr = null ;
145
- upstreamRefPtr . SafeDispose ( ) ;
146
- upstreamRefPtr = null ;
147
- ontoRefPtr . SafeDispose ( ) ;
148
- ontoRefPtr = null ;
149
-
150
- annotatedBranchCommitHandle . SafeDispose ( ) ;
151
- annotatedBranchCommitHandle = null ;
152
- annotatedUpstreamRefPtrCommitHandle . SafeDispose ( ) ;
153
- annotatedUpstreamRefPtrCommitHandle = null ;
154
- annotatedOntoRefPtrCommitHandle . SafeDispose ( ) ;
155
- annotatedOntoRefPtrCommitHandle = null ;
156
-
157
- rebaseOperationHandle . SafeDispose ( ) ;
158
- rebaseOperationHandle = null ;
105
+ version = 1 ,
106
+ } ;
107
+
108
+ using ( ReferenceSafeHandle branchRefPtr = RefHandleFromBranch ( branch ) )
109
+ using ( ReferenceSafeHandle upstreamRefPtr = RefHandleFromBranch ( upstream ) )
110
+ using ( ReferenceSafeHandle ontoRefPtr = RefHandleFromBranch ( onto ) )
111
+ using ( GitAnnotatedCommitHandle annotatedBranchCommitHandle = AnnotatedCommitHandleFromRefHandle ( branchRefPtr ) )
112
+ using ( GitAnnotatedCommitHandle upstreamRefAnnotatedCommitHandle = AnnotatedCommitHandleFromRefHandle ( upstreamRefPtr ) )
113
+ using ( GitAnnotatedCommitHandle ontoRefAnnotatedCommitHandle = AnnotatedCommitHandleFromRefHandle ( ontoRefPtr ) )
114
+ using ( RebaseSafeHandle rebaseOperationHandle = Proxy . git_rebase_init ( this . repository . Handle ,
115
+ annotatedBranchCommitHandle ,
116
+ upstreamRefAnnotatedCommitHandle ,
117
+ ontoRefAnnotatedCommitHandle ,
118
+ ref gitRebaseOptions ) )
119
+ {
120
+ RebaseResult rebaseResult = RebaseOperationImpl . Run ( rebaseOperationHandle ,
121
+ this . repository ,
122
+ committer ,
123
+ options ,
124
+ true ) ;
125
+ return rebaseResult ;
159
126
}
160
127
}
161
128
@@ -170,10 +137,8 @@ public virtual RebaseResult Continue(Signature committer, RebaseOptions options)
170
137
171
138
options = options ?? new RebaseOptions ( ) ;
172
139
173
- RebaseSafeHandle rebase = null ;
174
- try
140
+ using ( RebaseSafeHandle rebase = Proxy . git_rebase_open ( repository . Handle ) )
175
141
{
176
- rebase = Proxy . git_rebase_open ( repository . Handle ) ;
177
142
var rebaseCommitResult = Proxy . git_rebase_commit ( rebase , null , committer ) ;
178
143
179
144
// Report that we just completed the step
@@ -203,29 +168,17 @@ public virtual RebaseResult Continue(Signature committer, RebaseOptions options)
203
168
RebaseResult rebaseResult = RebaseOperationImpl . Run ( rebase , repository , committer , options , false ) ;
204
169
return rebaseResult ;
205
170
}
206
- finally
207
- {
208
- rebase . SafeDispose ( ) ;
209
- rebase = null ;
210
- }
211
171
}
212
172
213
173
/// <summary>
214
174
/// Abort the rebase operation.
215
175
/// </summary>
216
176
public virtual void Abort ( )
217
177
{
218
- RebaseSafeHandle rebase = null ;
219
- try
178
+ using ( RebaseSafeHandle rebase = Proxy . git_rebase_open ( repository . Handle ) )
220
179
{
221
- rebase = Proxy . git_rebase_open ( repository . Handle ) ;
222
180
Proxy . git_rebase_abort ( rebase ) ;
223
181
}
224
- finally
225
- {
226
- rebase . SafeDispose ( ) ;
227
- rebase = null ;
228
- }
229
182
}
230
183
231
184
/// <summary>
@@ -246,11 +199,8 @@ public virtual RebaseStepInfo GetCurrentStepInfo()
246
199
return null ;
247
200
}
248
201
249
- RebaseSafeHandle rebaseHandle = null ;
250
-
251
- try
202
+ using ( RebaseSafeHandle rebaseHandle = Proxy . git_rebase_open ( repository . Handle ) )
252
203
{
253
- rebaseHandle = Proxy . git_rebase_open ( repository . Handle ) ;
254
204
long currentStepIndex = Proxy . git_rebase_operation_current ( rebaseHandle ) ;
255
205
long totalStepCount = Proxy . git_rebase_operation_entrycount ( rebaseHandle ) ;
256
206
GitRebaseOperation gitRebasestepInfo = Proxy . git_rebase_operation_byindex ( rebaseHandle , currentStepIndex ) ;
@@ -261,11 +211,6 @@ public virtual RebaseStepInfo GetCurrentStepInfo()
261
211
totalStepCount ) ;
262
212
return stepInfo ;
263
213
}
264
- finally
265
- {
266
- rebaseHandle . SafeDispose ( ) ;
267
- rebaseHandle = null ;
268
- }
269
214
}
270
215
}
271
216
}
0 commit comments