* Comment out any un-commented commit messages, updating the message comments * to say they will be skipped but do not comment out the empty lines that * surround commit messages and their comments. */
| 1942 | * surround commit messages and their comments. |
| 1943 | */ |
| 1944 | static void update_squash_message_for_fixup(struct strbuf *msg) |
| 1945 | { |
| 1946 | void (*copy_lines)(struct strbuf *, const void *, size_t) = strbuf_add; |
| 1947 | struct strbuf buf1 = STRBUF_INIT, buf2 = STRBUF_INIT; |
| 1948 | const char *s, *start; |
| 1949 | char *orig_msg; |
| 1950 | size_t orig_msg_len; |
| 1951 | int i = 1; |
| 1952 | |
| 1953 | strbuf_add_commented_lines(&buf1, _(first_commit_msg_str), |
| 1954 | strlen(_(first_commit_msg_str)), |
| 1955 | comment_line_str); |
| 1956 | strbuf_add_commented_lines(&buf2, _(skip_first_commit_msg_str), |
| 1957 | strlen(_(skip_first_commit_msg_str)), |
| 1958 | comment_line_str); |
| 1959 | s = start = orig_msg = strbuf_detach(msg, &orig_msg_len); |
| 1960 | while (s) { |
| 1961 | const char *next; |
| 1962 | size_t off; |
| 1963 | if (skip_prefix(s, buf1.buf, &next)) { |
| 1964 | /* |
| 1965 | * Copy the last message, preserving the blank line |
| 1966 | * preceding the current line |
| 1967 | */ |
| 1968 | off = (s > start + 1 && s[-2] == '\n') ? 1 : 0; |
| 1969 | copy_lines(msg, start, s - start - off); |
| 1970 | if (off) |
| 1971 | strbuf_addch(msg, '\n'); |
| 1972 | /* |
| 1973 | * The next message needs to be commented out but the |
| 1974 | * message header is already commented out so just copy |
| 1975 | * it and the blank line that follows it. |
| 1976 | */ |
| 1977 | strbuf_addbuf(msg, &buf2); |
| 1978 | if (*next == '\n') |
| 1979 | strbuf_addch(msg, *next++); |
| 1980 | start = s = next; |
| 1981 | copy_lines = add_commented_lines; |
| 1982 | update_comment_bufs(&buf1, &buf2, ++i); |
| 1983 | } else if (skip_prefix(s, buf2.buf, &next)) { |
| 1984 | off = (s > start + 1 && s[-2] == '\n') ? 1 : 0; |
| 1985 | copy_lines(msg, start, s - start - off); |
| 1986 | start = s - off; |
| 1987 | s = next; |
| 1988 | copy_lines = strbuf_add; |
| 1989 | update_comment_bufs(&buf1, &buf2, ++i); |
| 1990 | } else { |
| 1991 | s = strchr(s, '\n'); |
| 1992 | if (s) |
| 1993 | s++; |
| 1994 | } |
| 1995 | } |
| 1996 | copy_lines(msg, start, orig_msg_len - (start - orig_msg)); |
| 1997 | free(orig_msg); |
| 1998 | strbuf_release(&buf1); |
| 1999 | strbuf_release(&buf2); |
| 2000 | } |
| 2001 |
no test coverage detected