@@ -426,42 +426,36 @@ static int is_empty_line(const char *line, int len)
426426 return !len ;
427427}
428428
429- static int add_parent_info (enum cmit_fmt fmt , char * buf , const char * line , int parents , int abbrev )
429+ static int add_merge_info (enum cmit_fmt fmt , char * buf , const struct commit * commit , int abbrev )
430430{
431- int offset = 0 ;
432- unsigned char sha1 [ 20 ] ;
431+ struct commit_list * parent = commit -> parents ;
432+ int offset ;
433433
434- if (fmt == CMIT_FMT_ONELINE )
435- return offset ;
436- switch (parents ) {
437- case 1 :
438- break ;
439- case 2 :
440- /* Go back to the previous line: 40 characters of previous parent, and one '\n' */
441- if (abbrev && !get_sha1_hex (line - 41 , sha1 ))
442- offset = sprintf (buf , "Merge: %s\n" ,
443- find_unique_abbrev (sha1 , abbrev ));
444- else
445- offset = sprintf (buf , "Merge: %.40s\n" , line - 41 );
446- /* Fallthrough */
447- default :
448- /* Replace the previous '\n' with a space */
449- buf [offset - 1 ] = ' ' ;
450- if (abbrev && !get_sha1_hex (line + 7 , sha1 ))
451- offset += sprintf (buf + offset , "%s\n" ,
452- find_unique_abbrev (sha1 , abbrev ));
453- else
454- offset += sprintf (buf + offset , "%.40s\n" , line + 7 );
434+ if ((fmt == CMIT_FMT_ONELINE ) || !parent || !parent -> next )
435+ return 0 ;
436+
437+ offset = sprintf (buf , "Merge:" );
438+
439+ while (parent ) {
440+ struct commit * p = parent -> item ;
441+ parent = parent -> next ;
442+
443+ offset += sprintf (buf + offset ,
444+ abbrev ? " %s..." : " %s" ,
445+ abbrev
446+ ? find_unique_abbrev (p -> object .sha1 , abbrev )
447+ : sha1_to_hex (p -> object .sha1 ));
455448 }
449+ buf [offset ++ ] = '\n' ;
456450 return offset ;
457451}
458452
459453unsigned long pretty_print_commit (enum cmit_fmt fmt , const struct commit * commit , unsigned long len , char * buf , unsigned long space , int abbrev )
460454{
461455 int hdr = 1 , body = 0 ;
462456 unsigned long offset = 0 ;
463- int parents = 0 ;
464457 int indent = (fmt == CMIT_FMT_ONELINE ) ? 0 : 4 ;
458+ int parents_shown = 0 ;
465459 const char * msg = commit -> buffer ;
466460
467461 for (;;) {
@@ -498,9 +492,15 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
498492 if (!memcmp (line , "parent " , 7 )) {
499493 if (linelen != 48 )
500494 die ("bad parent line in commit" );
501- offset += add_parent_info ( fmt , buf + offset , line , ++ parents , abbrev ) ;
495+ continue ;
502496 }
503497
498+ if (!parents_shown ) {
499+ offset += add_merge_info (fmt , buf + offset ,
500+ commit , abbrev );
501+ parents_shown = 1 ;
502+ continue ;
503+ }
504504 /*
505505 * MEDIUM == DEFAULT shows only author with dates.
506506 * FULL shows both authors but not dates.
0 commit comments