@@ -254,7 +254,8 @@ 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 diff_options * diffopt , struct strbuf * buf ,
257
+ static void output_pair_header (struct diff_options * diffopt , int patch_no_width ,
258
+ struct strbuf * buf ,
258
259
struct patch_util * a_util ,
259
260
struct patch_util * b_util )
260
261
{
@@ -293,9 +294,9 @@ static void output_pair_header(struct diff_options *diffopt, struct strbuf *buf,
293
294
strbuf_reset (buf );
294
295
strbuf_addstr (buf , status == '!' ? color_old : color );
295
296
if (!a_util )
296
- strbuf_addf (buf , "- : %s " , dashes );
297
+ strbuf_addf (buf , "%*s : %s " , patch_no_width , "- " , dashes );
297
298
else
298
- strbuf_addf (buf , "%d: %s " , a_util -> i + 1 ,
299
+ strbuf_addf (buf , "%* d: %s " , patch_no_width , a_util -> i + 1 ,
299
300
find_unique_abbrev (a_util -> oid .hash ,
300
301
DEFAULT_ABBREV ));
301
302
@@ -306,9 +307,9 @@ static void output_pair_header(struct diff_options *diffopt, struct strbuf *buf,
306
307
strbuf_addf (buf , "%s%s" , color_reset , color_new );
307
308
308
309
if (!b_util )
309
- strbuf_addf (buf , " - : %s" , dashes );
310
+ strbuf_addf (buf , " %*s : %s" , patch_no_width , "- " , dashes );
310
311
else
311
- strbuf_addf (buf , " %d: %s" , b_util -> i + 1 ,
312
+ strbuf_addf (buf , " %* d: %s" , patch_no_width , b_util -> i + 1 ,
312
313
find_unique_abbrev (b_util -> oid .hash ,
313
314
DEFAULT_ABBREV ));
314
315
@@ -362,6 +363,7 @@ static void output(struct string_list *a, struct string_list *b,
362
363
struct diff_options * diffopt )
363
364
{
364
365
struct strbuf buf = STRBUF_INIT ;
366
+ int patch_no_width = decimal_width (1 + (a -> nr > b -> nr ? a -> nr : b -> nr ));
365
367
int i = 0 , j = 0 ;
366
368
367
369
/*
@@ -383,21 +385,24 @@ static void output(struct string_list *a, struct string_list *b,
383
385
384
386
/* Show unmatched LHS commit whose predecessors were shown. */
385
387
if (i < a -> nr && a_util -> matching < 0 ) {
386
- output_pair_header (diffopt , & buf , a_util , NULL );
388
+ output_pair_header (diffopt , patch_no_width , & buf ,
389
+ a_util , NULL );
387
390
i ++ ;
388
391
continue ;
389
392
}
390
393
391
394
/* Show unmatched RHS commits. */
392
395
while (j < b -> nr && b_util -> matching < 0 ) {
393
- output_pair_header (diffopt , & buf , NULL , b_util );
396
+ output_pair_header (diffopt , patch_no_width , & buf ,
397
+ NULL , b_util );
394
398
b_util = ++ j < b -> nr ? b -> items [j ].util : NULL ;
395
399
}
396
400
397
401
/* Show matching LHS/RHS pair. */
398
402
if (j < b -> nr ) {
399
403
a_util = a -> items [b_util -> matching ].util ;
400
- output_pair_header (diffopt , & buf , a_util , b_util );
404
+ output_pair_header (diffopt , patch_no_width , & buf ,
405
+ a_util , b_util );
401
406
if (!(diffopt -> output_format & DIFF_FORMAT_NO_OUTPUT ))
402
407
patch_diff (a -> items [b_util -> matching ].string ,
403
408
b -> items [j ].string , diffopt );
0 commit comments