From: Junio C Hamano <gitster@pobox•com>
To: Thomas Rast <tr@thomasrast•ch>
Cc: git@vger•kernel.org, "Grégory Pakosz" <gregory.pakosz@gmail•com>
Subject: Re: [PATCH] diff: do not reuse_worktree_file for submodules
Date: Tue, 18 Feb 2014 13:01:22 -0800 [thread overview]
Message-ID: <xmqqy518cezh.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <d08b7e5a36ee13226d1ad56a731016762ae89938.1392569505.git.tr@thomasrast.ch> (Thomas Rast's message of "Sun, 16 Feb 2014 17:52:34 +0100")
Thomas Rast <tr@thomasrast•ch> writes:
> The GIT_EXTERNAL_DIFF calling code attempts to reuse existing worktree
> files for the worktree side of diffs, for performance reasons.
> However, that code also tries to do the same with submodules. This
> results in calls to $GIT_EXTERNAL_DIFF where the old-file is a file of
> the form "Submodule commit $sha1", but the new-file is a directory in
> the worktree.
>
> Fix it by never reusing a worktree "file" in the submodule case.
>
> Reported-by: Grégory Pakosz <gregory.pakosz@gmail•com>
> Signed-off-by: Thomas Rast <tr@thomasrast•ch>
> ---
> diff.c | 5 +++--
> t/t4020-diff-external.sh | 30 +++++++++++++++++++++++++++++-
> 2 files changed, 32 insertions(+), 3 deletions(-)
>
> diff --git a/diff.c b/diff.c
> index 7c59bfe..e9a8874 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -2845,8 +2845,9 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
> remove_tempfile_installed = 1;
> }
>
> - if (!one->sha1_valid ||
> - reuse_worktree_file(name, one->sha1, 1)) {
> + if (!S_ISGITLINK(one->mode) &&
> + (!one->sha1_valid ||
> + reuse_worktree_file(name, one->sha1, 1))) {
I agree with the goal/end result, but I have to wonder if the
reuse_worktree_file() be the helper function that ought to
encapsulate such a logic?
Instead of feeding it an object name and a path, if we passed a
diff_filespec to the helper, it would have access to the mode as
well. It would result in a more intrusive change, so I'd prefer to
see your patch applied first and then build such a refactor on top,
perhaps like the attached.
diff.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/diff.c b/diff.c
index a96992a..74eec80 100644
--- a/diff.c
+++ b/diff.c
@@ -2582,11 +2582,13 @@ void fill_filespec(struct diff_filespec *spec, const unsigned char *sha1,
* the work tree has that object contents, return true, so that
* prepare_temp_file() does not have to inflate and extract.
*/
-static int reuse_worktree_file(const char *name, const unsigned char *sha1, int want_file)
+static int reuse_worktree_file(const struct diff_filespec *spec, int want_file)
{
const struct cache_entry *ce;
struct stat st;
int pos, len;
+ const char *name = spec->path;
+ const unsigned char *sha1 = spec->sha1;
/*
* We do not read the cache ourselves here, because the
@@ -2698,7 +2700,7 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
return diff_populate_gitlink(s, size_only);
if (!s->sha1_valid ||
- reuse_worktree_file(s->path, s->sha1, 0)) {
+ reuse_worktree_file(s, 0)) {
struct strbuf buf = STRBUF_INIT;
struct stat st;
int fd;
@@ -2844,17 +2846,17 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
if (!S_ISGITLINK(one->mode) &&
(!one->sha1_valid ||
- reuse_worktree_file(name, one->sha1, 1))) {
+ reuse_worktree_file(one, 1))) {
struct stat st;
- if (lstat(name, &st) < 0) {
+ if (lstat(one->path, &st) < 0) {
if (errno == ENOENT)
goto not_a_valid_file;
- die_errno("stat(%s)", name);
+ die_errno("stat(%s)", one->path);
}
if (S_ISLNK(st.st_mode)) {
struct strbuf sb = STRBUF_INIT;
- if (strbuf_readlink(&sb, name, st.st_size) < 0)
- die_errno("readlink(%s)", name);
+ if (strbuf_readlink(&sb, one->path, st.st_size) < 0)
+ die_errno("readlink(%s)", one->path);
prep_temp_blob(name, temp, sb.buf, sb.len,
(one->sha1_valid ?
one->sha1 : null_sha1),
@@ -2864,7 +2866,7 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
}
else {
/* we can borrow from the file in the work tree */
- temp->name = name;
+ temp->name = one->path;
if (!one->sha1_valid)
strcpy(temp->hex, sha1_to_hex(null_sha1));
else
next prev parent reply other threads:[~2014-02-18 21:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-15 12:19 git diff, external diff tool, and submodules Grégory Pakosz
2014-02-16 16:52 ` [PATCH] diff: do not reuse_worktree_file for submodules Thomas Rast
2014-02-18 21:01 ` Junio C Hamano [this message]
2014-02-22 11:27 ` Thomas Rast
2014-02-23 12:46 ` Thomas Rast
2014-02-24 17:39 ` 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=xmqqy518cezh.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=gregory.pakosz@gmail$(echo .)com \
--cc=tr@thomasrast$(echo .)ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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