Add a --cover-letter option to format-patch
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/5 Add more tests for format-patch
Tests -o, and an excessively long subject, and --thread, with and without --in-reply-to=
--- t/t4014-format-patch.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 45 insertions(+), 0 deletions(-)
t/t4014-format-patch.sh +45 -0
@@ -88,4 +88,49 @@ test_expect_success 'replay did not screw up the log message' ' ' +test_expect_success 'multiple files' ' + + rm -rf patches/ && + git checkout side && + git format-patch -o patches/ master && + ls patches/0001-Side-changes-1.patch patches/0002-Side-changes-2.patch patches/0003-Side-changes-3-with-n-backslash-n-in-it.patch +' + +test_expect_success 'thread' ' + + rm -rf patches/ && + git checkout side && + git format-patch --thread -o patches/ master && + FIRST_MID=$(grep "Message-Id:" patches/0001-* | sed "s/^[^<]*\(<[^>]*>\).*$/\1/") && + for i in patches/0002-* patches/0003-* + do + grep "References: $FIRST_MID" $i && + grep "In-Reply-To: $FIRST_MID" $i + done +' + +test_expect_success 'thread in-reply-to' ' + + rm -rf patches/ && + git checkout side && + git format-patch --in-reply-to="<test.message>" --thread -o patches/ master && + FIRST_MID="<test.message>" && + for i in patches/* + do + grep "References: $FIRST_MID" $i && + grep "In-Reply-To: $FIRST_MID" $i + done +' + +test_expect_success 'excessive subject' ' + + rm -rf patches/ && + git checkout side && + for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >>file && + git update-index file && + git commit -m "This is an excessively long subject line for a message due to the habit some projects have of not having a short, one-line subject at the start of the commit message, but rather sticking a whole paragraph right at the start as the only thing in the commit message. It had better not become the filename for the patch." && + git format-patch -o patches/ master..side && + ls patches/0004-This-is-an-excessively-long-subject-line-for-a-messa.patch +' + test_done
Signature · 1 line
1.5.4.1.191.gfbf10
PATCH 2/5 Improve message-id generation flow control for format-patch
In reply to a message not in the archive--- builtin-log.c | 29 ++++++++++++++--------------- revision.h | 2 +- 2 files changed, 15 insertions(+), 16 deletions(-)
builtin-log.c +14 -15
@@ -575,16 +575,19 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids, const cha o2->flags = flags2; } -static void gen_message_id (char *dest,unsigned int length,char *base) +static void gen_message_id (struct rev_info *info,char *base) {const char *committer =git_committer_info (IDENT_WARN_ON_NO_NAME );const char *email_start =strrchr (committer,'<' );const char *email_end =strrchr (committer,'>' ); -if (!email_start || !email_end || email_start > email_end -1 ) +struct strbuf buf; +if (!email_start || !email_end || email_start > email_end -1 )die ("Could not extract email from committer identity." ); -snprintf (dest, length,"%s.%lu.git.%.*s" , base, - (unsigned long )time (NULL ), - (int )(email_end - email_start -1 ), email_start +1 ); +strbuf_init (&buf,0 ); +strbuf_addf (&buf,"%s.%lu.git.%.*s" , base, + (unsigned long )time (NULL ), + (int )(email_end - email_start -1 ), email_start +1 ); + info->message_id =strbuf_detach (&buf,NULL ); }static const char *clean_message_id (const char *msg_id)
@@ -625,8 +628,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)const char *in_reply_to =NULL ;struct patch_ids ids;char *add_signoff =NULL ; -char message_id[1024 ]; -char ref_message_id[1024 ];git_config (git_format_config);init_revisions (&rev, prefix);
@@ -809,15 +810,13 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) rev.nr = total - nr + (start_number -1 );/* Make the second and subsequent mails replies to the first */ if (thread) { -if (nr == (total -2 )) { -strncpy (ref_message_id, message_id, -sizeof (ref_message_id)); - ref_message_id[sizeof (ref_message_id)-1 ]='\0' ; - rev.ref_message_id = ref_message_id; +if (rev.message_id) { +if (rev.ref_message_id) +free (rev.message_id); +else + rev.ref_message_id = rev.message_id; } -gen_message_id (message_id,sizeof (message_id), -sha1_to_hex (commit->object.sha1)); - rev.message_id = message_id; +gen_message_id (&rev,sha1_to_hex (commit->object.sha1)); }if (!use_stdout) if (reopen_stdout(commit, rev.nr, keep_subject,
revision.h +1 -1
@@ -74,7 +74,7 @@ struct rev_info {struct log_info *loginfo;int nr, total;const char *mime_boundary; -const char *message_id; +char *message_id;const char *ref_message_id;const char *add_signoff;const char *extra_headers;
Signature · 1 line
1.5.4.1.191.gfbf10
Re: [PATCH 2/5] Improve message-id generation flow control for format-patch
Hi,
revision.h struct rev_info { · line 80
Quoted 13 lines · Daniel Barkalow
revision.h +1
-1@@ -74,7 +74,7 @@ struct rev_info {struct log_info *loginfo;int nr, total;const char *mime_boundary; -const char *message_id; +char *message_id;const char *ref_message_id;const char *add_signoff;const char *extra_headers;
Mini-nit: technically, ref_message_id should be "char *", too.
Ciao,
Dscho
Re: [PATCH 2/5] Improve message-id generation flow control for format-patch
Quoted 4 lines · Johannes Schindelin
Hi,
On Mon, 18 Feb 2008, Daniel Barkalow wrote:
Quoted 15 lines
revision.h struct rev_info { · line 80
Quoted 13 lines
revision.h +1
-1@@ -74,7 +74,7 @@ struct rev_info {struct log_info *loginfo;int nr, total;const char *mime_boundary; -const char *message_id; +char *message_id;const char *ref_message_id;const char *add_signoff;const char *extra_headers;Mini-nit: technically,
ref_message_idshould be "char *", too.
I'd intended ref_message_id to just reference the string owned by a different message's message_id, but that doesn't really work with struct rev_info. I bet you'd like me to not leak memory out through ref_message_id, too. I think I want to see how the code to collect the set of commits in the series (for more capable generation of cover letter contents) goes before changing this either way.
(It's incidentally kind of amusing that you managed to convey the way you thought the code should be designed, different from how I'd designed it, through a note on whether a struct field should be const or not.)
-Daniel
*This .sig left intentionally blank*
Re: [PATCH 2/5] Improve message-id generation flow control for format-patch
Hi,
Quoted 27 lines · Daniel Barkalow
Quoted 17 lines · Johannes Schindelin
revision.h struct rev_info { · line 80
Quoted 13 lines · Daniel Barkalow
revision.h +1
-1@@ -74,7 +74,7 @@ struct rev_info {struct log_info *loginfo;int nr, total;const char *mime_boundary; -const char *message_id; +char *message_id;const char *ref_message_id;const char *add_signoff;const char *extra_headers;Mini-nit: technically,
ref_message_idshould be "char *", too.I'd intended
ref_message_idto just reference the string owned by a different message'smessage_id, but that doesn't really work with structrev_info. I bet you'd like me to not leak memory out throughref_message_id, too. I think I want to see how the code to collect the set of commits in the series (for more capable generation of cover letter contents) goes before changing this either way.
Quoted 3 lines
(It's incidentally kind of amusing that you managed to convey the way you thought the code should be designed, different from how I'd designed it, through a note on whether a struct field should be const or not.)
Hehe!
You're right in that the revision machinery needs some cleaning up. AFAIK there is no method yet to release the memory allocated during one revision walk (including the preparation).
And you're right that this should be done separately, so please kindly accept my apologies while I retract my comment.
Ciao,
Dscho
PATCH 3/5 Export some email and pretty-printing functions
In reply to a message not in the archiveThese will be used for generating the cover letter in addition to the patch emails.
--- commit.h | 15 +++++++ log-tree.c | 126 ++++++++++++++++++++++++++++++++--------------------------- log-tree.h | 2 + pretty.c | 34 ++++++++-------- 4 files changed, 102 insertions(+), 75 deletions(-)
commit.h +15 -0
@@ -71,6 +71,21 @@ extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit*, int abbrev, const char *subject, const char *after_subject, enum date_mode, int non_ascii_present); +void pp_user_info (const char *what,enum cmit_fmt fmt,struct strbuf *sb, +const char *line,enum date_mode dmode, +const char *encoding); +void pp_title_line (enum cmit_fmt fmt, +const char **msg_p, +struct strbuf *sb, +const char *subject, +const char *after_subject, +const char *encoding, +int plain_non_ascii); +void pp_remainder (enum cmit_fmt fmt, +const char **msg_p, +struct strbuf *sb, +int indent); +/** Removes the first commit from a list sorted by date, and adds all * of its parents.
log-tree.c +68 -58
138 lines not on this page · raw message
log-tree.h +2 -0
@@ -13,5 +13,7 @@ int log_tree_commit(struct rev_info *, struct commit *);int log_tree_opt_parse (struct rev_info *,const char **,int );void show_log (struct rev_info *opt,const char *sep);void show_decorations (struct commit *commit); +void log_write_email_headers (struct rev_info *opt,const char *name, +const char **subject_p,const char **extra_headers_p);#endif
pretty.c +17 -17
@@ -110,9 +110,9 @@ needquote:strbuf_addstr (sb,"?=" ); } -static void add_user_info (const char *what,enum cmit_fmt fmt,struct strbuf *sb, -const char *line,enum date_mode dmode, -const char *encoding) +void pp_user_info (const char *what,enum cmit_fmt fmt,struct strbuf *sb, +const char *line,enum date_mode dmode, +const char *encoding) {char *date;int namelen;
@@ -295,7 +295,7 @@ static void format_person_part(struct strbuf *sb, char part,/* * If it does not even have a '<' and '>', that is * quite a bogus commit author and we discard it; -* this is in line with add_user_info() that is used +* this is in line with pp_user_info() that is used * in the normal codepath. When end points at the '<' * that we found, it should have matching '>' later, * which means start (beginning of email address) must
@@ -643,23 +643,23 @@ static void pp_header(enum cmit_fmt fmt,*/ if (!memcmp (line,"author " ,7 )) {strbuf_grow (sb, linelen +80 ); -add_user_info ("Author" , fmt, sb, line +7 , dmode, encoding); +pp_user_info ("Author" , fmt, sb, line +7 , dmode, encoding); }if (!memcmp (line,"committer " ,10 ) && (fmt ==CMIT_FMT_FULL || fmt ==CMIT_FMT_FULLER )) {strbuf_grow (sb, linelen +80 ); -add_user_info ("Commit" , fmt, sb, line +10 , dmode, encoding); +pp_user_info ("Commit" , fmt, sb, line +10 , dmode, encoding); } } } -static void pp_title_line (enum cmit_fmt fmt, -const char **msg_p, -struct strbuf *sb, -const char *subject, -const char *after_subject, -const char *encoding, -int plain_non_ascii) +void pp_title_line (enum cmit_fmt fmt, +const char **msg_p, +struct strbuf *sb, +const char *subject, +const char *after_subject, +const char *encoding, +int plain_non_ascii) {struct strbuf title;
@@ -708,10 +708,10 @@ static void pp_title_line(enum cmit_fmt fmt,strbuf_release (&title); } -static void pp_remainder (enum cmit_fmt fmt, -const char **msg_p, -struct strbuf *sb, -int indent) +void pp_remainder (enum cmit_fmt fmt, +const char **msg_p, +struct strbuf *sb, +int indent) {int first =1 ;for (;;) {
Signature · 1 line
1.5.4.1.191.gfbf10
Re: [PATCH 3/5] Export some email and pretty-printing functions
Hi,
Quoted 2 lines · Daniel Barkalow
These will be used for generating the cover letter in addition to the patch emails.
I copied the hunks of log_write_email_headers() and used "git diff -w" to verify that only one thing changed: "sha1" was renamed to "name". It might make sense to rename it to "from", but then, I do not really care.
Ciao,
Dscho
Re: [PATCH 3/5] Export some email and pretty-printing functions
Quoted 10 lines · Johannes Schindelin
Hi,
Quoted 2 lines · Daniel Barkalow
These will be used for generating the cover letter in addition to the patch emails.
I copied the hunks of
log_write_email_headers()and used "git diff -w" to verify that only one thing changed: "sha1" was renamed to "name". It might make sense to rename it to "from", but then, I do not really care.
No, it's actually supposed to be the filename, I think. Beats me as to why it's used as the envelope from, but I'm not changing the logic there.
-Daniel
*This .sig left intentionally blank*
PATCH 4/5 Retain extra blank lines between the summary and the body
In reply to a message not in the archiveThis is so that it's possible to have a message that will generate an email with the first line blank. If the email you're generating is actually a template, you may have a single line filling in for a ~3-line paragraph, meaning that the space starts with a blank line, which was impossible before as output from the message-splitting code.
Furthermore, extra blank lines that aren't at the beginning of the body portion aren't stripped, so this is more consistant overall.
--- pretty.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-)
pretty.c +0 -4
@@ -713,7 +713,6 @@ void pp_remainder(enum cmit_fmt fmt, struct strbuf *sb, int indent) { - int first = 1;for (;;) {const char *line = *msg_p;int linelen =get_one_line (line);
@@ -723,12 +722,9 @@ void pp_remainder(enum cmit_fmt fmt,break ;if (is_empty_line (line, &linelen)) { -if (first) -continue ;if (fmt ==CMIT_FMT_SHORT )break ; } - first =0 ;strbuf_grow (sb, linelen + indent +20 );if (indent) {
Signature · 1 line
1.5.4.1.191.gfbf10
PATCH 5/5 Add a --cover-letter option to format-patch
In reply to a message not in the archiveIf --cover-letter is provided, generate a cover letter message before the patches, numbered 0.
Original patch thanks to Johannes Schindelin
--- Documentation/git-format-patch.txt | 20 +- builtin-log.c | 232 +++++++++++++++----- t/t4013-diff-various.sh | 1 + ...tch_--stdout_--cover-letter_-n_initial..master^ | 101 +++++++++ t/t4014-format-patch.sh | 26 +++ 5 files changed, 315 insertions(+), 65 deletions(-) create mode 100644 t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^
Documentation/git-format-patch.txt +13 -7
@@ -10,13 +10,14 @@ SYNOPSIS -------- [verse] 'git-format-patch' [-k] [-o <dir> | --stdout] [--thread] - [--attach[=<boundary>] | --inline[=<boundary>]] - [-s | --signoff] [<common diff options>] - [-n | --numbered | -N | --no-numbered] - [--start-number <n>] [--numbered-files] - [--in-reply-to=Message-Id] [--suffix=.<sfx>] - [--ignore-if-in-upstream] - [--subject-prefix=Subject-Prefix] + [--attach[=<boundary>] | --inline[=<boundary>]] + [-s | --signoff] [<common diff options>] + [-n | --numbered | -N | --no-numbered] + [--start-number <n>] [--numbered-files] + [--in-reply-to=Message-Id] [--suffix=.<sfx>] + [--ignore-if-in-upstream] + [--subject-prefix=Subject-Prefix] + [--cover-letter] [ <since> | <revision range> ] DESCRIPTION
@@ -135,6 +136,11 @@ include::diff-options.txt[] allows for useful naming of a patch series, and can be combined with the --numbered option. +--cover-letter:: + Generate a cover letter template. You still have to fill in + a description, but the shortlog and the diffstat will be + generated for you. + --suffix=.<sfx>:: Instead of using `.patch` as the suffix for generated filenames, use specified suffix. A common alternative is
builtin-log.c +174 -58
304 lines not on this page · raw message
t/t4013-diff-various.sh +1 -0
@@ -245,6 +245,7 @@ format-patch --inline --stdout initial..master format-patch --inline --stdout --subject-prefix=TESTCASE initial..master config format.subjectprefix DIFFERENT_PREFIX format-patch --inline --stdout initial..master^^ +format-patch --stdout --cover-letter -n initial..master^ diff --abbrev initial..side diff -r initial..side
t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^ new file +101 -0
101 lines not on this page · raw message
t/t4014-format-patch.sh +26 -0
@@ -122,6 +122,32 @@ test_expect_success 'thread in-reply-to' ' done ' +test_expect_success 'thread cover-letter' ' + + rm -rf patches/ && + git checkout side && + git format-patch --cover-letter --thread -o patches/ master && + FIRST_MID=$(grep "Message-Id:" patches/0000-* | sed "s/^[^<]*\(<[^>]*>\).*$/\1/") && + for i in patches/0001-* patches/0002-* patches/0003-* + do + grep "References: $FIRST_MID" $i && + grep "In-Reply-To: $FIRST_MID" $i + done +' + +test_expect_success 'thread cover-letter in-reply-to' ' + + rm -rf patches/ && + git checkout side && + git format-patch --cover-letter --in-reply-to="<test.message>" --thread -o patches/ master && + FIRST_MID="<test.message>" && + for i in patches/* + do + grep "References: $FIRST_MID" $i && + grep "In-Reply-To: $FIRST_MID" $i + done +' + test_expect_success 'excessive subject' ' rm -rf patches/ &&
Signature · 1 line
1.5.4.1.191.gfbf10
Quoted 10 lines · Daniel Barkalow
(quoted diff) +1
-0+ const char *body = "*** SUBJECT HERE ***\n\n\n*** BLURB HERE ***\n";t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^ new file +2
-0@@ -0,0 +1,101 @@ +$ git format-patch --stdout --cover-letter -n initial..master^ +From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001
t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^ line 12
Quoted 10 lines
t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^ new file +10
-0+From: C O Mitter <[email protected]> +Date: Mon, 26 Jun 2006 00:05:00 +0000 +Subject: [DIFFERENT_PREFIX 0/2] *** SUBJECT HERE *** + + +*** BLURB HERE *** + +A U Thor (2): + Second + Third
I still disagree with your earlier point on the extra blank line here.
When we give commit log template, we do leave an extra blank line before we start the template material "# Please enter ...", to ease typing, but it is different. The template material does not have to be removed by the end-user, so giving a blank line upfront and starting the editor at that line is a usability improvement, compared to the case where there is none.
But this "*** BLURB HERE ***" needs to be removed when the user edits the cover-letter, and I really do not see any reason to have an extra blank line in front of it.
Incidentally, I strongly suspect that if you do not have that extra blank line, we would not even need to have the [PATCH 4/5] (which is a slight regression) in the series.
So how about this squashed in, with [PATCH 4/5] skipped?
builtin-log.c | 2 +- ...tch_--stdout_--cover-letter_-n_initial..master^ | 1 - 2 files changed, 1 insertions(+), 2 deletions(-)
builtin-log.c +1 -1
@@ -629,7 +629,7 @@ static void make_cover_letter(struct rev_info *rev,const char *origin_sha1, *head_sha1;const char *argv[7 ];const char *subject_start =NULL ; -const char *body ="*** SUBJECT HERE ***\n\n\n*** BLURB HERE ***\n" ; +const char *body ="*** SUBJECT HERE ***\n\n*** BLURB HERE ***\n" ;const char *msg;const char *extra_headers = rev->extra_headers;struct strbuf sb;
t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^ +0 -1
@@ -4,7 +4,6 @@ From: C O Mitter <[email protected]> Date: Mon, 26 Jun 2006 00:05:00 +0000 Subject: [DIFFERENT_PREFIX 0/2] *** SUBJECT HERE *** - *** BLURB HERE *** A U Thor (2):
Quoted 37 lines · Junio C Hamano
Quoted 10 lines · Daniel Barkalow
(quoted diff) +1
-0+ const char *body = "*** SUBJECT HERE ***\n\n\n*** BLURB HERE ***\n";t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^ new file +2
-0@@ -0,0 +1,101 @@ +$ git format-patch --stdout --cover-letter -n initial..master^ +From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^ line 12
Quoted 10 lines
t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^ new file +10
-0+From: C O Mitter <[email protected]> +Date: Mon, 26 Jun 2006 00:05:00 +0000 +Subject: [DIFFERENT_PREFIX 0/2] *** SUBJECT HERE *** + + +*** BLURB HERE *** + +A U Thor (2): + Second + ThirdI still disagree with your earlier point on the extra blank line here.
When we give commit log template, we do leave an extra blank line before we start the template material "# Please enter ...", to ease typing, but it is different. The template material does not have to be removed by the end-user, so giving a blank line upfront and starting the editor at that line is a usability improvement, compared to the case where there is none.
But this "*** BLURB HERE ***" needs to be removed when the user edits the cover-letter, and I really do not see any reason to have an extra blank line in front of it.
Quoted 5 lines
Incidentally, I strongly suspect that if you do not have that extra blank line, we would not even need to have the [PATCH 4/5] (which is a slight regression) in the series.
So how about this squashed in, with [PATCH 4/5] skipped?
Sure. I still like the extra line, but it's not that big a deal. (And I still think it's odd that the code removes extra blank lines from that spot but not elsewhere, but likewise not a big deal)
-Daniel
*This .sig left intentionally blank*