| 5672 | } |
| 5673 | |
| 5674 | void append_signoff(struct strbuf *msgbuf, size_t ignore_footer, unsigned flag) |
| 5675 | { |
| 5676 | unsigned no_dup_sob = flag & APPEND_SIGNOFF_DEDUP; |
| 5677 | struct strbuf sob = STRBUF_INIT; |
| 5678 | int has_footer; |
| 5679 | |
| 5680 | strbuf_addstr(&sob, sign_off_header); |
| 5681 | strbuf_addstr(&sob, fmt_name(WANT_COMMITTER_IDENT)); |
| 5682 | strbuf_addch(&sob, '\n'); |
| 5683 | |
| 5684 | if (!ignore_footer) |
| 5685 | strbuf_complete_line(msgbuf); |
| 5686 | |
| 5687 | /* |
| 5688 | * If the whole message buffer is equal to the sob, pretend that we |
| 5689 | * found a conforming footer with a matching sob |
| 5690 | */ |
| 5691 | if (msgbuf->len - ignore_footer == sob.len && |
| 5692 | !strncmp(msgbuf->buf, sob.buf, sob.len)) |
| 5693 | has_footer = 3; |
| 5694 | else |
| 5695 | has_footer = has_conforming_footer(msgbuf, &sob, ignore_footer); |
| 5696 | |
| 5697 | if (!has_footer) { |
| 5698 | const char *append_newlines = NULL; |
| 5699 | size_t len = msgbuf->len - ignore_footer; |
| 5700 | |
| 5701 | if (!len) { |
| 5702 | /* |
| 5703 | * The buffer is completely empty. Leave foom for |
| 5704 | * the title and body to be filled in by the user. |
| 5705 | */ |
| 5706 | append_newlines = "\n\n"; |
| 5707 | } else if (len == 1) { |
| 5708 | /* |
| 5709 | * Buffer contains a single newline. Add another |
| 5710 | * so that we leave room for the title and body. |
| 5711 | */ |
| 5712 | append_newlines = "\n"; |
| 5713 | } else if (msgbuf->buf[len - 2] != '\n') { |
| 5714 | /* |
| 5715 | * Buffer ends with a single newline. Add another |
| 5716 | * so that there is an empty line between the message |
| 5717 | * body and the sob. |
| 5718 | */ |
| 5719 | append_newlines = "\n"; |
| 5720 | } /* else, the buffer already ends with two newlines. */ |
| 5721 | |
| 5722 | if (append_newlines) |
| 5723 | strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0, |
| 5724 | append_newlines, strlen(append_newlines)); |
| 5725 | } |
| 5726 | |
| 5727 | if (has_footer != 3 && (!no_dup_sob || has_footer != 2)) |
| 5728 | strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0, |
| 5729 | sob.buf, sob.len); |
| 5730 | |
| 5731 | strbuf_release(&sob); |
no test coverage detected