@@ -48,22 +48,21 @@ public async Task<bool> ExecAsync()
48
48
proc . OutputDataReceived += ( _ , e ) => HandleOutput ( e . Data , errs ) ;
49
49
proc . ErrorDataReceived += ( _ , e ) => HandleOutput ( e . Data , errs ) ;
50
50
51
- Process dummy = null ;
52
- var dummyProcLock = new object ( ) ;
51
+ var captured = new CapturedProcess ( ) { Process = proc } ;
52
+ var capturedLock = new object ( ) ;
53
53
try
54
54
{
55
55
proc . Start ( ) ;
56
56
57
57
// Not safe, please only use `CancellationToken` in readonly commands.
58
58
if ( CancellationToken . CanBeCanceled )
59
59
{
60
- dummy = proc ;
61
60
CancellationToken . Register ( ( ) =>
62
61
{
63
- lock ( dummyProcLock )
62
+ lock ( capturedLock )
64
63
{
65
- if ( dummy is { HasExited : false } )
66
- dummy . Kill ( ) ;
64
+ if ( captured is { Process : { HasExited : false } } )
65
+ captured . Process . Kill ( ) ;
67
66
}
68
67
} ) ;
69
68
}
@@ -89,12 +88,9 @@ public async Task<bool> ExecAsync()
89
88
HandleOutput ( e . Message , errs ) ;
90
89
}
91
90
92
- if ( dummy != null )
91
+ lock ( capturedLock )
93
92
{
94
- lock ( dummyProcLock )
95
- {
96
- dummy = null ;
97
- }
93
+ captured . Process = null ;
98
94
}
99
95
100
96
Log ? . AppendLine ( string . Empty ) ;
@@ -116,7 +112,8 @@ public async Task<bool> ExecAsync()
116
112
117
113
protected Result ReadToEnd ( )
118
114
{
119
- using var proc = new Process ( ) { StartInfo = CreateGitStartInfo ( true ) } ;
115
+ using var proc = new Process ( ) ;
116
+ proc . StartInfo = CreateGitStartInfo ( true ) ;
120
117
121
118
try
122
119
{
@@ -138,7 +135,8 @@ protected Result ReadToEnd()
138
135
139
136
protected async Task < Result > ReadToEndAsync ( )
140
137
{
141
- using var proc = new Process ( ) { StartInfo = CreateGitStartInfo ( true ) } ;
138
+ using var proc = new Process ( ) ;
139
+ proc . StartInfo = CreateGitStartInfo ( true ) ;
142
140
143
141
try
144
142
{
@@ -245,6 +243,11 @@ private void HandleOutput(string line, List<string> errs)
245
243
errs . Add ( line ) ;
246
244
}
247
245
246
+ private class CapturedProcess
247
+ {
248
+ public Process Process { get ; set ; } = null ;
249
+ }
250
+
248
251
[ GeneratedRegex ( @"\d+%" ) ]
249
252
private static partial Regex REG_PROGRESS ( ) ;
250
253
}
0 commit comments