aboutsummaryrefslogtreecommitdiff
path: root/revision.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-11-20 02:00:40 -0800
committerJunio C Hamano <gitster@pobox.com>2009-11-20 14:50:43 -0800
commit63d564b300274ec71a274f9b672366d07ae5620a (patch)
treed6ddf4ae6954c6c441f255f6a87ceb14489888de /revision.c
parent3bb18e58fc4f5eddd97bc34fc11dc207b47cc093 (diff)
downloadgit-63d564b300274ec71a274f9b672366d07ae5620a.tar.gz
git-63d564b300274ec71a274f9b672366d07ae5620a.tar.xz
read_revision_from_stdin(): use strbuf
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>
Diffstat (limited to 'revision.c')
-rw-r--r--revision.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/revision.c b/revision.c
index 9fc4e8d38..d56387fe6 100644
--- a/revision.c
+++ b/revision.c
@@ -955,19 +955,21 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
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)