提交 cd1bea91 编写于 作者: J Junio C Hamano

Merge branch 'jc/shortlog-e'

* jc/shortlog-e:
  shortlog: default to HEAD when the standard input is a tty
  Invert numbers and names in the git-shortlog summary mode.
  shortlog: document -e option
  git-shortlog -e: show e-mail address as well
...@@ -8,8 +8,8 @@ git-shortlog - Summarize 'git log' output ...@@ -8,8 +8,8 @@ git-shortlog - Summarize 'git log' output
SYNOPSIS SYNOPSIS
-------- --------
[verse] [verse]
git-log --pretty=short | 'git-shortlog' [-h] [-n] [-s] git-log --pretty=short | 'git-shortlog' [-h] [-n] [-s] [-e]
git-shortlog [-n|--numbered] [-s|--summary] [<committish>...] git-shortlog [-n|--numbered] [-s|--summary] [-e|--email] [<committish>...]
DESCRIPTION DESCRIPTION
----------- -----------
...@@ -32,6 +32,9 @@ OPTIONS ...@@ -32,6 +32,9 @@ OPTIONS
-s, \--summary:: -s, \--summary::
Suppress commit description and provide a commit count summary only. Suppress commit description and provide a commit count summary only.
-e, \--email::
Show the email address of each author.
FILES FILES
----- -----
......
...@@ -176,18 +176,6 @@ static int builtin_diff_combined(struct rev_info *revs, ...@@ -176,18 +176,6 @@ static int builtin_diff_combined(struct rev_info *revs,
return 0; return 0;
} }
void add_head(struct rev_info *revs)
{
unsigned char sha1[20];
struct object *obj;
if (get_sha1("HEAD", sha1))
return;
obj = parse_object(sha1);
if (!obj)
return;
add_pending_object(revs, obj, "HEAD");
}
static void refresh_index_quietly(void) static void refresh_index_quietly(void)
{ {
struct lock_file *lock_file; struct lock_file *lock_file;
...@@ -272,7 +260,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) ...@@ -272,7 +260,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
if (!strcmp(arg, "--")) if (!strcmp(arg, "--"))
break; break;
else if (!strcmp(arg, "--cached")) { else if (!strcmp(arg, "--cached")) {
add_head(&rev); add_head_to_pending(&rev);
if (!rev.pending.nr) if (!rev.pending.nr)
die("No HEAD commit to compare with (yet)"); die("No HEAD commit to compare with (yet)");
break; break;
......
...@@ -18,9 +18,6 @@ ...@@ -18,9 +18,6 @@
static int default_show_root = 1; static int default_show_root = 1;
static const char *fmt_patch_subject_prefix = "PATCH"; static const char *fmt_patch_subject_prefix = "PATCH";
/* this is in builtin-diff.c */
void add_head(struct rev_info *revs);
static void add_name_decoration(const char *prefix, const char *name, struct object *obj) static void add_name_decoration(const char *prefix, const char *name, struct object *obj)
{ {
int plen = strlen(prefix); int plen = strlen(prefix);
...@@ -746,7 +743,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) ...@@ -746,7 +743,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
* does not have. * does not have.
*/ */
rev.pending.objects[0].item->flags |= UNINTERESTING; rev.pending.objects[0].item->flags |= UNINTERESTING;
add_head(&rev); add_head_to_pending(&rev);
} }
/* /*
* Otherwise, it is "format-patch -22 HEAD", and/or * Otherwise, it is "format-patch -22 HEAD", and/or
......
...@@ -11,6 +11,7 @@ static const char shortlog_usage[] = ...@@ -11,6 +11,7 @@ static const char shortlog_usage[] =
"git-shortlog [-n] [-s] [<commit-id>... ]"; "git-shortlog [-n] [-s] [<commit-id>... ]";
static char *common_repo_prefix; static char *common_repo_prefix;
static int email;
static int compare_by_number(const void *a1, const void *a2) static int compare_by_number(const void *a1, const void *a2)
{ {
...@@ -57,6 +58,14 @@ static void insert_one_record(struct path_list *list, ...@@ -57,6 +58,14 @@ static void insert_one_record(struct path_list *list,
len--; len--;
namebuf[len] = '\0'; 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); buffer = xstrdup(namebuf);
item = path_list_insert(buffer, list); item = path_list_insert(buffer, list);
...@@ -219,6 +228,9 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix) ...@@ -219,6 +228,9 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
else if (!strcmp(argv[1], "-s") || else if (!strcmp(argv[1], "-s") ||
!strcmp(argv[1], "--summary")) !strcmp(argv[1], "--summary"))
summary = 1; summary = 1;
else if (!strcmp(argv[1], "-e") ||
!strcmp(argv[1], "--email"))
email = 1;
else if (!prefixcmp(argv[1], "-w")) { else if (!prefixcmp(argv[1], "-w")) {
wrap_lines = 1; wrap_lines = 1;
parse_wrap_args(argv[1], &in1, &in2, &wrap); parse_wrap_args(argv[1], &in1, &in2, &wrap);
...@@ -237,9 +249,10 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix) ...@@ -237,9 +249,10 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
read_mailmap(&mailmap, ".mailmap", &common_repo_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 (rev.pending.nr == 0) {
if (isatty(0))
fprintf(stderr, "(reading log to summarize from standard input)\n");
read_from_stdin(&list); read_from_stdin(&list);
} }
else else
...@@ -253,7 +266,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix) ...@@ -253,7 +266,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
struct path_list *onelines = list.items[i].util; struct path_list *onelines = list.items[i].util;
if (summary) { if (summary) {
printf("%s: %d\n", list.items[i].path, onelines->nr); printf("%6d\t%s\n", onelines->nr, list.items[i].path);
} else { } else {
printf("%s (%d):\n", list.items[i].path, onelines->nr); printf("%s (%d):\n", list.items[i].path, onelines->nr);
for (j = onelines->nr - 1; j >= 0; j--) { for (j = onelines->nr - 1; j >= 0; j--) {
......
...@@ -139,6 +139,18 @@ void add_pending_object(struct rev_info *revs, struct object *obj, const char *n ...@@ -139,6 +139,18 @@ void add_pending_object(struct rev_info *revs, struct object *obj, const char *n
add_pending_object_with_mode(revs, obj, name, S_IFINVALID); add_pending_object_with_mode(revs, obj, name, S_IFINVALID);
} }
void add_head_to_pending(struct rev_info *revs)
{
unsigned char sha1[20];
struct object *obj;
if (get_sha1("HEAD", sha1))
return;
obj = parse_object(sha1);
if (!obj)
return;
add_pending_object(revs, obj, "HEAD");
}
static struct object *get_reference(struct rev_info *revs, const char *name, const unsigned char *sha1, unsigned int flags) static struct object *get_reference(struct rev_info *revs, const char *name, const unsigned char *sha1, unsigned int flags)
{ {
struct object *object; struct object *object;
......
...@@ -130,6 +130,8 @@ extern void add_object(struct object *obj, ...@@ -130,6 +130,8 @@ extern void add_object(struct object *obj,
extern void add_pending_object(struct rev_info *revs, struct object *obj, const char *name); extern void add_pending_object(struct rev_info *revs, struct object *obj, const char *name);
extern void add_head_to_pending(struct rev_info *);
enum commit_action { enum commit_action {
commit_ignore, commit_ignore,
commit_show, commit_show,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册