Skip to content

Commit ad770c4

Browse files
committed
sparse-index: mark am, mv, submodule, grep as sparse-index compatible
These commands were found to have never declared command_requires_full_index. After analysis, all four are safe with sparse index (= 0). git-am: The patch application path uses index_name_pos() which auto-expands sparse directory entries on demand when a specific file path is looked up. The three-way merge fallback uses merge-ort, which works from tree OIDs and handles sparse directories natively. refresh_index() explicitly skips S_ISSPARSEDIR entries. git-rebase --apply invokes git-am as a child process; rebase itself already declares command_requires_full_index = 0. git-mv: For in-cone moves, all index lookups use index_name_pos() on paths that cannot be ancestors of sparse directory entries (by definition of the sparse cone), so no expansion is triggered. index_range_of_same_dir() iterates only in-cone entries in this case. For out-of-cone moves (--sparse flag), a targeted ensure_full_index() is needed because the bulk cache[] iteration and rename_index_entry_at() assume individual file entries, not collapsed directory stubs. git-submodule--helper: Submodule entries (S_ISGITLINK) are never collapsed into sparse directory entries -- convert_to_sparse_rec() in sparse-index.c explicitly blocks directories containing gitlinks from being collapsed. module_list_compute() filters on S_ISGITLINK, skipping any sparse directory entries. module_add() already calls ensure_full_index() unconditionally before its index iteration. grep (submodule path): grep_cache() explicitly handles S_ISSPARSEDIR entries by reading the tree object and recursing via grep_tree(), so sparse directory contents are grepped correctly. The subrepo index is independent of the superproject.
1 parent b6b4a96 commit ad770c4

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

builtin/am.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,9 +2465,8 @@ int cmd_am(int argc,
24652465
/* Ensure a valid committer ident can be constructed */
24662466
git_committer_info(IDENT_STRICT);
24672467

2468-
/* not yet verified whether this can use the sparse index */
24692468
prepare_repo_settings(the_repository);
2470-
the_repository->settings.command_requires_full_index = 1;
2469+
the_repository->settings.command_requires_full_index = 0;
24712470

24722471
if (repo_read_index_preload(the_repository, NULL, 0) < 0)
24732472
die(_("failed to read the index"));

builtin/grep.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,8 @@ static int grep_submodule(struct grep_opt *opt,
500500
*
501501
* Note that this list is not exhaustive.
502502
*/
503-
/* not yet verified whether subrepo can use the sparse index */
504503
prepare_repo_settings(subrepo);
505-
subrepo->settings.command_requires_full_index = 1;
504+
subrepo->settings.command_requires_full_index = 0;
506505

507506
repo_read_gitmodules(subrepo, 0);
508507

builtin/mv.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "strvec.h"
2929
#include "submodule.h"
3030
#include "entry.h"
31+
#include "sparse-index.h"
3132

3233
static const char * const builtin_mv_usage[] = {
3334
N_("git mv [-v] [-f] [-n] [-k] <source> <destination>"),
@@ -248,14 +249,16 @@ int cmd_mv(int argc,
248249
if (--argc < 1)
249250
usage_with_options(builtin_mv_usage, builtin_mv_options);
250251

251-
/* not yet verified whether this can use the sparse index */
252252
prepare_repo_settings(the_repository);
253-
the_repository->settings.command_requires_full_index = 1;
253+
the_repository->settings.command_requires_full_index = 0;
254254

255255
repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
256256
if (repo_read_index(the_repository) < 0)
257257
die(_("index file corrupt"));
258258

259+
if (ignore_sparse)
260+
ensure_full_index(the_repository->index);
261+
259262
internal_prefix_pathspec(&sources, prefix, argv, argc, 0);
260263
CALLOC_ARRAY(modes, argc);
261264

builtin/submodule--helper.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3833,9 +3833,8 @@ int cmd_submodule__helper(int argc,
38333833
};
38343834
argc = parse_options(argc, argv, prefix, options, usage, 0);
38353835

3836-
/* not yet verified whether this can use the sparse index */
38373836
prepare_repo_settings(the_repository);
3838-
the_repository->settings.command_requires_full_index = 1;
3837+
the_repository->settings.command_requires_full_index = 0;
38393838

38403839
return fn(argc, argv, prefix, repo);
38413840
}

0 commit comments

Comments
 (0)