@@ -258,34 +258,53 @@ static void get_correspondences(struct string_list *a, struct string_list *b,
258
258
free (b2a );
259
259
}
260
260
261
- static void output_pair_header (struct strbuf * buf ,
261
+ static void output_pair_header (struct diff_options * diffopt ,
262
+ struct strbuf * buf ,
262
263
struct strbuf * dashes ,
263
264
struct patch_util * a_util ,
264
265
struct patch_util * b_util )
265
266
{
266
267
struct object_id * oid = a_util ? & a_util -> oid : & b_util -> oid ;
267
268
struct commit * commit ;
269
+ char status ;
270
+ const char * color_reset = diff_get_color_opt (diffopt , DIFF_RESET );
271
+ const char * color_old = diff_get_color_opt (diffopt , DIFF_FILE_OLD );
272
+ const char * color_new = diff_get_color_opt (diffopt , DIFF_FILE_NEW );
273
+ const char * color_commit = diff_get_color_opt (diffopt , DIFF_COMMIT );
274
+ const char * color ;
268
275
269
276
if (!dashes -> len )
270
277
strbuf_addchars (dashes , '-' ,
271
278
strlen (find_unique_abbrev (oid ,
272
279
DEFAULT_ABBREV )));
273
280
281
+ if (!b_util ) {
282
+ color = color_old ;
283
+ status = '<' ;
284
+ } else if (!a_util ) {
285
+ color = color_new ;
286
+ status = '>' ;
287
+ } else if (strcmp (a_util -> patch , b_util -> patch )) {
288
+ color = color_commit ;
289
+ status = '!' ;
290
+ } else {
291
+ color = color_commit ;
292
+ status = '=' ;
293
+ }
294
+
274
295
strbuf_reset (buf );
296
+ strbuf_addstr (buf , status == '!' ? color_old : color );
275
297
if (!a_util )
276
298
strbuf_addf (buf , "-: %s " , dashes -> buf );
277
299
else
278
300
strbuf_addf (buf , "%d: %s " , a_util -> i + 1 ,
279
301
find_unique_abbrev (& a_util -> oid , DEFAULT_ABBREV ));
280
302
281
- if (!a_util )
282
- strbuf_addch (buf , '>' );
283
- else if (!b_util )
284
- strbuf_addch (buf , '<' );
285
- else if (strcmp (a_util -> patch , b_util -> patch ))
286
- strbuf_addch (buf , '!' );
287
- else
288
- strbuf_addch (buf , '=' );
303
+ if (status == '!' )
304
+ strbuf_addf (buf , "%s%s" , color_reset , color );
305
+ strbuf_addch (buf , status );
306
+ if (status == '!' )
307
+ strbuf_addf (buf , "%s%s" , color_reset , color_new );
289
308
290
309
if (!b_util )
291
310
strbuf_addf (buf , " -: %s" , dashes -> buf );
@@ -295,10 +314,13 @@ static void output_pair_header(struct strbuf *buf,
295
314
296
315
commit = lookup_commit_reference (the_repository , oid );
297
316
if (commit ) {
317
+ if (status == '!' )
318
+ strbuf_addf (buf , "%s%s" , color_reset , color );
319
+
298
320
strbuf_addch (buf , ' ' );
299
321
pp_commit_easy (CMIT_FMT_ONELINE , commit , buf );
300
322
}
301
- strbuf_addch (buf , '\n' );
323
+ strbuf_addf (buf , "%s\n" , color_reset );
302
324
303
325
fwrite (buf -> buf , buf -> len , 1 , stdout );
304
326
}
@@ -356,21 +378,24 @@ static void output(struct string_list *a, struct string_list *b,
356
378
357
379
/* Show unmatched LHS commit whose predecessors were shown. */
358
380
if (i < a -> nr && a_util -> matching < 0 ) {
359
- output_pair_header (& buf , & dashes , a_util , NULL );
381
+ output_pair_header (diffopt ,
382
+ & buf , & dashes , a_util , NULL );
360
383
i ++ ;
361
384
continue ;
362
385
}
363
386
364
387
/* Show unmatched RHS commits. */
365
388
while (j < b -> nr && b_util -> matching < 0 ) {
366
- output_pair_header (& buf , & dashes , NULL , b_util );
389
+ output_pair_header (diffopt ,
390
+ & buf , & dashes , NULL , b_util );
367
391
b_util = ++ j < b -> nr ? b -> items [j ].util : NULL ;
368
392
}
369
393
370
394
/* Show matching LHS/RHS pair. */
371
395
if (j < b -> nr ) {
372
396
a_util = a -> items [b_util -> matching ].util ;
373
- output_pair_header (& buf , & dashes , a_util , b_util );
397
+ output_pair_header (diffopt ,
398
+ & buf , & dashes , a_util , b_util );
374
399
if (!(diffopt -> output_format & DIFF_FORMAT_NO_OUTPUT ))
375
400
patch_diff (a -> items [b_util -> matching ].string ,
376
401
b -> items [j ].string , diffopt );
0 commit comments