Skip to content

Commit cd1957f

Browse files
peffgitster
authored andcommitted
pretty: give placeholders to reflog identity
When doing a reflog walk, you can get some information about the reflog (such as the subject line), but not the identity information (i.e., name and email). Let's make those available, mimicing the options for author and committer identity. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7b6c583 commit cd1957f

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

Documentation/pretty-formats.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ The placeholders are:
132132
- '%N': commit notes
133133
- '%gD': reflog selector, e.g., `refs/stash@\{1\}`
134134
- '%gd': shortened reflog selector, e.g., `stash@\{1\}`
135+
- '%gn': reflog identity name
136+
- '%gN': reflog identity name (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1])
137+
- '%ge': reflog identity email
138+
- '%gE': reflog identity email (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1])
135139
- '%gs': reflog subject
136140
- '%Cred': switch color to red
137141
- '%Cgreen': switch color to green

pretty.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,23 @@ static void rewrap_message_tail(struct strbuf *sb,
822822
c->indent2 = new_indent2;
823823
}
824824

825+
static int format_reflog_person(struct strbuf *sb,
826+
char part,
827+
struct reflog_walk_info *log,
828+
enum date_mode dmode)
829+
{
830+
const char *ident;
831+
832+
if (!log)
833+
return 2;
834+
835+
ident = get_reflog_ident(log);
836+
if (!ident)
837+
return 2;
838+
839+
return format_person_part(sb, part, ident, strlen(ident), dmode);
840+
}
841+
825842
static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
826843
void *context)
827844
{
@@ -963,6 +980,14 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
963980
if (c->pretty_ctx->reflog_info)
964981
get_reflog_message(sb, c->pretty_ctx->reflog_info);
965982
return 2;
983+
case 'n':
984+
case 'N':
985+
case 'e':
986+
case 'E':
987+
return format_reflog_person(sb,
988+
placeholder[1],
989+
c->pretty_ctx->reflog_info,
990+
c->pretty_ctx->date_mode);
966991
}
967992
return 0; /* unknown %g placeholder */
968993
case 'N':

reflog-walk.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,18 @@ void get_reflog_message(struct strbuf *sb,
291291
strbuf_add(sb, info->message, len);
292292
}
293293

294+
const char *get_reflog_ident(struct reflog_walk_info *reflog_info)
295+
{
296+
struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;
297+
struct reflog_info *info;
298+
299+
if (!commit_reflog)
300+
return NULL;
301+
302+
info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
303+
return info->email;
304+
}
305+
294306
void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,
295307
enum date_mode dmode)
296308
{

reflog-walk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extern void show_reflog_message(struct reflog_walk_info *info, int,
1414
enum date_mode);
1515
extern void get_reflog_message(struct strbuf *sb,
1616
struct reflog_walk_info *reflog_info);
17+
extern const char *get_reflog_ident(struct reflog_walk_info *reflog_info);
1718
extern void get_reflog_selector(struct strbuf *sb,
1819
struct reflog_walk_info *reflog_info,
1920
enum date_mode dmode,

t/t6006-rev-list-format.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ test_expect_success '%gd shortens ref name' '
267267
test_cmp expect.gd-short actual.gd-short
268268
'
269269

270+
test_expect_success 'reflog identity' '
271+
echo "C O Mitter:[email protected]" >expect &&
272+
git log -g -1 --format="%gn:%ge" >actual &&
273+
test_cmp expect actual
274+
'
275+
270276
test_expect_success 'oneline with empty message' '
271277
git commit -m "dummy" --allow-empty &&
272278
git commit -m "dummy" --allow-empty &&

0 commit comments

Comments
 (0)