summaryrefslogtreecommitdiff
path: root/pretty.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-02-21 12:05:02 -0800
committerJunio C Hamano <gitster@pobox.com>2013-04-22 07:59:22 -0700
commitbe1a07fe27695081537d31748b989f86c82383cc (patch)
tree36bec251b5259cf89c85a47158e6f75070726d43 /pretty.c
parent47d6c5f2c112df55997742eab8d974bfa1cf7b3e (diff)
downloadgit-jc/format-patch.tar.gz
format-patch: --inline-singlejc/format-patch
Some people may find it convenient to append a simple patch at the bottom of a discussion e-mail separated by a "scissors" mark, ready to be applied with "git am -c". Introduce "--inline-single" option to format-patch to do so. A typical usage example might be to start 'f'ollow-up to a discussion, write your message, conclude with "a patch to do so may look like this.", and then \C-u M-! git format-patch --inline-single -1 HEAD <ENTER> if you are an Emacs user. Users of other MUA's may want to consult their manuals to find an equivalent command to append output from an external command to the message being composed. It does not make any sense to use this mode when formatting multiple patches, or to combine this with options such as --attach, --inline, and --cover-letter, so some of such uses are forbidden. There may be more insane combination the check in this patch may not even bother to reject. Caveat emptor. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pretty.c')
-rw-r--r--pretty.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/pretty.c b/pretty.c
index d3a82d22d3..4a0495430a 100644
--- a/pretty.c
+++ b/pretty.c
@@ -393,6 +393,29 @@ static void add_rfc2047(struct strbuf *sb, const char *line, size_t len,
strbuf_addstr(sb, "?=");
}
+static int is_current_user(const struct pretty_print_context *pp,
+ const char *email, size_t emaillen,
+ const char *name, size_t namelen)
+{
+ const char *me = git_committer_info(0);
+ const char *myname, *mymail;
+ size_t mynamelen, mymaillen;
+ struct ident_split ident;
+
+ if (split_ident_line(&ident, me, strlen(me)))
+ return 0; /* play safe, as we do not know */
+ mymail = ident.mail_begin;
+ mymaillen = ident.mail_end - ident.mail_begin;
+ myname = ident.name_begin;
+ mynamelen = ident.name_end - ident.name_begin;
+ if (pp->mailmap)
+ map_user(pp->mailmap, &mymail, &mymaillen, &myname, &mynamelen);
+ return (mymaillen == emaillen &&
+ mynamelen == namelen &&
+ !memcmp(mymail, email, emaillen) &&
+ !memcmp(myname, name, namelen));
+}
+
void pp_user_info(const struct pretty_print_context *pp,
const char *what, struct strbuf *sb,
const char *line, const char *encoding)
@@ -422,7 +445,6 @@ void pp_user_info(const struct pretty_print_context *pp,
if (split_ident_line(&ident, line, linelen))
return;
-
mailbuf = ident.mail_begin;
maillen = ident.mail_end - ident.mail_begin;
namebuf = ident.name_begin;
@@ -431,6 +453,9 @@ void pp_user_info(const struct pretty_print_context *pp,
if (pp->mailmap)
map_user(pp->mailmap, &mailbuf, &maillen, &namebuf, &namelen);
+ if (pp->inline_single && is_current_user(pp, mailbuf, maillen, namebuf, namelen))
+ return;
+
strbuf_init(&mail, 0);
strbuf_init(&name, 0);