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