git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: Re: [PATCH 1/1] diff: munmap() file contents before running external diff
Date: Mon, 08 Jul 2019 14:54:35 -0700	[thread overview]
Message-ID: <xmqq8st8xkdg.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <bef83fc20b9e2048872316e3f396da0cb6775086.1562231781.git.gitgitgadget@gmail.com> (Johannes Schindelin via GitGitGadget's message of "Thu, 04 Jul 2019 02:16:22 -0700 (PDT)")

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
writes:

> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> When running an external diff from, say, a diff tool, it is safe to
> assume that we want to write the files in question. On Windows, that
> means that there cannot be any other process holding an open handle to
> said files.

Please add "It is not enough to close the file descriptor; having a
region that is still mmapped keeps the file busy" or something like
that at the end.

> So let's make sure that `git diff` itself is not holding any open handle
> to the files in question.
>
> This fixes https://github.com/git-for-windows/git/issues/1315
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>  diff.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/diff.c b/diff.c
> index 4d3cf83a27..0afb76bbca 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -4206,6 +4206,10 @@ static void run_external_diff(const char *pgm,
>  	argv_array_pushf(&env, "GIT_DIFF_PATH_COUNTER=%d", ++o->diff_path_counter);
>  	argv_array_pushf(&env, "GIT_DIFF_PATH_TOTAL=%d", q->nr);
>  
> +	if (one && one->should_munmap)
> +		diff_free_filespec_data(one);
> +	if (two && two->should_munmap)
> +		diff_free_filespec_data(two);

I wondered if a single diff_filespec instance can be used in two
diff_filepair instances (e.g. file A is in-place modified and also
used to create file C), and if so after showing the diff for file A,
we have problems with showing file C.  But I do not think it should
pose a problem, as "free data after comparing a pair" is what we do
for the in-core codepath in builtin_diff().

We can lose the NULL-ness test for one and two if these "free the
resource once we no longer need it" is done inside "if (one && two)".
After all, once add_external_diff_name()[*1*] does its thing, we do
not need the data for these diff_filespec instances, right?

Also, just like builtin_diff() unconditionally frees the resources
held by diff_filespec instances, shouldn't this function do so, even
the ones that are not marked with should_munmap?


>  	if (run_command_v_opt_cd_env(argv.argv, RUN_USING_SHELL, NULL, env.argv))
>  		die(_("external diff died, stopping at %s"), name);

  reply	other threads:[~2019-07-08 21:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-04  9:16 [PATCH 0/1] diff: release all handles before running external diff Johannes Schindelin via GitGitGadget
2019-07-04  9:16 ` [PATCH 1/1] diff: munmap() file contents " Johannes Schindelin via GitGitGadget
2019-07-08 21:54   ` Junio C Hamano [this message]
2019-07-10 12:43     ` Johannes Schindelin
2019-07-08 19:24 ` [PATCH 0/1] diff: release all handles " Junio C Hamano
2019-07-11  8:23 ` [PATCH v2 " Johannes Schindelin via GitGitGadget
2019-07-11  8:23   ` [PATCH v2 1/1] diff: munmap() file contents " Johannes Schindelin via GitGitGadget
2019-07-11 19:03     ` 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

  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=xmqq8st8xkdg.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=johannes.schindelin@gmx.de \
    /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).