Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
mailinfo: move global "FILE *fin, *fout" to struct mailinfo
author
Junio C Hamano
<gitster@pobox.com>
Wed, 14 Oct 2015 22:40:04 +0000
(15:40 -0700)
committer
Junio C Hamano
<gitster@pobox.com>
Wed, 21 Oct 2015 22:39:01 +0000
(15:39 -0700)
This requires us to pass "struct mailinfo" to more functions
throughout the codepath that read input lines. Incidentally,
later steps are helped by this patch passing the struct to
more callchains.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/mailinfo.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
849106d
)
diff --git
a/builtin/mailinfo.c
b/builtin/mailinfo.c
index a219cbcc597c7e34cd6bf44a1e3985b11e32eecf..e2979e0c7661ebb938b6cd14a870bef023c5fdd5 100644
(file)
--- a/
builtin/mailinfo.c
+++ b/
builtin/mailinfo.c
@@
-7,11
+7,14
@@
#include "utf8.h"
#include "strbuf.h"
#include "utf8.h"
#include "strbuf.h"
-static FILE *cmitmsg, *patchfile
, *fin, *fout
;
+static FILE *cmitmsg, *patchfile;
static const char *metainfo_charset;
struct mailinfo {
static const char *metainfo_charset;
struct mailinfo {
+ FILE *input;
+ FILE *output;
+
struct strbuf name;
struct strbuf email;
int keep_subject;
struct strbuf name;
struct strbuf email;
int keep_subject;
@@
-788,16
+791,17
@@
static int read_one_header_line(struct strbuf *line, FILE *in)
return 1;
}
return 1;
}
-static int find_boundary(struct strbuf *line)
+static int find_boundary(struct
mailinfo *mi, struct
strbuf *line)
{
{
- while (!strbuf_getline(line,
fin
, '\n')) {
+ while (!strbuf_getline(line,
mi->input
, '\n')) {
if (*content_top && is_multipart_boundary(line))
return 1;
}
return 0;
}
if (*content_top && is_multipart_boundary(line))
return 1;
}
return 0;
}
-static int handle_boundary(struct strbuf *line, int *filter_stage, int *header_stage)
+static int handle_boundary(struct mailinfo *mi, struct strbuf *line,
+ int *filter_stage, int *header_stage)
{
struct strbuf newline = STRBUF_INIT;
{
struct strbuf newline = STRBUF_INIT;
@@
-823,7
+827,7
@@
static int handle_boundary(struct strbuf *line, int *filter_stage, int *header_s
strbuf_release(&newline);
/* skip to the next boundary */
strbuf_release(&newline);
/* skip to the next boundary */
- if (!find_boundary(line))
+ if (!find_boundary(
mi,
line))
return 0;
goto again;
}
return 0;
goto again;
}
@@
-833,18
+837,18
@@
static int handle_boundary(struct strbuf *line, int *filter_stage, int *header_s
strbuf_reset(&charset);
/* slurp in this section's info */
strbuf_reset(&charset);
/* slurp in this section's info */
- while (read_one_header_line(line,
fin
))
+ while (read_one_header_line(line,
mi->input
))
check_header(line, p_hdr_data, 0);
strbuf_release(&newline);
/* replenish line */
check_header(line, p_hdr_data, 0);
strbuf_release(&newline);
/* replenish line */
- if (strbuf_getline(line,
fin
, '\n'))
+ if (strbuf_getline(line,
mi->input
, '\n'))
return 0;
strbuf_addch(line, '\n');
return 1;
}
return 0;
strbuf_addch(line, '\n');
return 1;
}
-static void handle_body(struct strbuf *line)
+static void handle_body(struct
mailinfo *mi, struct
strbuf *line)
{
struct strbuf prev = STRBUF_INIT;
int filter_stage = 0;
{
struct strbuf prev = STRBUF_INIT;
int filter_stage = 0;
@@
-852,7
+856,7
@@
static void handle_body(struct strbuf *line)
/* Skip up to the first boundary */
if (*content_top) {
/* Skip up to the first boundary */
if (*content_top) {
- if (!find_boundary(line))
+ if (!find_boundary(
mi,
line))
goto handle_body_out;
}
goto handle_body_out;
}
@@
-864,7
+868,7
@@
static void handle_body(struct strbuf *line)
handle_filter(&prev, &filter_stage, &header_stage);
strbuf_reset(&prev);
}
handle_filter(&prev, &filter_stage, &header_stage);
strbuf_reset(&prev);
}
- if (!handle_boundary(line, &filter_stage, &header_stage))
+ if (!handle_boundary(
mi,
line, &filter_stage, &header_stage))
goto handle_body_out;
}
goto handle_body_out;
}
@@
-907,7
+911,7
@@
static void handle_body(struct strbuf *line)
handle_filter(line, &filter_stage, &header_stage);
}
handle_filter(line, &filter_stage, &header_stage);
}
- } while (!strbuf_getwholeline(line,
fin
, '\n'));
+ } while (!strbuf_getwholeline(line,
mi->input
, '\n'));
handle_body_out:
strbuf_release(&prev);
handle_body_out:
strbuf_release(&prev);
@@
-949,29
+953,25
@@
static void handle_info(struct mailinfo *mi)
cleanup_subject(mi, hdr);
cleanup_space(hdr);
}
cleanup_subject(mi, hdr);
cleanup_space(hdr);
}
- output_header_lines(
fo
ut, "Subject", hdr);
+ output_header_lines(
mi->outp
ut, "Subject", hdr);
} else if (!strcmp(header[i], "From")) {
cleanup_space(hdr);
handle_from(mi, hdr);
} else if (!strcmp(header[i], "From")) {
cleanup_space(hdr);
handle_from(mi, hdr);
- fprintf(
fo
ut, "Author: %s\n", mi->name.buf);
- fprintf(
fo
ut, "Email: %s\n", mi->email.buf);
+ fprintf(
mi->outp
ut, "Author: %s\n", mi->name.buf);
+ fprintf(
mi->outp
ut, "Email: %s\n", mi->email.buf);
} else {
cleanup_space(hdr);
} else {
cleanup_space(hdr);
- fprintf(
fo
ut, "%s: %s\n", header[i], hdr->buf);
+ fprintf(
mi->outp
ut, "%s: %s\n", header[i], hdr->buf);
}
}
}
}
- fprintf(
fo
ut, "\n");
+ fprintf(
mi->outp
ut, "\n");
}
}
-static int mailinfo(struct mailinfo *mi,
- FILE *in, FILE *out, const char *msg, const char *patch)
+static int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
{
int peek;
struct strbuf line = STRBUF_INIT;
{
int peek;
struct strbuf line = STRBUF_INIT;
- fin = in;
- fout = out;
-
cmitmsg = fopen(msg, "w");
if (!cmitmsg) {
perror(msg);
cmitmsg = fopen(msg, "w");
if (!cmitmsg) {
perror(msg);
@@
-988,15
+988,15
@@
static int mailinfo(struct mailinfo *mi,
s_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*s_hdr_data));
do {
s_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*s_hdr_data));
do {
- peek = fgetc(
in
);
+ peek = fgetc(
mi->input
);
} while (isspace(peek));
} while (isspace(peek));
- ungetc(peek,
in
);
+ ungetc(peek,
mi->input
);
/* process the email header */
/* process the email header */
- while (read_one_header_line(&line,
fin
))
+ while (read_one_header_line(&line,
mi->input
))
check_header(&line, p_hdr_data, 1);
check_header(&line, p_hdr_data, 1);
- handle_body(&line);
+ handle_body(
mi,
&line);
fclose(patchfile);
handle_info(mi);
fclose(patchfile);
handle_info(mi);
@@
-1074,7
+1074,9
@@
int cmd_mailinfo(int argc, const char **argv, const char *prefix)
if (argc != 3)
usage(mailinfo_usage);
if (argc != 3)
usage(mailinfo_usage);
- status = !!mailinfo(&mi, stdin, stdout, argv[1], argv[2]);
+ mi.input = stdin;
+ mi.output = stdout;
+ status = !!mailinfo(&mi, argv[1], argv[2]);
clear_mailinfo(&mi);
return status;
clear_mailinfo(&mi);
return status;