Skip to content

Commit adb8676

Browse files
committed
Merge branch 'jk/pretty-reglog-ent'
* jk/pretty-reglog-ent: pretty: give placeholders to reflog identity
2 parents d5cb31a + cd1957f commit adb8676

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
@@ -295,6 +295,18 @@ void get_reflog_message(struct strbuf *sb,
295295
strbuf_add(sb, info->message, len);
296296
}
297297

298+
const char *get_reflog_ident(struct reflog_walk_info *reflog_info)
299+
{
300+
struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;
301+
struct reflog_info *info;
302+
303+
if (!commit_reflog)
304+
return NULL;
305+
306+
info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
307+
return info->email;
308+
}
309+
298310
void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,
299311
enum date_mode dmode)
300312
{

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)