shortlog: use strbufs to read from stdin
[gitweb.git] / builtin / shortlog.c
index ab25b443d0d3cfbd59e4bc32040f1f74a6656537..6c0a72edef864016c5faafd260df61e9242a7937 100644 (file)
@@ -91,21 +91,24 @@ static void insert_one_record(struct shortlog *log,
 
 static void read_from_stdin(struct shortlog *log)
 {
-       char author[1024], oneline[1024];
+       struct strbuf author = STRBUF_INIT;
+       struct strbuf oneline = STRBUF_INIT;
 
-       while (fgets(author, sizeof(author), stdin) != NULL) {
+       while (strbuf_getline(&author, stdin, '\n') != EOF) {
                const char *v;
-               if (!skip_prefix(author, "Author: ", &v) &&
-                   !skip_prefix(author, "author ", &v))
+               if (!skip_prefix(author.buf, "Author: ", &v) &&
+                   !skip_prefix(author.buf, "author ", &v))
                        continue;
-               while (fgets(oneline, sizeof(oneline), stdin) &&
-                      oneline[0] != '\n')
+               while (strbuf_getline(&oneline, stdin, '\n') != EOF &&
+                      oneline.len)
                        ; /* discard headers */
-               while (fgets(oneline, sizeof(oneline), stdin) &&
-                      oneline[0] == '\n')
+               while (strbuf_getline(&oneline, stdin, '\n') != EOF &&
+                      !oneline.len)
                        ; /* discard blanks */
-               insert_one_record(log, v, oneline);
+               insert_one_record(log, v, oneline.buf);
        }
+       strbuf_release(&author);
+       strbuf_release(&oneline);
 }
 
 void shortlog_add_commit(struct shortlog *log, struct commit *commit)