git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v4 3/3] ident.c: cleanup wrt ident's source

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 4, 2016, 22:42 UTC
Message-ID
<xmqqvb64f66o.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1454577160-24484-4-git-send-email-alonid@gmail.com>
Dan Aloni <alonid@gmail.com> writes:
Show 6 quoted lines
> +static int ident_source_is_sufficient(enum ident_source source)
> +{
> +	switch (source) {
> +	case IDENT_SOURCE_CONFIG:
> +	case IDENT_SOURCE_ENVIRONMENT:
> +		return 1;
Without adding these two lines here:
	default:
        	break;
I get this build failure:
ident.c: In function 'ident_source_is_sufficient':
ident.c:444:2: error: enumeration value 'IDENT_SOURCE_UNKNOWN' not handled in switch [-Werror=switch]
  switch (source) {
  ^
ident.c:444:2: error: enumeration value 'IDENT_SOURCE_GUESSED' not handled in switch [-Werror=switch]
ident.c:444:2: error: enumeration value 'IDENT_SOURCE_GUESSED_BOGUS' not handled in switch [-Werror=switch]
Show 29 quoted lines
> +static int ident_is_sufficient(enum ident_person person)
>  {
> +	const char *str_name, *str_email;
> +	int name, email;
> +
> +	switch (person) {
> +	case IDENT_PERSON_COMMITTER:
> +		str_name = getenv("GIT_COMMITTER_NAME");
> +		str_email = getenv("GIT_COMMITTER_EMAIL");
> +		break;
> +	case IDENT_PERSON_AUTHOR:
> +		str_name = getenv("GIT_AUTHOR_NAME");
> +		str_email = getenv("GIT_AUTHOR_EMAIL");
> +		break;
> +	default:
> +		die("invalid parameter to ident_is_sufficient()");
> +	}
> +
> +	name = !!str_name || ident_source_is_sufficient(source_of_default_name);
> +	email = !!str_email || ident_source_is_sufficient(source_of_default_email);
> +
>  #ifndef WINDOWS
> -	return (user_ident_explicitly_given & IDENT_MAIL_GIVEN);
> +	return email;
>  #else
> -	return (user_ident_explicitly_given == IDENT_ALL_GIVEN);
> +	return name && email;
>  #endif
>  }

It appears that str_name and name are unconditionally computed even though it does not affect the outcome of the whole thing. When building for !WINDOWS, I get

ident.c: In function 'ident_is_sufficient':
ident.c:456:6: error: variable 'name' set but not used [-Werror=unused-but-set-variable]
  int name, email;
      ^
cc1: all warnings being treated as errors
make: *** [ident.o] Error 1
as the result of this.
Previous: Junio C HamanoNext: Dan Aloni
Message 8 of 9 in “Add user.useConfigOnly boolean for when ident shouldn't be guessed”
  1. Add user.useConfigOnly boolean for when ident shouldn't be guessedDan Aloni, Feb 4, 2016
  2. 1/3 fmt_ident: refactor strictness checksDan Aloni, Feb 4, 2016
  3. 2/3 Add user.useConfigOnly boolean for when ident shouldn't be guessedDan Aloni, Feb 4, 2016
  4. Junio C HamanoFeb 4, 2016
  5. Dan AloniFeb 5, 2016
  6. 3/3 ident.c: cleanup wrt ident's sourceDan Aloni, Feb 4, 2016
  7. Junio C HamanoFeb 4, 2016
  8. Junio C HamanoFeb 4, 2016
  9. Dan AloniFeb 5, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.