Merge branch 'jk/shortlog'
authorJunio C Hamano <gitster@pobox.com>
Fri, 29 Jan 2016 00:10:14 +0000 (16:10 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 29 Jan 2016 00:10:14 +0000 (16:10 -0800)
"git shortlog" used to accumulate various pieces of information
regardless of what was asked to be shown in the final output. It
has been optimized by noticing what need not to be collected
(e.g. there is no need to collect the log messages when showing
only the number of changes).

* jk/shortlog:
shortlog: don't warn on empty author
shortlog: optimize out useless string list
shortlog: optimize out useless "<none>" normalization
shortlog: optimize "--summary" mode
shortlog: replace hand-parsing of author with pretty-printer
shortlog: use strbufs to read from stdin
shortlog: match both "Author:" and "author" on stdin

1  2 
builtin/shortlog.c
index 35ebd17f80d7784f17023a4f76ac71e1317a94d0,e32be3993cdf17c3ae6f4900876d2c83de39299f..bfc082e58467953c1e4c96fd27a884abea4f5127
@@@ -91,20 -115,24 +115,24 @@@ static void insert_one_record(struct sh
  
  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) {
-               if (!(author[0] == 'A' || author[0] == 'a') ||
-                   !starts_with(author + 1, "uthor: "))
 -      while (strbuf_getline(&author, stdin, '\n') != EOF) {
++      while (strbuf_getline_lf(&author, stdin) != EOF) {
+               const char *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 &&
++              while (strbuf_getline_lf(&oneline, stdin) != EOF &&
+                      oneline.len)
                        ; /* discard headers */
-               while (fgets(oneline, sizeof(oneline), stdin) &&
-                      oneline[0] == '\n')
 -              while (strbuf_getline(&oneline, stdin, '\n') != EOF &&
++              while (strbuf_getline_lf(&oneline, stdin) != EOF &&
+                      !oneline.len)
                        ; /* discard blanks */
-               insert_one_record(log, author + 8, oneline);
+               insert_one_record(log, v, oneline.buf);
        }
+       strbuf_release(&author);
+       strbuf_release(&oneline);
  }
  
  void shortlog_add_commit(struct shortlog *log, struct commit *commit)