summaryrefslogtreecommitdiff
path: root/builtin/add.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2021-08-24 15:32:35 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-08-24 15:32:35 -0700
commit2f713668784266b4682816fadcf2034d846e9cc1 (patch)
tree22af9c76e4c6fcd9663c68d10fd0152725285e65 /builtin/add.c
parentMerge branch 'jc/bisect-sans-show-branch' (diff)
parentadd: remove ensure_full_index() with --renormalize (diff)
downloadtgif-2f713668784266b4682816fadcf2034d846e9cc1.tar.xz
Merge branch 'ds/add-with-sparse-index'
"git add" can work better with the sparse index. * ds/add-with-sparse-index: add: remove ensure_full_index() with --renormalize add: ignore outside the sparse-checkout in refresh() pathspec: stop calling ensure_full_index add: allow operating on a sparse-only index t1092: test merge conflicts outside cone
Diffstat (limited to 'builtin/add.c')
-rw-r--r--builtin/add.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/builtin/add.c b/builtin/add.c
index 09e684585d..17528e8f92 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -144,8 +144,6 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
{
int i, retval = 0;
- /* TODO: audit for interaction with sparse-index. */
- ensure_full_index(&the_index);
for (i = 0; i < active_nr; i++) {
struct cache_entry *ce = active_cache[i];
@@ -192,13 +190,21 @@ static int refresh(int verbose, const struct pathspec *pathspec)
struct string_list only_match_skip_worktree = STRING_LIST_INIT_NODUP;
int flags = REFRESH_IGNORE_SKIP_WORKTREE |
(verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET);
+ struct pattern_list pl = { 0 };
+ int sparse_checkout_enabled = !get_sparse_checkout_patterns(&pl);
seen = xcalloc(pathspec->nr, 1);
refresh_index(&the_index, flags, pathspec, seen,
_("Unstaged changes after refreshing the index:"));
for (i = 0; i < pathspec->nr; i++) {
if (!seen[i]) {
- if (matches_skip_worktree(pathspec, i, &skip_worktree_seen)) {
+ const char *path = pathspec->items[i].original;
+ int dtype = DT_REG;
+
+ if (matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
+ (sparse_checkout_enabled &&
+ !path_matches_pattern_list(path, strlen(path), NULL,
+ &dtype, &pl, &the_index))) {
string_list_append(&only_match_skip_worktree,
pathspec->items[i].original);
} else {
@@ -528,6 +534,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
add_new_files = !take_worktree_changes && !refresh_only && !add_renormalize;
require_pathspec = !(take_worktree_changes || (0 < addremove_explicit));
+ prepare_repo_settings(the_repository);
+ the_repository->settings.command_requires_full_index = 0;
+
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
/*