git.el: Add support for commit hooks.
[gitweb.git] / builtin-shortlog.c
index f1124e261b04ca93118c662f391dec41d9ee9713..29343aefc843c4dd22095f559262bc6b5e381440 100644 (file)
@@ -4,7 +4,6 @@
 #include "diff.h"
 #include "path-list.h"
 #include "revision.h"
-#include <string.h>
 
 static const char shortlog_usage[] =
 "git-shortlog [-n] [-s] [<commit-id>... ]";
@@ -125,7 +124,7 @@ static void insert_author_oneline(struct path_list *list,
        else
                free(buffer);
 
-       if (!strncmp(oneline, "[PATCH", 6)) {
+       if (!prefixcmp(oneline, "[PATCH")) {
                char *eob = strchr(oneline, ']');
 
                if (eob) {
@@ -180,7 +179,7 @@ static void read_from_stdin(struct path_list *list)
        while (fgets(buffer, sizeof(buffer), stdin) != NULL) {
                char *bob;
                if ((buffer[0] == 'A' || buffer[0] == 'a') &&
-                               !strncmp(buffer + 1, "uthor: ", 7) &&
+                               !prefixcmp(buffer + 1, "uthor: ") &&
                                (bob = strchr(buffer + 7, '<')) != NULL) {
                        char buffer2[1024], offset = 0;
 
@@ -188,18 +187,25 @@ static void read_from_stdin(struct path_list *list)
                                bob = buffer + strlen(buffer);
                        else {
                                offset = 8;
-                               while (isspace(bob[-1]))
+                               while (buffer + offset < bob &&
+                                      isspace(bob[-1]))
                                        bob--;
                        }
 
                        while (fgets(buffer2, sizeof(buffer2), stdin) &&
                                        buffer2[0] != '\n')
                                ; /* chomp input */
-                       if (fgets(buffer2, sizeof(buffer2), stdin))
+                       if (fgets(buffer2, sizeof(buffer2), stdin)) {
+                               int l2 = strlen(buffer2);
+                               int i;
+                               for (i = 0; i < l2; i++)
+                                       if (!isspace(buffer2[i]))
+                                               break;
                                insert_author_oneline(list,
                                                buffer + offset,
                                                bob - buffer - offset,
-                                               buffer2, strlen(buffer2));
+                                               buffer2 + i, l2 - i);
+                       }
                }
        }
 }
@@ -211,20 +217,20 @@ static void get_from_rev(struct rev_info *rev, struct path_list *list)
 
        prepare_revision_walk(rev);
        while ((commit = get_revision(rev)) != NULL) {
-               char *author = NULL, *oneline, *buffer;
+               const char *author = NULL, *oneline, *buffer;
                int authorlen = authorlen, onelinelen;
 
                /* get author and oneline */
                for (buffer = commit->buffer; buffer && *buffer != '\0' &&
                                *buffer != '\n'; ) {
-                       char *eol = strchr(buffer, '\n');
+                       const char *eol = strchr(buffer, '\n');
 
                        if (eol == NULL)
                                eol = buffer + strlen(buffer);
                        else
                                eol++;
 
-                       if (!strncmp(buffer, "author ", 7)) {
+                       if (!prefixcmp(buffer, "author ")) {
                                char *bracket = strchr(buffer, '<');
 
                                if (bracket == NULL || bracket > eol)
@@ -236,7 +242,7 @@ static void get_from_rev(struct rev_info *rev, struct path_list *list)
                                        author = scratch;
                                        authorlen = strlen(scratch);
                                } else {
-                                       while (bracket[-1] == ' ')
+                                       if (bracket[-1] == ' ')
                                                bracket--;
 
                                        author = buffer + 7;
@@ -298,8 +304,11 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
        if (!access(".mailmap", R_OK))
                read_mailmap(".mailmap");
 
-       if (rev.pending.nr == 0)
+       if (rev.pending.nr == 0) {
+               if (isatty(0))
+                       fprintf(stderr, "(reading log to summarize from standard input)\n");
                read_from_stdin(&list);
+       }
        else
                get_from_rev(&rev, &list);