summaryrefslogtreecommitdiff
path: root/wt-status.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2021-07-28 20:18:01 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-07-28 20:18:02 (GMT)
commitb271a3034fc54a7c84ae5803d72f14a29b172c78 (patch)
treeecace44004f0254c6b107d1748f0977eab2c98de /wt-status.c
parent6d56fb28fb0de8add352352c9b271cace08670b8 (diff)
parente5ca291076a8a936283bb2c57433c4393d3f80c2 (diff)
downloadgit-b271a3034fc54a7c84ae5803d72f14a29b172c78.zip
git-b271a3034fc54a7c84ae5803d72f14a29b172c78.tar.gz
git-b271a3034fc54a7c84ae5803d72f14a29b172c78.tar.bz2
Merge branch 'ds/status-with-sparse-index'
"git status" codepath learned to work with sparsely populated index without hydrating it fully. * ds/status-with-sparse-index: t1092: document bad sparse-checkout behavior fsmonitor: integrate with sparse index wt-status: expand added sparse directory entries status: use sparse-index throughout status: skip sparse-checkout percentage with sparse-index diff-lib: handle index diffs with sparse dirs dir.c: accept a directory as part of cone-mode patterns unpack-trees: unpack sparse directory entries unpack-trees: rename unpack_nondirectories() unpack-trees: compare sparse directories correctly unpack-trees: preserve cache_bottom t1092: add tests for status/add and sparse files t1092: expand repository data shape t1092: replace incorrect 'echo' with 'cat' sparse-index: include EXTENDED flag when expanding sparse-index: skip indexes with unmerged entries
Diffstat (limited to 'wt-status.c')
-rw-r--r--wt-status.c65
1 files changed, 62 insertions, 3 deletions
diff --git a/wt-status.c b/wt-status.c
index c0dbf96..eaed30e 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -657,6 +657,36 @@ static void wt_status_collect_changes_index(struct wt_status *s)
clear_pathspec(&rev.prune_data);
}
+static int add_file_to_list(const struct object_id *oid,
+ struct strbuf *base, const char *path,
+ unsigned int mode, void *context)
+{
+ struct string_list_item *it;
+ struct wt_status_change_data *d;
+ struct wt_status *s = context;
+ struct strbuf full_name = STRBUF_INIT;
+
+ if (S_ISDIR(mode))
+ return READ_TREE_RECURSIVE;
+
+ strbuf_add(&full_name, base->buf, base->len);
+ strbuf_addstr(&full_name, path);
+ it = string_list_insert(&s->change, full_name.buf);
+ d = it->util;
+ if (!d) {
+ CALLOC_ARRAY(d, 1);
+ it->util = d;
+ }
+
+ d->index_status = DIFF_STATUS_ADDED;
+ /* Leave {mode,oid}_head zero for adds. */
+ d->mode_index = mode;
+ oidcpy(&d->oid_index, oid);
+ s->committable = 1;
+ strbuf_release(&full_name);
+ return 0;
+}
+
static void wt_status_collect_changes_initial(struct wt_status *s)
{
struct index_state *istate = s->repo->index;
@@ -671,6 +701,27 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
continue;
if (ce_intent_to_add(ce))
continue;
+ if (S_ISSPARSEDIR(ce->ce_mode)) {
+ /*
+ * This is a sparse directory entry, so we want to collect all
+ * of the added files within the tree. This requires recursively
+ * expanding the trees to find the elements that are new in this
+ * tree and marking them with DIFF_STATUS_ADDED.
+ */
+ struct strbuf base = STRBUF_INIT;
+ struct pathspec ps = { 0 };
+ struct tree *tree = lookup_tree(istate->repo, &ce->oid);
+
+ ps.recursive = 1;
+ ps.has_wildcard = 1;
+ ps.max_depth = -1;
+
+ strbuf_add(&base, ce->name, ce->ce_namelen);
+ read_tree_at(istate->repo, tree, &base, &ps,
+ add_file_to_list, s);
+ continue;
+ }
+
it = string_list_insert(&s->change, ce->name);
d = it->util;
if (!d) {
@@ -1492,9 +1543,12 @@ static void show_sparse_checkout_in_use(struct wt_status *s,
if (s->state.sparse_checkout_percentage == SPARSE_CHECKOUT_DISABLED)
return;
- status_printf_ln(s, color,
- _("You are in a sparse checkout with %d%% of tracked files present."),
- s->state.sparse_checkout_percentage);
+ if (s->state.sparse_checkout_percentage == SPARSE_CHECKOUT_SPARSE_INDEX)
+ status_printf_ln(s, color, _("You are in a sparse checkout."));
+ else
+ status_printf_ln(s, color,
+ _("You are in a sparse checkout with %d%% of tracked files present."),
+ s->state.sparse_checkout_percentage);
wt_longstatus_print_trailer(s);
}
@@ -1652,6 +1706,11 @@ static void wt_status_check_sparse_checkout(struct repository *r,
return;
}
+ if (r->index->sparse_index) {
+ state->sparse_checkout_percentage = SPARSE_CHECKOUT_SPARSE_INDEX;
+ return;
+ }
+
for (i = 0; i < r->index->cache_nr; i++) {
struct cache_entry *ce = r->index->cache[i];
if (ce_skip_worktree(ce))