10
10
static FILE * cmitmsg , * patchfile , * fin , * fout ;
11
11
12
12
static int keep_subject ;
13
+ static int keep_non_patch_brackets_in_subject ;
13
14
static const char * metainfo_charset ;
14
15
static struct strbuf line = STRBUF_INIT ;
15
16
static struct strbuf name = STRBUF_INIT ;
@@ -221,35 +222,41 @@ static int is_multipart_boundary(const struct strbuf *line)
221
222
222
223
static void cleanup_subject (struct strbuf * subject )
223
224
{
224
- char * pos ;
225
- size_t remove ;
226
- while (subject -> len ) {
227
- switch (* subject -> buf ) {
225
+ size_t at = 0 ;
226
+
227
+ while (at < subject -> len ) {
228
+ char * pos ;
229
+ size_t remove ;
230
+
231
+ switch (subject -> buf [at ]) {
228
232
case 'r' : case 'R' :
229
- if (subject -> len <= 3 )
233
+ if (subject -> len <= at + 3 )
230
234
break ;
231
- if (!memcmp (subject -> buf + 1 , "e:" , 2 )) {
232
- strbuf_remove (subject , 0 , 3 );
235
+ if (!memcmp (subject -> buf + at + 1 , "e:" , 2 )) {
236
+ strbuf_remove (subject , at , 3 );
233
237
continue ;
234
238
}
239
+ at ++ ;
235
240
break ;
236
241
case ' ' : case '\t' : case ':' :
237
- strbuf_remove (subject , 0 , 1 );
242
+ strbuf_remove (subject , at , 1 );
238
243
continue ;
239
244
case '[' :
240
- if ((pos = strchr (subject -> buf , ']' ))) {
241
- remove = pos - subject -> buf ;
242
- if (remove <= (subject -> len - remove ) * 2 ) {
243
- strbuf_remove (subject , 0 , remove + 1 );
244
- continue ;
245
- }
246
- } else
247
- strbuf_remove (subject , 0 , 1 );
248
- break ;
245
+ pos = strchr (subject -> buf + at , ']' );
246
+ if (!pos )
247
+ break ;
248
+ remove = pos - subject -> buf + at + 1 ;
249
+ if (!keep_non_patch_brackets_in_subject ||
250
+ (7 <= remove &&
251
+ memmem (subject -> buf + at , remove , "PATCH" , 5 )))
252
+ strbuf_remove (subject , at , remove );
253
+ else
254
+ at += remove ;
255
+ continue ;
249
256
}
250
- strbuf_trim (subject );
251
- return ;
257
+ break ;
252
258
}
259
+ strbuf_trim (subject );
253
260
}
254
261
255
262
static void cleanup_space (struct strbuf * sb )
@@ -1014,7 +1021,7 @@ static int git_mailinfo_config(const char *var, const char *value, void *unused)
1014
1021
}
1015
1022
1016
1023
static const char mailinfo_usage [] =
1017
- "git mailinfo [-k] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] msg patch < mail >info" ;
1024
+ "git mailinfo [-k|-b ] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] msg patch < mail >info" ;
1018
1025
1019
1026
int cmd_mailinfo (int argc , const char * * argv , const char * prefix )
1020
1027
{
@@ -1031,6 +1038,8 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
1031
1038
while (1 < argc && argv [1 ][0 ] == '-' ) {
1032
1039
if (!strcmp (argv [1 ], "-k" ))
1033
1040
keep_subject = 1 ;
1041
+ else if (!strcmp (argv [1 ], "-b" ))
1042
+ keep_non_patch_brackets_in_subject = 1 ;
1034
1043
else if (!strcmp (argv [1 ], "-u" ))
1035
1044
metainfo_charset = def_charset ;
1036
1045
else if (!strcmp (argv [1 ], "-n" ))
0 commit comments