From: Thomas Rast <tr@thomasrast.ch>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, "Grégory Pakosz" <gregory.pakosz@gmail.com>
Subject: Re: [PATCH] diff: do not reuse_worktree_file for submodules
Date: Sat, 22 Feb 2014 12:27:29 +0100 [thread overview]
Message-ID: <8738jbtmji.fsf@thomasrast.ch> (raw)
In-Reply-To: <xmqqy518cezh.fsf@gitster.dls.corp.google.com> (Junio C. Hamano's message of "Tue, 18 Feb 2014 13:01:22 -0800")
Junio C Hamano <gitster@pobox.com> writes:
> Thomas Rast <tr@thomasrast.ch> writes:
>
>> @@ -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.
I see that you already queued 721e727, which has the change you
described plus moving the S_ISGITLINK test into reuse_worktree_file.
The change looks good to me. However, two nits about the comments:
diff.c now says
/*
* Given a name and sha1 pair, if the index tells us the file in
* 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 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;
/* reading the directory will not give us "Submodule commit XYZ" */
if (S_ISGITLINK(spec->mode))
return 0;
But the function comment is no longer accurate, and the comment about
the S_ISGITLINK exit is rather obscure if one doesn't know what the
callers want. So how about this on top?
diff.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git i/diff.c w/diff.c
index a342ea6..dabf913 100644
--- i/diff.c
+++ w/diff.c
@@ -2578,9 +2578,14 @@ void fill_filespec(struct diff_filespec *spec, const unsigned char *sha1,
}
/*
- * Given a name and sha1 pair, if the index tells us the file in
- * the work tree has that object contents, return true, so that
- * prepare_temp_file() does not have to inflate and extract.
+ * Given a diff_filespec, determine if the corresponding worktree file
+ * can be used for diffing instead of reading the object from the
+ * repository.
+ *
+ * We normally try packfiles, worktree, loose objects in this order.
+ *
+ * If want_file=1 or git was compiled with NO_FAST_WORKING_DIRECTORY,
+ * the order is: worktree, packfiles, loose objects.
*/
static int reuse_worktree_file(const struct diff_filespec *spec, int want_file)
{
@@ -2590,7 +2595,11 @@ static int reuse_worktree_file(const struct diff_filespec *spec, int want_file)
const char *name = spec->path;
const unsigned char *sha1 = spec->sha1;
- /* reading the directory will not give us "Submodule commit XYZ" */
+ /*
+ * The diff representation of a submodule is "Submodule commit
+ * XYZ", but in the worktree we have a directory. So they
+ * never match.
+ */
if (S_ISGITLINK(spec->mode))
return 0;
--
Thomas Rast
tr@thomasrast.ch
next prev parent reply other threads:[~2014-02-22 11:28 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
2014-02-22 11:27 ` Thomas Rast [this message]
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=8738jbtmji.fsf@thomasrast.ch \
--to=tr@thomasrast.ch \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=gregory.pakosz@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.