From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 1/3] read_revision_from_stdin(): use strbuf
Date: Fri, 20 Nov 2009 03:25:13 -0800 [thread overview]
Message-ID: <1258716315-2213-2-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1258716315-2213-1-git-send-email-gitster@pobox.com>
It is so 2005 (and Linus ;-) to have a fixed 1000-byte buffer that
reads from the user. Let's use strbuf to unlimit the input length.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
revision.c | 18 ++++++++++--------
1 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/revision.c b/revision.c
index 45c5de8..f5b735f 100644
--- a/revision.c
+++ b/revision.c
@@ -955,19 +955,21 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
static void read_revisions_from_stdin(struct rev_info *revs)
{
- char line[1000];
+ struct strbuf sb;
- while (fgets(line, sizeof(line), stdin) != NULL) {
- int len = strlen(line);
- if (len && line[len - 1] == '\n')
- line[--len] = '\0';
+ strbuf_init(&sb, 1000);
+ while (strbuf_getwholeline(&sb, stdin, '\n') != EOF) {
+ int len = sb.len;
+ if (len && sb.buf[len - 1] == '\n')
+ sb.buf[--len] = '\0';
if (!len)
break;
- if (line[0] == '-')
+ if (sb.buf[0] == '-')
die("options not supported in --stdin mode");
- if (handle_revision_arg(line, revs, 0, 1))
- die("bad revision '%s'", line);
+ if (handle_revision_arg(sb.buf, revs, 0, 1))
+ die("bad revision '%s'", sb.buf);
}
+ strbuf_release(&sb);
}
static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token what)
--
1.6.5.3.342.g14bb9
next prev parent reply other threads:[~2009-11-20 11:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-20 11:25 [PATCH 0/3] "log --stdin" updates Junio C Hamano
2009-11-20 11:25 ` Junio C Hamano [this message]
2009-11-20 11:25 ` [PATCH 2/3] setup_revisions(): do not call get_pathspec() too early Junio C Hamano
2009-11-20 11:25 ` [PATCH 3/3] Make --stdin option to "log" family read also pathspecs Junio C Hamano
2009-11-20 14:40 ` [PATCH 0/3] "log --stdin" updates Jeff King
2009-11-20 17:59 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1258716315-2213-2-git-send-email-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox