@@ -776,13 +776,21 @@ enum flush_type {
776
776
flush_both
777
777
};
778
778
779
+ enum trunc_type {
780
+ trunc_none ,
781
+ trunc_left ,
782
+ trunc_middle ,
783
+ trunc_right
784
+ };
785
+
779
786
struct format_commit_context {
780
787
const struct commit * commit ;
781
788
const struct pretty_print_context * pretty_ctx ;
782
789
unsigned commit_header_parsed :1 ;
783
790
unsigned commit_message_parsed :1 ;
784
791
struct signature_check signature_check ;
785
792
enum flush_type flush_type ;
793
+ enum trunc_type truncate ;
786
794
char * message ;
787
795
char * commit_encoding ;
788
796
size_t width , indent1 , indent2 ;
@@ -1033,7 +1041,7 @@ static size_t parse_padding_placeholder(struct strbuf *sb,
1033
1041
1034
1042
if (* ch == '(' ) {
1035
1043
const char * start = ch + 1 ;
1036
- const char * end = strchr (start , ')' );
1044
+ const char * end = start + strcspn (start , ",)" );
1037
1045
char * next ;
1038
1046
int width ;
1039
1047
if (!end || end == start )
@@ -1043,6 +1051,23 @@ static size_t parse_padding_placeholder(struct strbuf *sb,
1043
1051
return 0 ;
1044
1052
c -> padding = to_column ? - width : width ;
1045
1053
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
+
1046
1071
return end - placeholder + 1 ;
1047
1072
}
1048
1073
return 0 ;
@@ -1309,9 +1334,29 @@ static size_t format_and_pad_commit(struct strbuf *sb, /* in UTF-8 */
1309
1334
total_consumed ++ ;
1310
1335
}
1311
1336
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
+ }
1313
1358
strbuf_addstr (sb , local_sb .buf );
1314
- else {
1359
+ } else {
1315
1360
int sb_len = sb -> len , offset = 0 ;
1316
1361
if (c -> flush_type == flush_left )
1317
1362
offset = padding - len ;
0 commit comments