Junio C Hamano <[email protected]> writes:
> Thomas Rast <[email protected]> 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
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html