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>
Junio C Hamano committed
Nov 20, 2009 at 02:00 UTC
63d564b300274ec71a274f9b672366d07ae5620a
1 file changed
+10
-8
revision.c
+10
-8
@@ -955,19 +955,21 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
955
956
void read_revisions_from_stdin(struct rev_info *revs)
957
{
958
- char line[1000];
958
+ struct strbuf sb;
959
960
- while (fgets(line, sizeof(line), stdin) != NULL) {
961
- int len = strlen(line);
962
- if (len && line[len - 1] == '\n')
963
- line[--len] = '\0';
960
+ strbuf_init(&sb, 1000);
961
+ while (strbuf_getwholeline(&sb, stdin, '\n') != EOF) {
962
+ int len = sb.len;
963
+ if (len && sb.buf[len - 1] == '\n')
964
+ sb.buf[--len] = '\0';
965
if (!len)
966
break;
966
- if (line[0] == '-')
967
+ if (sb.buf[0] == '-')
968
die("options not supported in --stdin mode");
968
- if (handle_revision_arg(line, revs, 0, 1))
969
- die("bad revision '%s'", line);
969
+ if (handle_revision_arg(sb.buf, revs, 0, 1))
970
+ die("bad revision '%s'", sb.buf);
971
}
972
+ strbuf_release(&sb);
973
}
974
975
static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token what)