Code

Documentation: Moving out of detached HEAD does not warn anymore.
[git.git] / builtin-shortlog.c
index b760b477ea40e7826982f3578ea17c49dd32492e..edb40429ec4465f3bebba02f2174314dd0183225 100644 (file)
@@ -4,11 +4,12 @@
 #include "diff.h"
 #include "path-list.h"
 #include "revision.h"
-#include <string.h>
 
 static const char shortlog_usage[] =
 "git-shortlog [-n] [-s] [<commit-id>... ]";
 
+static char *common_repo_prefix;
+
 static int compare_by_number(const void *a1, const void *a2)
 {
        const struct path_list_item *i1 = a1, *i2 = a2;
@@ -35,8 +36,26 @@ static int read_mailmap(const char *filename)
                char *end_of_name, *left_bracket, *right_bracket;
                char *name, *email;
                int i;
-               if (buffer[0] == '#')
+               if (buffer[0] == '#') {
+                       static const char abbrev[] = "# repo-abbrev:";
+                       int abblen = sizeof(abbrev) - 1;
+                       int len = strlen(buffer);
+
+                       if (len && buffer[len - 1] == '\n')
+                               buffer[--len] = 0;
+                       if (!strncmp(buffer, abbrev, abblen)) {
+                               char *cp;
+
+                               if (common_repo_prefix)
+                                       free(common_repo_prefix);
+                               common_repo_prefix = xmalloc(len);
+
+                               for (cp = buffer + abblen; isspace(*cp); cp++)
+                                       ; /* nothing */
+                               strcpy(common_repo_prefix, cp);
+                       }
                        continue;
+               }
                if ((left_bracket = strchr(buffer, '<')) == NULL)
                        continue;
                if ((right_bracket = strchr(left_bracket + 1, '>')) == NULL)
@@ -87,7 +106,7 @@ static void insert_author_oneline(struct path_list *list,
                const char *author, int authorlen,
                const char *oneline, int onelinelen)
 {
-       const char *dot3 = "/pub/scm/linux/kernel/git/";
+       const char *dot3 = common_repo_prefix;
        char *buffer, *p;
        struct path_list_item *item;
        struct path_list *onelines;
@@ -130,12 +149,17 @@ static void insert_author_oneline(struct path_list *list,
        memcpy(buffer, oneline, onelinelen);
        buffer[onelinelen] = '\0';
 
-       while ((p = strstr(buffer, dot3)) != NULL) {
-               memcpy(p, "...", 3);
-               strcpy(p + 2, p + sizeof(dot3) - 1);
+       if (dot3) {
+               int dot3len = strlen(dot3);
+               if (dot3len > 5) {
+                       while ((p = strstr(buffer, dot3)) != NULL) {
+                               int taillen = strlen(p) - dot3len;
+                               memcpy(p, "/.../", 5);
+                               memmove(p + 5, p + dot3len, taillen + 1);
+                       }
+               }
        }
 
-
        onelines = item->util;
        if (onelines->nr >= onelines->alloc) {
                onelines->alloc = alloc_nr(onelines->nr);
@@ -163,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,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;
@@ -273,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);