MCPcopy Create free account
hub / github.com/git/git / cleanup_subject

Function cleanup_subject

mailinfo.c:304–352  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

302}
303
304static void cleanup_subject(struct mailinfo *mi, struct strbuf *subject)
305{
306 size_t at = 0;
307
308 while (at < subject->len) {
309 char *pos;
310 size_t remove;
311
312 switch (subject->buf[at]) {
313 case 'r': case 'R':
314 if (subject->len <= at + 3)
315 break;
316 if ((subject->buf[at + 1] == 'e' ||
317 subject->buf[at + 1] == 'E') &&
318 subject->buf[at + 2] == ':') {
319 strbuf_remove(subject, at, 3);
320 continue;
321 }
322 at++;
323 break;
324 case ' ': case '\t': case ':':
325 strbuf_remove(subject, at, 1);
326 continue;
327 case '[':
328 pos = strchr(subject->buf + at, ']');
329 if (!pos)
330 break;
331 remove = pos - (subject->buf + at) + 1;
332 if (!mi->keep_non_patch_brackets_in_subject ||
333 (7 <= remove &&
334 memmem(subject->buf + at, remove, "PATCH", 5)))
335 strbuf_remove(subject, at, remove);
336 else {
337 at += remove;
338 /*
339 * If the input had a space after the ], keep
340 * it. We don't bother with finding the end of
341 * the space, since we later normalize it
342 * anyway.
343 */
344 if (isspace(subject->buf[at]))
345 at += 1;
346 }
347 continue;
348 }
349 break;
350 }
351 strbuf_trim(subject);
352}
353
354static const char * const header[] = {
355 "From", "Subject", "Date",

Callers 1

handle_infoFunction · 0.70

Calls 2

strbuf_removeFunction · 0.85
strbuf_trimFunction · 0.85

Tested by

no test coverage detected