Skip to content

Commit 4701026

Browse files
peffgitster
authored andcommitted
commit: use split_ident_line to compare author/committer
Instead of string-wise comparing the author/committer lines with their timestamps truncated, we can use split_ident_line and ident_cmp. These functions are more robust than our ad-hoc parsing, though in practice it should not matter, as we just generated these ident lines ourselves. However, this will also allow us easy access to the timestamp and tz fields in future patches. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b4f86a4 commit 4701026

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

builtin/commit.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -585,13 +585,11 @@ static void determine_author_info(struct strbuf *author_ident)
585585
}
586586
}
587587

588-
static char *cut_ident_timestamp_part(char *string)
588+
static void split_ident_or_die(struct ident_split *id, const struct strbuf *buf)
589589
{
590-
char *ket = strrchr(string, '>');
591-
if (!ket || ket[1] != ' ')
592-
die(_("Malformed ident string: '%s'"), string);
593-
*++ket = '\0';
594-
return ket;
590+
if (split_ident_line(id, buf->buf, buf->len) ||
591+
!sane_ident_split(id))
592+
die(_("Malformed ident string: '%s'"), buf->buf);
595593
}
596594

597595
static int prepare_to_commit(const char *index_file, const char *prefix,
@@ -755,7 +753,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
755753
if (use_editor && include_status) {
756754
int ident_shown = 0;
757755
int saved_color_setting;
758-
char *ai_tmp, *ci_tmp;
756+
struct ident_split ci, ai;
757+
759758
if (whence != FROM_COMMIT) {
760759
if (cleanup_mode == CLEANUP_SCISSORS)
761760
wt_status_add_cut_line(s->fp);
@@ -795,21 +794,24 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
795794
status_printf_ln(s, GIT_COLOR_NORMAL,
796795
"%s", only_include_assumed);
797796

798-
ai_tmp = cut_ident_timestamp_part(author_ident->buf);
799-
ci_tmp = cut_ident_timestamp_part(committer_ident.buf);
800-
if (strcmp(author_ident->buf, committer_ident.buf))
797+
split_ident_or_die(&ai, author_ident);
798+
split_ident_or_die(&ci, &committer_ident);
799+
800+
if (ident_cmp(&ai, &ci))
801801
status_printf_ln(s, GIT_COLOR_NORMAL,
802802
_("%s"
803-
"Author: %s"),
803+
"Author: %.*s <%.*s>"),
804804
ident_shown++ ? "" : "\n",
805-
author_ident->buf);
805+
(int)(ai.name_end - ai.name_begin), ai.name_begin,
806+
(int)(ai.mail_end - ai.mail_begin), ai.mail_begin);
806807

807808
if (!committer_ident_sufficiently_given())
808809
status_printf_ln(s, GIT_COLOR_NORMAL,
809810
_("%s"
810-
"Committer: %s"),
811+
"Committer: %.*s <%.*s>"),
811812
ident_shown++ ? "" : "\n",
812-
committer_ident.buf);
813+
(int)(ci.name_end - ci.name_begin), ci.name_begin,
814+
(int)(ci.mail_end - ci.mail_begin), ci.mail_begin);
813815

814816
if (ident_shown)
815817
status_printf_ln(s, GIT_COLOR_NORMAL, "");
@@ -818,9 +820,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
818820
s->use_color = 0;
819821
commitable = run_status(s->fp, index_file, prefix, 1, s);
820822
s->use_color = saved_color_setting;
821-
822-
*ai_tmp = ' ';
823-
*ci_tmp = ' ';
824823
} else {
825824
unsigned char sha1[20];
826825
const char *parent = "HEAD";

0 commit comments

Comments
 (0)