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