@@ -85,77 +85,44 @@ public virtual RebaseResult Start(Branch branch, Branch upstream, Branch onto, S
8585 "A {0} operation is already in progress." , this . repository . Info . CurrentOperation ) ) ;
8686 }
8787
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 ) =>
9989 {
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+ } ;
11394
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 ) ?
11999 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+ } ;
132102
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 ( )
142104 {
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 ;
159126 }
160127 }
161128
@@ -170,10 +137,8 @@ public virtual RebaseResult Continue(Signature committer, RebaseOptions options)
170137
171138 options = options ?? new RebaseOptions ( ) ;
172139
173- RebaseSafeHandle rebase = null ;
174- try
140+ using ( RebaseSafeHandle rebase = Proxy . git_rebase_open ( repository . Handle ) )
175141 {
176- rebase = Proxy . git_rebase_open ( repository . Handle ) ;
177142 var rebaseCommitResult = Proxy . git_rebase_commit ( rebase , null , committer ) ;
178143
179144 // Report that we just completed the step
@@ -203,29 +168,17 @@ public virtual RebaseResult Continue(Signature committer, RebaseOptions options)
203168 RebaseResult rebaseResult = RebaseOperationImpl . Run ( rebase , repository , committer , options , false ) ;
204169 return rebaseResult ;
205170 }
206- finally
207- {
208- rebase . SafeDispose ( ) ;
209- rebase = null ;
210- }
211171 }
212172
213173 /// <summary>
214174 /// Abort the rebase operation.
215175 /// </summary>
216176 public virtual void Abort ( )
217177 {
218- RebaseSafeHandle rebase = null ;
219- try
178+ using ( RebaseSafeHandle rebase = Proxy . git_rebase_open ( repository . Handle ) )
220179 {
221- rebase = Proxy . git_rebase_open ( repository . Handle ) ;
222180 Proxy . git_rebase_abort ( rebase ) ;
223181 }
224- finally
225- {
226- rebase . SafeDispose ( ) ;
227- rebase = null ;
228- }
229182 }
230183
231184 /// <summary>
@@ -246,11 +199,8 @@ public virtual RebaseStepInfo GetCurrentStepInfo()
246199 return null ;
247200 }
248201
249- RebaseSafeHandle rebaseHandle = null ;
250-
251- try
202+ using ( RebaseSafeHandle rebaseHandle = Proxy . git_rebase_open ( repository . Handle ) )
252203 {
253- rebaseHandle = Proxy . git_rebase_open ( repository . Handle ) ;
254204 long currentStepIndex = Proxy . git_rebase_operation_current ( rebaseHandle ) ;
255205 long totalStepCount = Proxy . git_rebase_operation_entrycount ( rebaseHandle ) ;
256206 GitRebaseOperation gitRebasestepInfo = Proxy . git_rebase_operation_byindex ( rebaseHandle , currentStepIndex ) ;
@@ -261,11 +211,6 @@ public virtual RebaseStepInfo GetCurrentStepInfo()
261211 totalStepCount ) ;
262212 return stepInfo ;
263213 }
264- finally
265- {
266- rebaseHandle . SafeDispose ( ) ;
267- rebaseHandle = null ;
268- }
269214 }
270215 }
271216}
0 commit comments