Skip to content

Commit

Permalink
diff: ignore sparse paths in diffstat
Browse files Browse the repository at this point in the history
The diff_populate_filespec() method is used to describe the diff after a
merge operation is complete, especially when a conflict appears. 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.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
  • Loading branch information
derrickstolee authored and dscho committed Aug 16, 2023
1 parent f6470e9 commit 0d78437
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -3994,6 +3994,13 @@ static int reuse_worktree_file(struct index_state *istate,
if (!FAST_WORKING_DIRECTORY && !want_file && has_object_pack(oid))
return 0;

/*
* If this path does not match our sparse-checkout definition,
* then the file will not be in the working directory.
*/
if (!path_in_sparse_checkout(name, istate))
return 0;

/*
* Similarly, if we'd have to convert the file contents anyway, that
* makes the optimization not worthwhile.
Expand Down

0 comments on commit 0d78437

Please sign in to comment.