]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-shortlog.c
Merge branch 'maint'
[git.git] / builtin-shortlog.c
index b5b13dee3b3a5fe5877762817af9de7dd22d5c4c..2d7726e8b975d9977e14638cc127ed0b30d3058b 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,9 +304,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
        if (!access(".mailmap", R_OK))
                read_mailmap(".mailmap");
 
-       if (rev.pending.nr == 1)
-               die ("Need a range!");
-       else if (rev.pending.nr == 0)
+       if (rev.pending.nr == 0)
                read_from_stdin(&list);
        else
                get_from_rev(&rev, &list);