git-svn: pass an unambiguous ref to rev-list when grafting-branches
[gitweb.git] / builtin-shortlog.c
index b5b13dee3b3a5fe5877762817af9de7dd22d5c4c..edb40429ec4465f3bebba02f2174314dd0183225 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>... ]";
@@ -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);
+                       }
                }
        }
 }
@@ -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);