]> git.ipfire.org Git - thirdparty/git.git/blobdiff - wt-status.c
reftable: (de)serialization for the polymorphic record type.
[thirdparty/git.git] / wt-status.c
index 42b673571696bd398fea34b969853975de2a010b..eaed30eafba8005994894fac2e4046ee00987486 100644 (file)
@@ -639,7 +639,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
                 * mode by passing a command line option we do not ignore any
                 * changed submodule SHA-1s when comparing index and HEAD, no
                 * matter what is configured. Otherwise the user won't be
-                * shown any submodules she manually added (and which are
+                * shown any submodules manually added (and which are
                 * staged to be committed), which would be really confusing.
                 */
                handle_ignore_submodules_arg(&rev.diffopt, "dirty");
@@ -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) {
@@ -699,14 +750,13 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
 static void wt_status_collect_untracked(struct wt_status *s)
 {
        int i;
-       struct dir_struct dir;
+       struct dir_struct dir = DIR_INIT;
        uint64_t t_begin = getnanotime();
        struct index_state *istate = s->repo->index;
 
        if (!s->show_untracked_files)
                return;
 
-       dir_init(&dir);
        if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES)
                dir.flags |=
                        DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
@@ -1493,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);
 }
 
@@ -1653,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))