From: David Aguilar <davvid@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Ismail Badawi <ismail@badawi.io>,
John Keeping <john@keeping.me.uk>,
Tim Henigan <tim.henigan@gmail.com>,
Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH] difftool: avoid symlinks when reusing worktree files
Date: Fri, 30 Oct 2015 00:28:57 -0700 [thread overview]
Message-ID: <20151030072857.GA15031@gmail.com> (raw)
In-Reply-To: <xmqq4mh9sfl6.fsf@gitster.mtv.corp.google.com>
On Thu, Oct 29, 2015 at 11:19:01AM -0700, Junio C Hamano wrote:
> Junio C Hamano <gitster@pobox.com> writes:
>
> > So I think it is fine to return $use=0 for any symbolic link from
> > use_wt_file. Anything you do there will be replaced by the loop
> > over %symlink that appears later in the caller. The caller discards
> > $wt_sha1 when $use=0 is returned, so the second return value does
> > not matter.
>
> So let me try to update your patch with the result of the study of
> the codeflow.
>
> -- >8 --
> From: David Aguilar <davvid@gmail.com>
> Subject: difftool: ignore symbolic links in use_wt_file
>
> The caller is preparing a narrowed-down copy of the working tree and
> this function is asked if the path should be included in that copy.
> If we say yes, the path from the working tree will be either symlinked
> or copied into the narrowed-down copy.
>
> For any path that is a symbolic link, the caller later fixes up the
> narrowed-down copy by unlinking the path and replacing it with a
> regular file it writes out that mimics the way how "git diff"
> compares symbolic links.
>
> Let's answer "no, you do not want to copy/symlink the working tree
> file" for all symbolic links from this function, as we know the
> result will not be used because it will be overwritten anyway.
>
> Incidentally, this also stops the function from feeding a symbolic
> link in the working tree to hash-object, which is a wrong thing to
> do to begin with. The link may be pointing at a directory, or worse
> may be dangling (both would be noticed as an error). Even if the
> link points at a regular file, hashing the contents of a file that
> is pointed at by the link is not correct (Git hashes the contents of
> the link itself, not the pointee).
>
> Signed-off-by: David Aguilar <davvid@gmail.com>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
This is a very nicely worded commit message. Thanks for the
thorough explanation.
> git-difftool.perl | 4 +---
> t/t7800-difftool.sh | 19 +++++++++++++++++++
> 2 files changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/git-difftool.perl b/git-difftool.perl
> index 7df7c8a..488d14b 100755
> --- a/git-difftool.perl
> +++ b/git-difftool.perl
> @@ -70,9 +70,7 @@ sub use_wt_file
> my ($repo, $workdir, $file, $sha1) = @_;
> my $null_sha1 = '0' x 40;
>
> - if (! -e "$workdir/$file") {
> - # If the file doesn't exist in the working tree, we cannot
> - # use it.
> + if (-l "$workdir/$file" || ! -e _) {
> return (0, $null_sha1);
> }
The "-e _" shorthand caught my eye ~ I didn't know perl could do that!
Nice.
Underline is barely mentioned in perlvar, but it's obvious what
(I think) it means, and since Perl is DWIM, it must be right. ;-)
--
David
next prev parent reply other threads:[~2015-10-30 7:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-27 21:24 [PATCH] difftool: avoid symlinks when reusing worktree files David Aguilar
2015-10-27 22:24 ` Junio C Hamano
2015-10-29 1:55 ` David Aguilar
2015-10-29 17:59 ` Junio C Hamano
2015-10-29 18:19 ` Junio C Hamano
2015-10-30 7:28 ` David Aguilar [this message]
2015-10-30 16:19 ` Junio C Hamano
2015-10-27 22:41 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151030072857.GA15031@gmail.com \
--to=davvid@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=ismail@badawi.io \
--cc=john@keeping.me.uk \
--cc=tim.henigan@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).