Skip to content

Commit

Permalink
read_revision_from_stdin(): use strbuf
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Nov 20, 2009
1 parent 3bb18e5 commit 63d564b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions revision.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 63d564b

Please sign in to comment.