From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: David Aguilar <davvid@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
Christophe Macabiau <christophemacabiau@gmail.com>,
Git ML <git@vger.kernel.org>
Subject: Re: [PATCH] difftool: handle changing symlinks in dir-diff mode
Date: Mon, 13 Mar 2017 22:36:22 +0100 (CET) [thread overview]
Message-ID: <alpine.DEB.2.20.1703132212430.3767@virtualbox> (raw)
In-Reply-To: <20170313175640.14106-1-davvid@gmail.com>
Hi David,
Thank you very much for picking this up!
On Mon, 13 Mar 2017, David Aguilar wrote:
> Detect the null object ID for symlinks in dir-diff so that difftool can
> prepare temporary files that matches how git handles symlinks.
Maybe a description is needed how the OID can be null in that case. I have
to admit that I failed to wrap my head around this so far.
> Previously, a null object ID would crash difftool. We now detect null
> object IDs and write the symlink's content into the temporary symlink
> stand-in file.
>
> Original-patch-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> Signed-off-by: David Aguilar <davvid@gmail.com>
> ---
> diff --git a/builtin/difftool.c b/builtin/difftool.c
> index d13350ce83..6c20e20b45 100644
> --- a/builtin/difftool.c
> +++ b/builtin/difftool.c
> @@ -254,6 +254,31 @@ static int ensure_leading_directories(char *path)
> }
> }
>
> +static int create_symlink_file(struct cache_entry* ce, struct checkout* state)
> +{
> + /*
> + * Dereference a worktree symlink and writes its contents
> + * into the checkout state's path.
> + */
> + struct strbuf path = STRBUF_INIT;
> + struct strbuf link = STRBUF_INIT;
> +
> + int ok = 0;
It would appear that the convention in Git's C code is for functions to
return 0 upon success and -1 upon error, and to use `int ret` for that
purpose.
> + if (strbuf_readlink(&link, ce->name, ce_namelen(ce)) == 0) {
Looking at the calling site, I would have expected the code to read the
contents as per ce->hash... After all, we are calling this in the
!use_wt_file() case.
But that is exactly that null hash, isn't it?
> @@ -414,7 +439,12 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
The lines before this hunk read:
> if (!use_wt_file(workdir, dst_path, &roid)) {
> ce->ce_mode = rmode;
... and then follow these lines:
> oidcpy(&ce->oid, &roid);
> strcpy(ce->name, dst_path);
> ce->ce_namelen = dst_path_len;
> - if (checkout_entry(ce, &rstate, NULL))
> +
> + if (S_ISLNK(rmode) && is_null_oid(&roid)) {
> + if (!create_symlink_file(ce, &rstate))
> + return error("unable to create symlink file %s",
> + dst_path);
> + } else if (checkout_entry(ce, &rstate, NULL))
> return error("could not write '%s'",
> dst_path);
> } else if (!is_null_oid(&roid)) {
Given that we explicitly ask use_wt_file() whether we can use the
worktree's file, and we get the answer "no" before we enter the modified
code block, I would really expect us *not* to want to read the link from
disk at all.
Further, reading the code of use_wt_file(), there seems to be another case
where roid is left alone: when the file could not be lstat()ed. So I
wonder whether the create_symlink_file() is the correct solution, or
whether we could somehow fill roid correctly instead, and keep the
checkout_entry() call?
Ciao,
Dscho
prev parent reply other threads:[~2017-03-13 21:36 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-24 11:47 fatal error when diffing changed symlinks Christophe Macabiau
2017-02-24 17:53 ` Junio C Hamano
2017-02-24 19:51 ` Junio C Hamano
2017-02-24 20:35 ` Jeff King
2017-02-25 12:36 ` Johannes Schindelin
2017-03-07 18:16 ` Junio C Hamano
2017-03-07 22:34 ` Johannes Schindelin
2017-03-13 17:56 ` [PATCH] difftool: handle changing symlinks in dir-diff mode David Aguilar
2017-03-13 18:32 ` Junio C Hamano
2017-03-13 21:04 ` Johannes Schindelin
2017-03-13 21:27 ` Johannes Schindelin
2017-03-13 21:33 ` Junio C Hamano
2017-03-14 2:20 ` David Aguilar
2017-03-14 5:52 ` Junio C Hamano
2017-03-14 4:13 ` Junio C Hamano
2017-03-13 19:02 ` Junio C Hamano
2017-03-13 21:36 ` Johannes Schindelin [this message]
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.20.1703132212430.3767@virtualbox \
--to=johannes.schindelin@gmx.de \
--cc=christophemacabiau@gmail.com \
--cc=davvid@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).