From 43ae9f47ab8a7762d914e91d6f57b79126986640 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 21 May 2012 19:10:08 -0400 Subject: format-patch: use default email for generating message ids We try to generate a sane message id for cover letters and threading by appending some changing bits to the front of the user's email address. The current code parses the email out of the results of git_committer_info, but we can do this much more easily by just calling ident_default_email ourselves. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/log.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'builtin/log.c') diff --git a/builtin/log.c b/builtin/log.c index 690caa7830..656bddfb03 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -737,15 +737,9 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids, const cha 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, '>'); struct strbuf buf = STRBUF_INIT; - if (!email_start || !email_end || email_start > email_end - 1) - die(_("Could not extract email from committer identity.")); - strbuf_addf(&buf, "%s.%lu.git.%.*s", base, - (unsigned long) time(NULL), - (int)(email_end - email_start - 1), email_start + 1); + strbuf_addf(&buf, "%s.%lu.git.%s", base, + (unsigned long) time(NULL), ident_default_email()); info->message_id = strbuf_detach(&buf, NULL); } -- cgit v1.2.3 From a21c2f94fb6e74ebddb5c78cf6b5f68983646530 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 21 May 2012 19:10:32 -0400 Subject: format-patch: refactor get_patch_filename The get_patch_filename function expects a commit argument and uses it to get the sanitized subject line when making a patch filename. However, we also want to use this same function for the cover letter, which does not have a commit object. The current solution is to create a fake commit with the subject "cover letter". Instead, let's make the get_patch_filename interface more flexibile, and allow passing a direct subject. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/log.c | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) (limited to 'builtin/log.c') diff --git a/builtin/log.c b/builtin/log.c index 656bddfb03..8010a4045e 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -663,7 +663,8 @@ static FILE *realstdout = NULL; static const char *output_directory = NULL; static int outdir_offset; -static int reopen_stdout(struct commit *commit, struct rev_info *rev, int quiet) +static int reopen_stdout(struct commit *commit, const char *subject, + struct rev_info *rev, int quiet) { struct strbuf filename = STRBUF_INIT; int suffix_len = strlen(fmt_patch_suffix) + 1; @@ -677,7 +678,7 @@ static int reopen_stdout(struct commit *commit, struct rev_info *rev, int quiet) strbuf_addch(&filename, '/'); } - get_patch_filename(commit, rev->nr, fmt_patch_suffix, &filename); + get_patch_filename(commit, subject, rev->nr, fmt_patch_suffix, &filename); if (!quiet) fprintf(realstdout, "%s\n", filename.buf + outdir_offset); @@ -778,7 +779,6 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, const char *encoding = "UTF-8"; struct diff_options opts; int need_8bit_cte = 0; - struct commit *commit = NULL; struct pretty_print_context pp = {0}; if (rev->commit_format != CMIT_FMT_EMAIL) @@ -786,31 +786,10 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, committer = git_committer_info(0); - if (!numbered_files) { - /* - * We fake a commit for the cover letter so we get the filename - * desired. - */ - commit = xcalloc(1, sizeof(*commit)); - commit->buffer = xmalloc(400); - snprintf(commit->buffer, 400, - "tree 0000000000000000000000000000000000000000\n" - "parent %s\n" - "author %s\n" - "committer %s\n\n" - "cover letter\n", - sha1_to_hex(head->object.sha1), committer, committer); - } - - if (!use_stdout && reopen_stdout(commit, rev, quiet)) + if (!use_stdout && + reopen_stdout(NULL, numbered_files ? NULL : "cover-letter", rev, quiet)) return; - if (commit) { - - free(commit->buffer); - free(commit); - } - log_write_email_headers(rev, head, &pp.subject, &pp.after_subject, &need_8bit_cte); @@ -1405,8 +1384,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) gen_message_id(&rev, sha1_to_hex(commit->object.sha1)); } - if (!use_stdout && reopen_stdout(numbered_files ? NULL : commit, - &rev, quiet)) + if (!use_stdout && + reopen_stdout(numbered_files ? NULL : commit, NULL, &rev, quiet)) die(_("Failed to create output files")); shown = log_tree_commit(&rev, commit); free(commit->buffer); -- cgit v1.2.3 From c73f384f92dcb0d7111533ed21f6c2dc9fcc323b Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 24 May 2012 19:28:25 -0400 Subject: format-patch: use GIT_COMMITTER_EMAIL in message ids Before commit 43ae9f4, we generated the tail of a message id by calling git_committer_info and parsing the email out of the result. 43ae9f4 changed to use ident_default_email directly, so we didn't have to bother with parsing. As a side effect, it meant we no longer used GIT_COMMITTER_EMAIL at all. In general, this is probably reasonable behavior. Either the default email is sane on your system, or you are using user.email to provide something sane. The exception is if you rely on GIT_COMMITTER_EMAIL being set all the time to override the bogus generated email. This is unlikely to match anybody's real-life setup, but we do use it in the test environment. And furthermore, it's what we have always done, and the change in 43ae9f4 was about cleaning up, not fixing any bug; we should be conservative and keep the behavior identical. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/log.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'builtin/log.c') diff --git a/builtin/log.c b/builtin/log.c index 8010a4045e..4538309d02 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -740,7 +740,8 @@ static void gen_message_id(struct rev_info *info, char *base) { struct strbuf buf = STRBUF_INIT; strbuf_addf(&buf, "%s.%lu.git.%s", base, - (unsigned long) time(NULL), ident_default_email()); + (unsigned long) time(NULL), + git_committer_info(IDENT_NO_NAME|IDENT_NO_DATE)); info->message_id = strbuf_detach(&buf, NULL); } -- cgit v1.2.3 From f9bc573fdaeaf8621008f3f49aaaa64869791691 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 24 May 2012 19:28:40 -0400 Subject: ident: rename IDENT_ERROR_ON_NO_NAME to IDENT_STRICT Callers who ask for ERROR_ON_NO_NAME are not so much concerned that the name will be blank (because, after all, we will fall back to using the username), but rather it is a check to make sure that low-quality identities do not end up in things like commit messages or emails (whereas it is OK for them to end up in things like reflogs). When future commits add more quality checks on the identity, each of these callers would want to use those checks, too. Rather than modify each of them later to add a new flag, let's refactor the flag. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin/log.c') diff --git a/builtin/log.c b/builtin/log.c index 4538309d02..d86bca34dd 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1147,7 +1147,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) if (do_signoff) { const char *committer; const char *endpos; - committer = git_committer_info(IDENT_ERROR_ON_NO_NAME); + committer = git_committer_info(IDENT_STRICT); endpos = strchr(committer, '>'); if (!endpos) die(_("bogus committer info %s"), committer); -- cgit v1.2.3 From 59f9b8a9a95cbcf4f6a5123cac04dc5073a8d0cc Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 24 May 2012 19:32:52 -0400 Subject: format-patch: do not use bogus email addresses in message ids We can ask git_committer_info to be strict about coming up with an email, which will die automatically on a poorly configured machine. This is better than letting invalid message-ids into the wild. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin/log.c') diff --git a/builtin/log.c b/builtin/log.c index d86bca34dd..906dca475a 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -741,7 +741,7 @@ static void gen_message_id(struct rev_info *info, char *base) struct strbuf buf = STRBUF_INIT; strbuf_addf(&buf, "%s.%lu.git.%s", base, (unsigned long) time(NULL), - git_committer_info(IDENT_NO_NAME|IDENT_NO_DATE)); + git_committer_info(IDENT_NO_NAME|IDENT_NO_DATE|IDENT_STRICT)); info->message_id = strbuf_detach(&buf, NULL); } -- cgit v1.2.3