static void format_sanitized_subject(struct strbuf *sb, const char *msg) { size_t trimlen; size_t start_len = sb->len; int space = 2; for (; *msg && *msg != '\n'; msg++) { if (istitlechar(*msg)) { if (space == 1) strbuf_addch(sb, '-'); space = 0; strbuf_addch(sb, *msg); if (*msg == '.') while (*(msg+1) == '.') msg++; } else space |= 1; } /* trim any trailing '.' or '-' characters */ trimlen = 0; while (sb->len - trimlen > start_len && (sb->buf[sb->len - 1 - trimlen] == '.' || sb->buf[sb->len - 1 - trimlen] == '-')) trimlen++; strbuf_remove(sb, sb->len - trimlen, trimlen); }
static const char *get_oneline_for_filename(struct commit *commit, int keep_subject) { static char filename[PATH_MAX]; char *sol; int len = 0; int suffix_len = strlen(fmt_patch_suffix) + 1; sol = strstr(commit->buffer, "\n\n"); if (!sol) filename[0] = '\0'; else { int j, space = 0; sol += 2; /* strip [PATCH] or [PATCH blabla] */ if (!keep_subject && !prefixcmp(sol, "[PATCH")) { char *eos = strchr(sol + 6, ']'); if (eos) { while (isspace(*eos)) eos++; sol = eos; } } for (j = 0; j < FORMAT_PATCH_NAME_MAX - suffix_len - 5 && len < sizeof(filename) - suffix_len && sol[j] && sol[j] != '\n'; j++) { if (istitlechar(sol[j])) { if (space) { filename[len++] = '-'; space = 0; } filename[len++] = sol[j]; if (sol[j] == '.') while (sol[j + 1] == '.') j++; } else space = 1; } while (filename[len - 1] == '.' || filename[len - 1] == '-') len--; filename[len] = '\0'; } return filename; }