@@ -48,22 +48,21 @@ public async Task<bool> ExecAsync()
4848 proc . OutputDataReceived += ( _ , e ) => HandleOutput ( e . Data , errs ) ;
4949 proc . ErrorDataReceived += ( _ , e ) => HandleOutput ( e . Data , errs ) ;
5050
51- Process dummy = null ;
52- var dummyProcLock = new object ( ) ;
51+ var captured = new CapturedProcess ( ) { Process = proc } ;
52+ var capturedLock = new object ( ) ;
5353 try
5454 {
5555 proc . Start ( ) ;
5656
5757 // Not safe, please only use `CancellationToken` in readonly commands.
5858 if ( CancellationToken . CanBeCanceled )
5959 {
60- dummy = proc ;
6160 CancellationToken . Register ( ( ) =>
6261 {
63- lock ( dummyProcLock )
62+ lock ( capturedLock )
6463 {
65- if ( dummy is { HasExited : false } )
66- dummy . Kill ( ) ;
64+ if ( captured is { Process : { HasExited : false } } )
65+ captured . Process . Kill ( ) ;
6766 }
6867 } ) ;
6968 }
@@ -89,12 +88,9 @@ public async Task<bool> ExecAsync()
8988 HandleOutput ( e . Message , errs ) ;
9089 }
9190
92- if ( dummy != null )
91+ lock ( capturedLock )
9392 {
94- lock ( dummyProcLock )
95- {
96- dummy = null ;
97- }
93+ captured . Process = null ;
9894 }
9995
10096 Log ? . AppendLine ( string . Empty ) ;
@@ -116,7 +112,8 @@ public async Task<bool> ExecAsync()
116112
117113 protected Result ReadToEnd ( )
118114 {
119- using var proc = new Process ( ) { StartInfo = CreateGitStartInfo ( true ) } ;
115+ using var proc = new Process ( ) ;
116+ proc . StartInfo = CreateGitStartInfo ( true ) ;
120117
121118 try
122119 {
@@ -138,7 +135,8 @@ protected Result ReadToEnd()
138135
139136 protected async Task < Result > ReadToEndAsync ( )
140137 {
141- using var proc = new Process ( ) { StartInfo = CreateGitStartInfo ( true ) } ;
138+ using var proc = new Process ( ) ;
139+ proc . StartInfo = CreateGitStartInfo ( true ) ;
142140
143141 try
144142 {
@@ -245,6 +243,11 @@ private void HandleOutput(string line, List<string> errs)
245243 errs . Add ( line ) ;
246244 }
247245
246+ private class CapturedProcess
247+ {
248+ public Process Process { get ; set ; } = null ;
249+ }
250+
248251 [ GeneratedRegex ( @"\d+%" ) ]
249252 private static partial Regex REG_PROGRESS ( ) ;
250253 }
0 commit comments