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

Re: [PATCH 2/2] difftool: handle uninitialized variable on empty diff

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 28, 2012, 20:00 UTC
Message-ID
<7v7gur5hqv.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1340912395-16990-2-git-send-email-tim.henigan@gmail.com>
Tim Henigan <tim.henigan@gmail.com> writes:
Show 18 quoted lines
> When 'difftool --dir-diff' finds no changes, it results in an
> uninitialized variable warning.
>
> Signed-off-by: Tim Henigan <tim.henigan@gmail.com>
> ---
>  git-difftool.perl | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/git-difftool.perl b/git-difftool.perl
> index 679a56d..c94557d 100755
> --- a/git-difftool.perl
> +++ b/git-difftool.perl
> @@ -117,7 +117,7 @@ sub setup_dir_diff
>  	# by Git->repository->command*.
>  	my $diffrepo = Git->repository(Repository => $repo_path, WorkingCopy => $workdir);
>  	my $diffrtn = $diffrepo->command_oneline('diff', '--raw', '--no-abbrev', '-z', @ARGV);
> -	exit(0) if (length($diffrtn) == 0);
> +	exit(0) if ((not defined($diffrtn)) or (length($diffrtn) == 0));
Wouldn't it be far more readable to say something like
        if (!$diffrtn) {
        	exit(0);
	}

instead, as "diff --raw" output, when not empty, cannot be a single "0"?

By the way, I suspect that the use of command_oneline() here is wrong. It uses '-z' so that it can handle whitespace characters in pathnames sensibly (in other words, the output does not use LF as a record separator), so pathnames with LF in them will be output literally. Taking only the first line of the "diff -z" output would mean that you will stop when you see the first pathname with LF in it.

This is not a new problem with this patch, but came from your 7e0abce (difftool: teach difftool to handle directory diffs, 2012-04-23).

Previous: Tim HeniganNext: Junio C Hamano
Message 3 of 8 in “difftool: only copy back files modified during directory diff”
  1. 1/2 difftool: only copy back files modified during directory diffTim Henigan, Jun 28, 2012
  2. 2/2 difftool: handle uninitialized variable on empty diffTim Henigan, Jun 28, 2012
  3. Junio C HamanoJun 28, 2012
  4. Junio C HamanoJun 28, 2012
  5. David AguilarJul 19, 2012
  6. difftool: only copy back files modified during directory diffDavid Aguilar, Jul 19, 2012
  7. Junio C HamanoJul 19, 2012
  8. David AguilarJul 21, 2012

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.