@@ -9,10 +9,12 @@ import (
9
9
"github.com/sourcegraph/src-cli/internal/output"
10
10
)
11
11
12
- func newCampaignProgressPrinter (out * output.Output , numParallelism int ) * campaignProgressPrinter {
12
+ func newCampaignProgressPrinter (out * output.Output , verbose bool , numParallelism int ) * campaignProgressPrinter {
13
13
return & campaignProgressPrinter {
14
14
out : out ,
15
15
16
+ verbose : verbose ,
17
+
16
18
numParallelism : numParallelism ,
17
19
18
20
completedTasks : map [string ]bool {},
@@ -26,6 +28,8 @@ func newCampaignProgressPrinter(out *output.Output, numParallelism int) *campaig
26
28
type campaignProgressPrinter struct {
27
29
out * output.Output
28
30
31
+ verbose bool
32
+
29
33
progress output.ProgressWithStatusBars
30
34
numStatusBars int
31
35
@@ -134,18 +138,47 @@ func (p *campaignProgressPrinter) PrintStatuses(statuses []*campaigns.TaskStatus
134
138
}
135
139
136
140
for _ , ts := range newlyCompleted {
137
- statusText , err := taskStatusText (ts )
138
- if err != nil {
139
- p .progress .Verbosef ("%-*s failed to display status: %s" , p .maxRepoName , ts .RepoName , err )
140
- continue
141
+ var fileDiffs []* diff.FileDiff
142
+
143
+ if ts .ChangesetSpec != nil {
144
+ var err error
145
+ fileDiffs , err = diff .ParseMultiFileDiff ([]byte (ts .ChangesetSpec .Commits [0 ].Diff ))
146
+ if err != nil {
147
+ p .progress .Verbosef ("%-*s failed to display status: %s" , p .maxRepoName , ts .RepoName , err )
148
+ continue
149
+ }
141
150
}
142
151
143
- p .progress .Verbosef ("%-*s %s" , p .maxRepoName , ts .RepoName , statusText )
152
+ if p .verbose {
153
+ p .progress .WriteLine (output .Linef ("" , output .StylePending , "%s" , ts .RepoName ))
154
+
155
+ if ts .ChangesetSpec == nil {
156
+ p .progress .Verbosef (" No changes" )
157
+ } else {
158
+ lines , err := verboseDiffSummary (fileDiffs )
159
+ if err != nil {
160
+ p .progress .Verbosef ("%-*s failed to display status: %s" , p .maxRepoName , ts .RepoName , err )
161
+ continue
162
+ }
163
+
164
+ for _ , line := range lines {
165
+ p .progress .Verbose (line )
166
+ }
167
+ }
168
+
169
+ p .progress .Verbose ("" )
170
+ }
144
171
145
172
if idx , ok := p .repoStatusBar [ts .RepoName ]; ok {
146
173
// Log that this task completed, but only if there is no
147
174
// currently executing one in this bar, to avoid flicker.
148
175
if _ , ok := p .statusBarRepo [idx ]; ! ok {
176
+ statusText , err := taskStatusBarText (ts )
177
+ if err != nil {
178
+ p .progress .Verbosef ("%-*s failed to display status: %s" , p .maxRepoName , ts .RepoName , err )
179
+ continue
180
+ }
181
+
149
182
if ts .Err != nil {
150
183
p .progress .StatusBarFailf (idx , statusText )
151
184
} else {
@@ -163,7 +196,7 @@ func (p *campaignProgressPrinter) PrintStatuses(statuses []*campaigns.TaskStatus
163
196
continue
164
197
}
165
198
166
- statusText , err := taskStatusText (ts )
199
+ statusText , err := taskStatusBarText (ts )
167
200
if err != nil {
168
201
p .progress .Verbosef ("%-*s failed to display status: %s" , p .maxRepoName , ts .RepoName , err )
169
202
continue
@@ -181,7 +214,7 @@ type statusTexter interface {
181
214
StatusText () string
182
215
}
183
216
184
- func taskStatusText (ts * campaigns.TaskStatus ) (string , error ) {
217
+ func taskStatusBarText (ts * campaigns.TaskStatus ) (string , error ) {
185
218
var statusText string
186
219
187
220
if ts .IsCompleted () {
@@ -223,3 +256,57 @@ func taskStatusText(ts *campaigns.TaskStatus) (string, error) {
223
256
224
257
return statusText , nil
225
258
}
259
+
260
+ func verboseDiffSummary (fileDiffs []* diff.FileDiff ) ([]string , error ) {
261
+ var (
262
+ lines []string
263
+
264
+ maxFilenameLen int
265
+ sumInsertions int
266
+ sumDeletions int
267
+ )
268
+
269
+ fileStats := make (map [string ]string , len (fileDiffs ))
270
+
271
+ for _ , f := range fileDiffs {
272
+ name := f .NewName
273
+ if name == "/dev/null" {
274
+ name = f .OrigName
275
+ }
276
+
277
+ if len (name ) > maxFilenameLen {
278
+ maxFilenameLen = len (name )
279
+ }
280
+
281
+ stat := f .Stat ()
282
+
283
+ sumInsertions += int (stat .Added ) + int (stat .Changed )
284
+ sumDeletions += int (stat .Deleted ) + int (stat .Changed )
285
+
286
+ num := stat .Added + 2 * stat .Changed + stat .Deleted
287
+
288
+ fileStats [name ] = fmt .Sprintf ("%d %s" , num , diffStatDiagram (stat ))
289
+ }
290
+
291
+ for file , stats := range fileStats {
292
+ lines = append (lines , fmt .Sprintf ("\t %-*s | %s" , maxFilenameLen , file , stats ))
293
+ }
294
+
295
+ var insertionsPlural string
296
+ if sumInsertions != 0 {
297
+ insertionsPlural = "s"
298
+ }
299
+
300
+ var deletionsPlural string
301
+ if sumDeletions != 1 {
302
+ deletionsPlural = "s"
303
+ }
304
+
305
+ lines = append (lines , fmt .Sprintf (" %s, %s, %s" ,
306
+ diffStatDescription (fileDiffs ),
307
+ fmt .Sprintf ("%d insertion%s" , sumInsertions , insertionsPlural ),
308
+ fmt .Sprintf ("%d deletion%s" , sumDeletions , deletionsPlural ),
309
+ ))
310
+
311
+ return lines , nil
312
+ }
0 commit comments