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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
May 1, 2014 at 21:06 UTC
4701026352ada1ebc36532272ca1e12897b1de11
1 file changed
+16
-17
builtin/commit.c
+16
-17
@@ -585,13 +585,11 @@ static void determine_author_info(struct strbuf *author_ident)
585
}
586
}
587
588
-static char *cut_ident_timestamp_part(char *string)
588
+static void split_ident_or_die(struct ident_split *id, const struct strbuf *buf)
589
{
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);
593
}
594
595
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,
753
if (use_editor && include_status) {
754
int ident_shown = 0;
755
int saved_color_setting;
758
- char *ai_tmp, *ci_tmp;
756
+ struct ident_split ci, ai;
757
+
758
if (whence != FROM_COMMIT) {
759
if (cleanup_mode == CLEANUP_SCISSORS)
760
wt_status_add_cut_line(s->fp);
@@ -795,21 +794,24 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
794
status_printf_ln(s, GIT_COLOR_NORMAL,
795
"%s", only_include_assumed);
796
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))
801
status_printf_ln(s, GIT_COLOR_NORMAL,
802
_("%s"
803
- "Author: %s"),
803
+ "Author: %.*s <%.*s>"),
804
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);
807
808
if (!committer_ident_sufficiently_given())
809
status_printf_ln(s, GIT_COLOR_NORMAL,
810
_("%s"
810
- "Committer: %s"),
811
+ "Committer: %.*s <%.*s>"),
812
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);
815
816
if (ident_shown)
817
status_printf_ln(s, GIT_COLOR_NORMAL, "");
@@ -818,9 +820,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
820
s->use_color = 0;
821
commitable = run_status(s->fp, index_file, prefix, 1, s);
822
s->use_color = saved_color_setting;
821
-
822
- *ai_tmp = ' ';
823
- *ci_tmp = ' ';
823
} else {
824
unsigned char sha1[20];
825
const char *parent = "HEAD";