summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c7e4f0d)
raw | patch | inline | side by side (parent: c7e4f0d)
author | Brandon Casey <drafnel@gmail.com> | |
Wed, 5 Aug 2009 03:31:57 +0000 (22:31 -0500) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 5 Aug 2009 19:13:57 +0000 (12:13 -0700) |
There should be no functional change. Just the necessary changes and
simplifications associated with calling strbuf_getwholeline() rather
than an internal function or fgets.
Signed-off-by: Brandon Casey <drafnel@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
simplifications associated with calling strbuf_getwholeline() rather
than an internal function or fgets.
Signed-off-by: Brandon Casey <drafnel@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-mailinfo.c | patch | blob | history | |
builtin-mailsplit.c | patch | blob | history |
diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index 92637ac0bae82d0b88e267b572a51a75299cda5c..b0b5d8f6cb5107f3422d6107fd56f35ef62786f6 100644 (file)
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
static void handle_body(void)
{
- int len = 0;
struct strbuf prev = STRBUF_INIT;
/* Skip up to the first boundary */
}
do {
- strbuf_setlen(&line, line.len + len);
-
/* process any boundary lines */
if (*content_top && is_multipart_boundary(&line)) {
/* flush any leftover */
handle_filter(&line);
}
- strbuf_reset(&line);
- if (strbuf_avail(&line) < 100)
- strbuf_grow(&line, 100);
- } while ((len = read_line_with_nul(line.buf, strbuf_avail(&line), fin)));
+ } while (!strbuf_getwholeline(&line, fin, '\n'));
handle_body_out:
strbuf_release(&prev);
diff --git a/builtin-mailsplit.c b/builtin-mailsplit.c
index ad5f6b593df45f01360f3daa8b37d024ee793e9e..c2ec6ea3d51e760581dcb6f86c1783a545ebc07a 100644 (file)
--- a/builtin-mailsplit.c
+++ b/builtin-mailsplit.c
#include "cache.h"
#include "builtin.h"
#include "string-list.h"
+#include "strbuf.h"
static const char git_mailsplit_usage[] =
"git mailsplit [-d<prec>] [-f<n>] [-b] -o<directory> [<mbox>|<Maildir>...]";
return 1;
}
-/* Could be as small as 64, enough to hold a Unix "From " line. */
-static char buf[4096];
+static struct strbuf buf = STRBUF_INIT;
/* We cannot use fgets() because our lines can contain NULs */
int read_line_with_nul(char *buf, int size, FILE *in)
static int split_one(FILE *mbox, const char *name, int allow_bare)
{
FILE *output = NULL;
- int len = strlen(buf);
int fd;
int status = 0;
- int is_bare = !is_from_line(buf, len);
+ int is_bare = !is_from_line(buf.buf, buf.len);
if (is_bare && !allow_bare)
goto corrupt;
* "From " and having something that looks like a date format.
*/
for (;;) {
- int is_partial = len && buf[len-1] != '\n';
-
- if (fwrite(buf, 1, len, output) != len)
+ if (fwrite(buf.buf, 1, buf.len, output) != buf.len)
die_errno("cannot write output");
- len = read_line_with_nul(buf, sizeof(buf), mbox);
- if (len == 0) {
+ if (strbuf_getwholeline(&buf, mbox, '\n')) {
if (feof(mbox)) {
status = 1;
break;
}
die_errno("cannot read mbox");
}
- if (!is_partial && !is_bare && is_from_line(buf, len))
+ if (!is_bare && is_from_line(buf.buf, buf.len))
break; /* done with one message */
}
fclose(output);
goto out;
}
- if (fgets(buf, sizeof(buf), f) == NULL) {
+ if (strbuf_getwholeline(&buf, f, '\n')) {
error("cannot read mail %s (%s)", file, strerror(errno));
goto out;
}
} while (isspace(peek));
ungetc(peek, f);
- if (fgets(buf, sizeof(buf), f) == NULL) {
+ if (strbuf_getwholeline(&buf, f, '\n')) {
/* empty stdin is OK */
if (f != stdin) {
error("cannot read mbox %s", file);