summaryrefslogtreecommitdiff
path: root/builtin/mailinfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/mailinfo.c')
-rw-r--r--builtin/mailinfo.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index 4a8c704..11c8ee0 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
@@ -12,7 +12,6 @@
struct mailinfo {
FILE *input;
FILE *output;
- FILE *cmitmsg;
FILE *patchfile;
struct strbuf name;
@@ -36,6 +35,8 @@ struct mailinfo {
int header_stage; /* still checking in-body headers? */
struct strbuf **p_hdr_data;
struct strbuf **s_hdr_data;
+
+ struct strbuf log_message;
};
static void cleanup_space(struct strbuf *sb)
@@ -676,10 +677,8 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
if (mi->use_scissors && is_scissors_line(line)) {
int i;
- if (fseek(mi->cmitmsg, 0L, SEEK_SET))
- die_errno("Could not rewind output message file");
- if (ftruncate(fileno(mi->cmitmsg), 0))
- die_errno("Could not truncate output message file at scissors");
+
+ strbuf_setlen(&mi->log_message, 0);
mi->header_stage = 1;
/*
@@ -696,13 +695,12 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
if (patchbreak(line)) {
if (mi->message_id)
- fprintf(mi->cmitmsg, "Message-Id: %s\n", mi->message_id);
- fclose(mi->cmitmsg);
- mi->cmitmsg = NULL;
+ strbuf_addf(&mi->log_message,
+ "Message-Id: %s\n", mi->message_id);
return 1;
}
- fputs(line->buf, mi->cmitmsg);
+ strbuf_addbuf(&mi->log_message, line);
return 0;
}
@@ -968,18 +966,19 @@ static void handle_info(struct mailinfo *mi)
static int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
{
+ FILE *cmitmsg;
int peek;
struct strbuf line = STRBUF_INIT;
- mi->cmitmsg = fopen(msg, "w");
- if (!mi->cmitmsg) {
+ cmitmsg = fopen(msg, "w");
+ if (!cmitmsg) {
perror(msg);
return -1;
}
mi->patchfile = fopen(patch, "w");
if (!mi->patchfile) {
perror(patch);
- fclose(mi->cmitmsg);
+ fclose(cmitmsg);
return -1;
}
@@ -996,6 +995,8 @@ static int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
check_header(mi, &line, mi->p_hdr_data, 1);
handle_body(mi, &line);
+ fwrite(mi->log_message.buf, 1, mi->log_message.len, cmitmsg);
+ fclose(cmitmsg);
fclose(mi->patchfile);
handle_info(mi);
@@ -1023,6 +1024,7 @@ static void setup_mailinfo(struct mailinfo *mi)
strbuf_init(&mi->name, 0);
strbuf_init(&mi->email, 0);
strbuf_init(&mi->charset, 0);
+ strbuf_init(&mi->log_message, 0);
mi->header_stage = 1;
mi->use_inbody_headers = 1;
mi->content_top = mi->content;
@@ -1049,6 +1051,8 @@ static void clear_mailinfo(struct mailinfo *mi)
free(*(mi->content_top));
mi->content_top--;
}
+
+ strbuf_release(&mi->log_message);
}
static const char mailinfo_usage[] =