Documentation/git-request-pull: Fixed a typo ("send" -> "end")
[gitweb.git] / builtin-shortlog.c
index b9cc134443feb4f9573166faf0745074384e0c21..f08095bc91b92ad93560459d060259bd5df52c4a 100644 (file)
@@ -8,9 +8,10 @@
 #include "mailmap.h"
 
 static const char shortlog_usage[] =
-"git-shortlog [-n] [-s] [<commit-id>... ]";
+"git-shortlog [-n] [-s] [-e] [<commit-id>... ]";
 
 static char *common_repo_prefix;
+static int email;
 
 static int compare_by_number(const void *a1, const void *a2)
 {
@@ -57,6 +58,14 @@ static void insert_one_record(struct path_list *list,
                        len--;
                namebuf[len] = '\0';
        }
+       else
+               len = strlen(namebuf);
+
+       if (email) {
+               size_t room = sizeof(namebuf) - len - 1;
+               int maillen = eoemail - boemail + 1;
+               snprintf(namebuf + len, room, " %.*s", maillen, boemail);
+       }
 
        buffer = xstrdup(namebuf);
        item = path_list_insert(buffer, list);
@@ -65,11 +74,12 @@ static void insert_one_record(struct path_list *list,
        else
                free(buffer);
 
+       /* Skip any leading whitespace, including any blank lines. */
+       while (*oneline && isspace(*oneline))
+               oneline++;
        eol = strchr(oneline, '\n');
        if (!eol)
                eol = oneline + strlen(oneline);
-       while (*oneline && isspace(*oneline) && *oneline != '\n')
-               oneline++;
        if (!prefixcmp(oneline, "[PATCH")) {
                char *eob = strchr(oneline, ']');
                if (eob && (!eol || eob < eol))
@@ -219,6 +229,9 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
                else if (!strcmp(argv[1], "-s") ||
                                !strcmp(argv[1], "--summary"))
                        summary = 1;
+               else if (!strcmp(argv[1], "-e") ||
+                        !strcmp(argv[1], "--email"))
+                       email = 1;
                else if (!prefixcmp(argv[1], "-w")) {
                        wrap_lines = 1;
                        parse_wrap_args(argv[1], &in1, &in2, &wrap);
@@ -237,9 +250,10 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
 
        read_mailmap(&mailmap, ".mailmap", &common_repo_prefix);
 
+       /* assume HEAD if from a tty */
+       if (!rev.pending.nr && isatty(0))
+               add_head_to_pending(&rev);
        if (rev.pending.nr == 0) {
-               if (isatty(0))
-                       fprintf(stderr, "(reading log to summarize from standard input)\n");
                read_from_stdin(&list);
        }
        else
@@ -253,7 +267,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
                struct path_list *onelines = list.items[i].util;
 
                if (summary) {
-                       printf("%s: %d\n", list.items[i].path, onelines->nr);
+                       printf("%6d\t%s\n", onelines->nr, list.items[i].path);
                } else {
                        printf("%s (%d):\n", list.items[i].path, onelines->nr);
                        for (j = onelines->nr - 1; j >= 0; j--) {