Code

Merge branch 'jk/pretty-reglog-ent'
authorJunio C Hamano <gitster@pobox.com>
Thu, 22 Dec 2011 19:27:28 +0000 (11:27 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Dec 2011 19:27:28 +0000 (11:27 -0800)
* jk/pretty-reglog-ent:
  pretty: give placeholders to reflog identity

Documentation/pretty-formats.txt
pretty.c
reflog-walk.c
reflog-walk.h
t/t6006-rev-list-format.sh

index 561cc9f7d7ef1a2502d608e59e2eae345bffd685..880b6f2e6f946ab6fc0ff4850759908364d50854 100644 (file)
@@ -132,6 +132,10 @@ The placeholders are:
 - '%N': commit notes
 - '%gD': reflog selector, e.g., `refs/stash@\{1\}`
 - '%gd': shortened reflog selector, e.g., `stash@\{1\}`
+- '%gn': reflog identity name
+- '%gN': reflog identity name (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1])
+- '%ge': reflog identity email
+- '%gE': reflog identity email (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1])
 - '%gs': reflog subject
 - '%Cred': switch color to red
 - '%Cgreen': switch color to green
index 230fe1cc82e3a3bf7c0fef604350868d917acef4..1580299d4037ada9e1f0e3c11c6c5578f44f52dd 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -822,6 +822,23 @@ static void rewrap_message_tail(struct strbuf *sb,
        c->indent2 = new_indent2;
 }
 
+static int format_reflog_person(struct strbuf *sb,
+                               char part,
+                               struct reflog_walk_info *log,
+                               enum date_mode dmode)
+{
+       const char *ident;
+
+       if (!log)
+               return 2;
+
+       ident = get_reflog_ident(log);
+       if (!ident)
+               return 2;
+
+       return format_person_part(sb, part, ident, strlen(ident), dmode);
+}
+
 static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
                                void *context)
 {
@@ -963,6 +980,14 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
                        if (c->pretty_ctx->reflog_info)
                                get_reflog_message(sb, c->pretty_ctx->reflog_info);
                        return 2;
+               case 'n':
+               case 'N':
+               case 'e':
+               case 'E':
+                       return format_reflog_person(sb,
+                                                   placeholder[1],
+                                                   c->pretty_ctx->reflog_info,
+                                                   c->pretty_ctx->date_mode);
                }
                return 0;       /* unknown %g placeholder */
        case 'N':
index 64c677fc49d7874736221b1828f96d8652cb1fb3..86d18843f52046d87741bffa9f865ec973a2ae73 100644 (file)
@@ -295,6 +295,18 @@ void get_reflog_message(struct strbuf *sb,
        strbuf_add(sb, info->message, len);
 }
 
+const char *get_reflog_ident(struct reflog_walk_info *reflog_info)
+{
+       struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;
+       struct reflog_info *info;
+
+       if (!commit_reflog)
+               return NULL;
+
+       info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
+       return info->email;
+}
+
 void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,
        enum date_mode dmode)
 {
index 7bd2cd4c4e5cd9d51e645509eeacc49a83a44ba7..afb1ae3fde93a5c61def211be56b0554a25dd45e 100644 (file)
@@ -14,6 +14,7 @@ extern void show_reflog_message(struct reflog_walk_info *info, int,
                enum date_mode);
 extern void get_reflog_message(struct strbuf *sb,
                struct reflog_walk_info *reflog_info);
+extern const char *get_reflog_ident(struct reflog_walk_info *reflog_info);
 extern void get_reflog_selector(struct strbuf *sb,
                struct reflog_walk_info *reflog_info,
                enum date_mode dmode,
index d918cc02d090157485d404d34d49005e50cd9f1a..444279077e803ca96e48281ae956ea6536317608 100755 (executable)
@@ -267,6 +267,12 @@ test_expect_success '%gd shortens ref name' '
        test_cmp expect.gd-short actual.gd-short
 '
 
+test_expect_success 'reflog identity' '
+       echo "C O Mitter:committer@example.com" >expect &&
+       git log -g -1 --format="%gn:%ge" >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'oneline with empty message' '
        git commit -m "dummy" --allow-empty &&
        git commit -m "dummy" --allow-empty &&