@@ -776,13 +776,21 @@ enum flush_type {
776776 flush_both
777777};
778778
779+ enum trunc_type {
780+ trunc_none ,
781+ trunc_left ,
782+ trunc_middle ,
783+ trunc_right
784+ };
785+
779786struct format_commit_context {
780787 const struct commit * commit ;
781788 const struct pretty_print_context * pretty_ctx ;
782789 unsigned commit_header_parsed :1 ;
783790 unsigned commit_message_parsed :1 ;
784791 struct signature_check signature_check ;
785792 enum flush_type flush_type ;
793+ enum trunc_type truncate ;
786794 char * message ;
787795 char * commit_encoding ;
788796 size_t width , indent1 , indent2 ;
@@ -1033,7 +1041,7 @@ static size_t parse_padding_placeholder(struct strbuf *sb,
10331041
10341042 if (* ch == '(' ) {
10351043 const char * start = ch + 1 ;
1036- const char * end = strchr (start , ')' );
1044+ const char * end = start + strcspn (start , ",)" );
10371045 char * next ;
10381046 int width ;
10391047 if (!end || end == start )
@@ -1043,6 +1051,23 @@ static size_t parse_padding_placeholder(struct strbuf *sb,
10431051 return 0 ;
10441052 c -> padding = to_column ? - width : width ;
10451053 c -> flush_type = flush_type ;
1054+
1055+ if (* end == ',' ) {
1056+ start = end + 1 ;
1057+ end = strchr (start , ')' );
1058+ if (!end || end == start )
1059+ return 0 ;
1060+ if (!prefixcmp (start , "trunc)" ))
1061+ c -> truncate = trunc_right ;
1062+ else if (!prefixcmp (start , "ltrunc)" ))
1063+ c -> truncate = trunc_left ;
1064+ else if (!prefixcmp (start , "mtrunc)" ))
1065+ c -> truncate = trunc_middle ;
1066+ else
1067+ return 0 ;
1068+ } else
1069+ c -> truncate = trunc_none ;
1070+
10461071 return end - placeholder + 1 ;
10471072 }
10481073 return 0 ;
@@ -1309,9 +1334,29 @@ static size_t format_and_pad_commit(struct strbuf *sb, /* in UTF-8 */
13091334 total_consumed ++ ;
13101335 }
13111336 len = utf8_strnwidth (local_sb .buf , -1 , 1 );
1312- if (len > padding )
1337+ if (len > padding ) {
1338+ switch (c -> truncate ) {
1339+ case trunc_left :
1340+ strbuf_utf8_replace (& local_sb ,
1341+ 0 , len - (padding - 2 ),
1342+ ".." );
1343+ break ;
1344+ case trunc_middle :
1345+ strbuf_utf8_replace (& local_sb ,
1346+ padding / 2 - 1 ,
1347+ len - (padding - 2 ),
1348+ ".." );
1349+ break ;
1350+ case trunc_right :
1351+ strbuf_utf8_replace (& local_sb ,
1352+ padding - 2 , len - (padding - 2 ),
1353+ ".." );
1354+ break ;
1355+ case trunc_none :
1356+ break ;
1357+ }
13131358 strbuf_addstr (sb , local_sb .buf );
1314- else {
1359+ } else {
13151360 int sb_len = sb -> len , offset = 0 ;
13161361 if (c -> flush_type == flush_left )
13171362 offset = padding - len ;
0 commit comments