summaryrefslogtreecommitdiff
path: root/ident.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-02-04 09:12:38 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-02-04 21:18:48 (GMT)
commit59f929596b611d88270ac0fd3ea132b32d66d460 (patch)
tree85e899a9409daa95fbb0a73e50c6c46bdb9d5125 /ident.c
parent754884255bb580df159e58defa81cdd30b5c430c (diff)
downloadgit-59f929596b611d88270ac0fd3ea132b32d66d460.zip
git-59f929596b611d88270ac0fd3ea132b32d66d460.tar.gz
git-59f929596b611d88270ac0fd3ea132b32d66d460.tar.bz2
fmt_ident: refactor strictness checks
This function has evolved quite a bit over time, and as a result, the logic for "is this an OK ident" has been sprinkled throughout. This ends up with a lot of redundant conditionals, like checking want_name repeatedly. Worse, we want to know in many cases whether we are using the "default" ident, and we do so by comparing directly to the global strbuf, which violates the abstraction of the ident_default_* functions. Let's reorganize the function into a hierarchy of conditionals to handle similar cases together. The only case that doesn't just work naturally for this is that of an empty name, where our advice is different based on whether we came from ident_default_name() or not. We can use a simple flag to cover this case. 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.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/ident.c b/ident.c
index daf7e1e..f796206 100644
--- a/ident.c
+++ b/ident.c
@@ -345,32 +345,34 @@ const char *fmt_ident(const char *name, const char *email,
int want_date = !(flag & IDENT_NO_DATE);
int want_name = !(flag & IDENT_NO_NAME);
- if (want_name && !name)
- name = ident_default_name();
- if (!email)
- email = ident_default_email();
-
- if (want_name && !*name) {
- struct passwd *pw;
-
- if (strict) {
- if (name == git_default_name.buf)
+ if (want_name) {
+ int using_default = 0;
+ if (!name) {
+ name = ident_default_name();
+ using_default = 1;
+ if (strict && default_name_is_bogus) {
fputs(env_hint, stderr);
- die("empty ident name (for <%s>) not allowed", email);
+ die("unable to auto-detect name (got '%s')", name);
+ }
+ }
+ if (!*name) {
+ struct passwd *pw;
+ if (strict) {
+ if (using_default)
+ fputs(env_hint, stderr);
+ die("empty ident name (for <%s>) not allowed", email);
+ }
+ pw = xgetpwuid_self(NULL);
+ name = pw->pw_name;
}
- pw = xgetpwuid_self(NULL);
- name = pw->pw_name;
- }
-
- if (want_name && strict &&
- name == git_default_name.buf && default_name_is_bogus) {
- fputs(env_hint, stderr);
- die("unable to auto-detect name (got '%s')", name);
}
- if (strict && email == git_default_email.buf && default_email_is_bogus) {
- fputs(env_hint, stderr);
- die("unable to auto-detect email address (got '%s')", email);
+ if (!email) {
+ email = ident_default_email();
+ if (strict && default_email_is_bogus) {
+ fputs(env_hint, stderr);
+ die("unable to auto-detect email address (got '%s')", email);
+ }
}
strbuf_reset(&ident);