mailinfo: handle_commit_msg() shouldn't be called after finding patchbreak
authorJunio C Hamano <gitster@pobox.com>
Wed, 14 Oct 2015 23:16:33 +0000 (16:16 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 21 Oct 2015 22:57:17 +0000 (15:57 -0700)
There is a strange "if (!mi->cmitmsg) return 0" at the very beginning
of handle_commit_msg(), but the condition should never trigger, because:

* The only place cmitmsg is set to NULL is after this function sees
a patch break, closes the FILE * to write the commit log message
and returns 1. This function returns non-zero only from that
codepath.

* The caller of this function, upon seeing a non-zero return,
increments filter_stage, starts treating the input as patch text
and will never call handle_commit_msg() again.

Replace it with an assert(!mi->filter_stage) to ensure the above
observation will stay to be true.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/mailinfo.c
index 93043255ad69842840565186751cbc08aac7b4f9..4a8c704c8a255ae5e1828cb7cb61364eadaf20a1 100644 (file)
@@ -654,8 +654,7 @@ static int is_scissors_line(const struct strbuf *line)
 
 static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
 {
-       if (!mi->cmitmsg)
-               return 0;
+       assert(!mi->filter_stage);
 
        if (mi->header_stage) {
                if (!line->len || (line->len == 1 && line->buf[0] == '\n'))