diff options
author | Junio C Hamano <gitster@pobox.com> | 2013-10-28 10:18:43 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-10-28 10:18:43 -0700 |
commit | da212eabec969f0a45475b6a962b06c103a3ec65 (patch) | |
tree | 30ba87a33028ff84b6a2c6ba61a60e8bb4788ed4 | |
parent | 77bc4302dc93ac33891c72df59d9426eb6d06d0b (diff) | |
parent | 662cc30cd048f2ccd7ba8d1540e0768ae264c0dd (diff) | |
download | git-da212eabec969f0a45475b6a962b06c103a3ec65.tar.gz |
Merge branch 'jk/format-patch-from' into maint
"format-patch --from=<whom>" forgot to omit unnecessary in-body from
line, i.e. when <whom> is the same as the real author.
* jk/format-patch-from:
format-patch: print in-body "From" only when needed
-rw-r--r-- | cache.h | 9 | ||||
-rw-r--r-- | ident.c | 29 | ||||
-rw-r--r-- | pretty.c | 2 | ||||
-rwxr-xr-x | t/t4014-format-patch.sh | 10 |
4 files changed, 49 insertions, 1 deletions
@@ -966,6 +966,15 @@ struct ident_split { */ extern int split_ident_line(struct ident_split *, const char *, int); +/* + * Compare split idents for equality or strict ordering. Note that we + * compare only the ident part of the line, ignoring any timestamp. + * + * Because there are two fields, we must choose one as the primary key; we + * currently arbitrarily pick the email. + */ +extern int ident_cmp(const struct ident_split *, const struct ident_split *); + struct checkout { const char *base_dir; int base_dir_len; @@ -402,3 +402,32 @@ int git_ident_config(const char *var, const char *value, void *data) return 0; } + +static int buf_cmp(const char *a_begin, const char *a_end, + const char *b_begin, const char *b_end) +{ + int a_len = a_end - a_begin; + int b_len = b_end - b_begin; + int min = a_len < b_len ? a_len : b_len; + int cmp; + + cmp = memcmp(a_begin, b_begin, min); + if (cmp) + return cmp; + + return a_len - b_len; +} + +int ident_cmp(const struct ident_split *a, + const struct ident_split *b) +{ + int cmp; + + cmp = buf_cmp(a->mail_begin, a->mail_end, + b->mail_begin, b->mail_end); + if (cmp) + return cmp; + + return buf_cmp(a->name_begin, a->name_end, + b->name_begin, b->name_end); +} @@ -432,7 +432,7 @@ void pp_user_info(struct pretty_print_context *pp, map_user(pp->mailmap, &mailbuf, &maillen, &namebuf, &namelen); if (pp->fmt == CMIT_FMT_EMAIL) { - if (pp->from_ident) { + if (pp->from_ident && ident_cmp(pp->from_ident, &ident)) { struct strbuf buf = STRBUF_INIT; strbuf_addstr(&buf, "From: "); diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 668933bfb2..8f272bce84 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -1000,6 +1000,16 @@ test_expect_success '--from uses committer ident' ' test_cmp expect patch.head ' +test_expect_success '--from omits redundant in-body header' ' + git format-patch -1 --stdout --from="A U Thor <author@example.com>" >patch && + cat >expect <<-\EOF && + From: A U Thor <author@example.com> + + EOF + sed -ne "/^From:/p; /^$/p; /^---$/q" <patch >patch.head && + test_cmp expect patch.head +' + test_expect_success 'in-body headers trigger content encoding' ' GIT_AUTHOR_NAME="éxötìc" test_commit exotic && test_when_finished "git reset --hard HEAD^" && |