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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed May 24, 2012 at 19:28 UTC f9bc573fdaeaf8621008f3f49aaaa64869791691
9 files changed +14 -15
builtin/commit.c
+1 -2
@@ -526,8 +526,7 @@ static void determine_author_info(struct strbuf *author_ident)
526
527 if (force_date)
528 date = force_date;
529 - strbuf_addstr(author_ident, fmt_ident(name, email, date,
530 - IDENT_ERROR_ON_NO_NAME));
529 + strbuf_addstr(author_ident, fmt_ident(name, email, date, IDENT_STRICT));
530 if (!split_ident_line(&author, author_ident->buf, author_ident->len)) {
531 export_one("GIT_AUTHOR_NAME", author.name_begin, author.name_end, 0);
532 export_one("GIT_AUTHOR_EMAIL", author.mail_begin, author.mail_end, 0);
builtin/log.c
+1 -1
@@ -1147,7 +1147,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1147 if (do_signoff) {
1148 const char *committer;
1149 const char *endpos;
1150 - committer = git_committer_info(IDENT_ERROR_ON_NO_NAME);
1150 + committer = git_committer_info(IDENT_STRICT);
1151 endpos = strchr(committer, '>');
1152 if (!endpos)
1153 die(_("bogus committer info %s"), committer);
builtin/merge.c
+2 -2
@@ -1447,7 +1447,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1447 refresh_cache(REFRESH_QUIET);
1448 if (allow_trivial && !fast_forward_only) {
1449 /* See if it is really trivial. */
1450 - git_committer_info(IDENT_ERROR_ON_NO_NAME);
1450 + git_committer_info(IDENT_STRICT);
1451 printf(_("Trying really trivial in-index merge...\n"));
1452 if (!read_tree_trivial(common->item->object.sha1,
1453 head_commit->object.sha1,
@@ -1490,7 +1490,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1490 die(_("Not possible to fast-forward, aborting."));
1491
1492 /* We are going to make a new commit. */
1493 - git_committer_info(IDENT_ERROR_ON_NO_NAME);
1493 + git_committer_info(IDENT_STRICT);
1494
1495 /*
1496 * At this point, we need a real merge. No matter what strategy
builtin/tag.c
+1 -1
@@ -332,7 +332,7 @@ static void create_tag(const unsigned char *object, const char *tag,
332 sha1_to_hex(object),
333 typename(type),
334 tag,
335 - git_committer_info(IDENT_ERROR_ON_NO_NAME));
335 + git_committer_info(IDENT_STRICT));
336
337 if (header_len > sizeof(header_buf) - 1)
338 die(_("tag header too big."));
builtin/var.c
+2 -2
@@ -11,7 +11,7 @@ static const char *editor(int flag)
11 {
12 const char *pgm = git_editor();
13
14 - if (!pgm && flag & IDENT_ERROR_ON_NO_NAME)
14 + if (!pgm && flag & IDENT_STRICT)
15 die("Terminal is dumb, but EDITOR unset");
16
17 return pgm;
@@ -55,7 +55,7 @@ static const char *read_var(const char *var)
55 val = NULL;
56 for (ptr = git_vars; ptr->read; ptr++) {
57 if (strcmp(var, ptr->name) == 0) {
58 - val = ptr->read(IDENT_ERROR_ON_NO_NAME);
58 + val = ptr->read(IDENT_STRICT);
59 break;
60 }
61 }
cache.h
+1 -1
@@ -887,7 +887,7 @@ unsigned long approxidate_careful(const char *, int *);
887 unsigned long approxidate_relative(const char *date, const struct timeval *now);
888 enum date_mode parse_date_format(const char *format);
889
890 -#define IDENT_ERROR_ON_NO_NAME 1
890 +#define IDENT_STRICT 1
891 #define IDENT_NO_DATE 2
892 #define IDENT_NO_NAME 4
893 extern const char *git_author_info(int);
commit.c
+2 -2
@@ -1154,9 +1154,9 @@ int commit_tree_extended(const struct strbuf *msg, unsigned char *tree,
1154
1155 /* Person/date information */
1156 if (!author)
1157 - author = git_author_info(IDENT_ERROR_ON_NO_NAME);
1157 + author = git_author_info(IDENT_STRICT);
1158 strbuf_addf(&buffer, "author %s\n", author);
1159 - strbuf_addf(&buffer, "committer %s\n", git_committer_info(IDENT_ERROR_ON_NO_NAME));
1159 + strbuf_addf(&buffer, "committer %s\n", git_committer_info(IDENT_STRICT));
1160 if (!encoding_is_utf8)
1161 strbuf_addf(&buffer, "encoding %s\n", git_commit_encoding);
1162
gpg-interface.c
+1 -1
@@ -30,7 +30,7 @@ const char *get_signing_key(void)
30 {
31 if (configured_signing_key)
32 return configured_signing_key;
33 - return git_committer_info(IDENT_ERROR_ON_NO_NAME|IDENT_NO_DATE);
33 + return git_committer_info(IDENT_STRICT|IDENT_NO_DATE);
34 }
35
36 /*
ident.c
+3 -3
@@ -267,7 +267,7 @@ const char *fmt_ident(const char *name, const char *email,
267 {
268 static struct strbuf ident = STRBUF_INIT;
269 char date[50];
270 - int error_on_no_name = (flag & IDENT_ERROR_ON_NO_NAME);
270 + int strict = (flag & IDENT_STRICT);
271 int want_date = !(flag & IDENT_NO_DATE);
272 int want_name = !(flag & IDENT_NO_NAME);
273
@@ -279,7 +279,7 @@ const char *fmt_ident(const char *name, const char *email,
279 if (want_name && !*name) {
280 struct passwd *pw;
281
282 - if (error_on_no_name) {
282 + if (strict) {
283 if (name == git_default_name.buf)
284 fputs(env_hint, stderr);
285 die("empty ident name (for <%s>) not allowed", email);
@@ -314,7 +314,7 @@ const char *fmt_ident(const char *name, const char *email,
314
315 const char *fmt_name(const char *name, const char *email)
316 {
317 - return fmt_ident(name, email, NULL, IDENT_ERROR_ON_NO_NAME | IDENT_NO_DATE);
317 + return fmt_ident(name, email, NULL, IDENT_STRICT | IDENT_NO_DATE);
318 }
319
320 const char *git_author_info(int flag)