summaryrefslogtreecommitdiff
path: root/ident.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2013-09-20 06:16:28 -0400
committerJunio C Hamano <gitster@pobox.com>2013-09-20 11:09:51 -0700
commit662cc30cd048f2ccd7ba8d1540e0768ae264c0dd (patch)
treed05ea629e93ae982f0bb6941e5c052a8b4f9f348 /ident.c
parenta90804752f6ab2b911882d47fafb6c2b78f447c3 (diff)
downloadgit-662cc30cd048f2ccd7ba8d1540e0768ae264c0dd.tar.gz
format-patch: print in-body "From" only when neededjk/format-patch-from
Commit a908047 taught format-patch the "--from" option, which places the author ident into an in-body from header, and uses the committer ident in the rfc822 from header. The documentation claims that it will omit the in-body header when it is the same as the rfc822 header, but the code never implemented that behavior. This patch completes the feature by comparing the two idents and doing nothing when they are the same (this is the same as simply omitting the in-body header, as the two are by definition indistinguishable in this case). This makes it reasonable to turn on "--from" all the time (if it matches your particular workflow), rather than only using it when exporting other people's patches. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'ident.c')
-rw-r--r--ident.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/ident.c b/ident.c
index 1c123e685f..b29f81f83a 100644
--- a/ident.c
+++ b/ident.c
@@ -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);
+}