Skip to content

Commit ad90da7

Browse files
derrickstoleegitster
authored andcommitted
diff: ignore sparse paths in diffstat
The diff_populate_filespec() method is used to describe the diff after a merge operation is complete. In order to avoid expanding a sparse index, the reuse_worktree_file() needs to be adapted to ignore files that are outside of the sparse-checkout cone. The file names and OIDs used for this check come from the merged tree in the case of the ORT strategy, not the index, hence the ability to look into these paths without having already expanded the index. The work done by reuse_worktree_file() is only an optimization, and requires the file being on disk for it to be of any value. Thus, it is safe to exit the method early if we do not expect the file on disk. Signed-off-by: Derrick Stolee <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 55dfcf9 commit ad90da7

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

diff.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "parse-options.h"
2727
#include "help.h"
2828
#include "promisor-remote.h"
29+
#include "dir.h"
2930

3031
#ifdef NO_FAST_WORKING_DIRECTORY
3132
#define FAST_WORKING_DIRECTORY 0
@@ -3907,6 +3908,13 @@ static int reuse_worktree_file(struct index_state *istate,
39073908
if (!want_file && would_convert_to_git(istate, name))
39083909
return 0;
39093910

3911+
/*
3912+
* If this path does not match our sparse-checkout definition,
3913+
* then the file will not be in the working directory.
3914+
*/
3915+
if (!path_in_sparse_checkout(name, istate))
3916+
return 0;
3917+
39103918
len = strlen(name);
39113919
pos = index_name_pos(istate, name, len);
39123920
if (pos < 0)

0 commit comments

Comments
 (0)