Skip to content

Commit 92a62a0

Browse files
committed
pretty: add %cm/%cf.
1 parent 43c8a30 commit 92a62a0

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

pretty.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -775,13 +775,17 @@ static int mailmap_name(const char **email, size_t *email_len,
775775

776776
static size_t format_person_part(struct strbuf *sb, char part,
777777
const char *msg, int len,
778-
const struct date_mode *dmode)
778+
const struct date_mode *dmode,
779+
const char *ca_msg, int ca_len)
779780
{
780781
/* currently all placeholders have same length */
781782
const int placeholder_len = 2;
782783
struct ident_split s;
784+
struct ident_split ca_s;
783785
const char *name, *mail;
786+
const char *ca_name, *ca_mail;
784787
size_t maillen, namelen;
788+
size_t ca_maillen, ca_namelen;
785789

786790
if (split_ident_line(&s, msg, len) < 0)
787791
goto skip;
@@ -791,13 +795,26 @@ static size_t format_person_part(struct strbuf *sb, char part,
791795
mail = s.mail_begin;
792796
maillen = s.mail_end - s.mail_begin;
793797

798+
if (part == 'm' || part == 'f') { /* committer name or email if committer != author */
799+
if (ca_msg != NULL && !split_ident_line(&ca_s, ca_msg, ca_len)) {
800+
ca_name = ca_s.name_begin;
801+
ca_namelen = ca_s.name_end - ca_s.name_begin;
802+
ca_mail = ca_s.mail_begin;
803+
ca_maillen = ca_s.mail_end - ca_s.mail_begin;
804+
if (namelen == ca_namelen &&
805+
maillen == ca_maillen &&
806+
!strncmp(name, ca_name, namelen) &&
807+
!strncmp(mail, ca_mail, maillen))
808+
return placeholder_len;
809+
}
810+
}
794811
if (part == 'N' || part == 'E' || part == 'L') /* mailmap lookup */
795812
mailmap_name(&mail, &maillen, &name, &namelen);
796-
if (part == 'n' || part == 'N') { /* name */
813+
if (part == 'n' || part == 'N' || part == 'm') { /* name */
797814
strbuf_add(sb, name, namelen);
798815
return placeholder_len;
799816
}
800-
if (part == 'e' || part == 'E') { /* email */
817+
if (part == 'e' || part == 'E' || part == 'f') { /* email */
801818
strbuf_add(sb, mail, maillen);
802819
return placeholder_len;
803820
}
@@ -1045,7 +1062,7 @@ static int format_reflog_person(struct strbuf *sb,
10451062
if (!ident)
10461063
return 2;
10471064

1048-
return format_person_part(sb, part, ident, strlen(ident), dmode);
1065+
return format_person_part(sb, part, ident, strlen(ident), dmode, NULL, 0);
10491066
}
10501067

10511068
static size_t parse_color(struct strbuf *sb, /* in UTF-8 */
@@ -1650,11 +1667,13 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
16501667
case 'a': /* author ... */
16511668
return format_person_part(sb, placeholder[1],
16521669
msg + c->author.off, c->author.len,
1653-
&c->pretty_ctx->date_mode);
1670+
&c->pretty_ctx->date_mode,
1671+
NULL, 0);
16541672
case 'c': /* committer ... */
16551673
return format_person_part(sb, placeholder[1],
16561674
msg + c->committer.off, c->committer.len,
1657-
&c->pretty_ctx->date_mode);
1675+
&c->pretty_ctx->date_mode,
1676+
msg + c->author.off, c->author.len);
16581677
case 'e': /* encoding */
16591678
if (c->commit_encoding)
16601679
strbuf_addstr(sb, c->commit_encoding);

0 commit comments

Comments
 (0)