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

Re: [PATCH 1/3] builtin/apply: get rid of useless 'name' variable

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 22, 2016, 21:20 UTC
Message-ID
<xmqq7fgugqfp.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1458680322-17681-2-git-send-email-chriscool@tuxfamily.org>
Christian Couder <christian.couder@gmail.com> writes:
Show 39 quoted lines
> While at it put an 'else' on the same line as the previous '}'.
>
> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
> ---
>  builtin/apply.c | 13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/builtin/apply.c b/builtin/apply.c
> index 42c610e..465f954 100644
> --- a/builtin/apply.c
> +++ b/builtin/apply.c
> @@ -931,22 +931,19 @@ static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name,
>  		return find_name(line, NULL, p_value, TERM_TAB);
>  
>  	if (orig_name) {
> -		int len;
> -		const char *name;
> +		int len = strlen(orig_name);
>  		char *another;
> -		name = orig_name;
> -		len = strlen(name);
>  		if (isnull)
> -			die(_("git apply: bad git-diff - expected /dev/null, got %s on line %d"), name, linenr);
> +			die(_("git apply: bad git-diff - expected /dev/null, got %s on line %d"),
> +			    orig_name, linenr);
>  		another = find_name(line, NULL, p_value, TERM_TAB);
> -		if (!another || memcmp(another, name, len + 1))
> +		if (!another || memcmp(another, orig_name, len + 1))
>  			die((side == DIFF_NEW_NAME) ?
>  			    _("git apply: bad git-diff - inconsistent new filename on line %d") :
>  			    _("git apply: bad git-diff - inconsistent old filename on line %d"), linenr);
>  		free(another);
>  		return orig_name;
> -	}
> -	else {
> +	} else {
>  		/* expect "/dev/null" */
>  		if (memcmp("/dev/null", line, 9) || line[9] != '\n')
>  			die(_("git apply: bad git-diff - expected /dev/null on line %d"), linenr);

Looks correct; back when 1e3f6b6e (git-apply: more consistency checks on gitdiff filenames, 2005-05-23) introduced this function, the variable "name" was in the outer scope, and a subsequent update narrowed its scope at ea56188a (Update git-apply to use C-style quoting for funny pathnames., 2005-10-16) but it could have removed the variable at the same time.

Previous: Christian CouderNext: Christian Couder
Message 3 of 8 in “builtin/apply: simplify some gitdiff_* functions”
  1. 0/3 builtin/apply: simplify some gitdiff_* functionsChristian Couder, Mar 22, 2016
  2. 1/3 builtin/apply: get rid of useless 'name' variableChristian Couder, Mar 22, 2016
  3. Junio C HamanoMar 22, 2016
  4. 2/3 builtin/apply: make gitdiff_verify_name() return voidChristian Couder, Mar 22, 2016
  5. Junio C HamanoMar 22, 2016
  6. Christian CouderMar 22, 2016
  7. 3/3 builtin/apply: simplify gitdiff_{old,new}name()Christian Couder, Mar 22, 2016
  8. Junio C HamanoMar 22, 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.