summaryrefslogtreecommitdiff
path: root/wt-status.c
diff options
context:
space:
mode:
Diffstat (limited to 'wt-status.c')
-rw-r--r--wt-status.c62
1 files changed, 51 insertions, 11 deletions
diff --git a/wt-status.c b/wt-status.c
index 98dfa6f73f..d75399085d 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -8,7 +8,7 @@
#include "diffcore.h"
#include "quote.h"
#include "run-command.h"
-#include "argv-array.h"
+#include "strvec.h"
#include "remote.h"
#include "refs.h"
#include "submodule.h"
@@ -913,17 +913,16 @@ static void wt_longstatus_print_submodule_summary(struct wt_status *s, int uncom
struct strbuf summary = STRBUF_INIT;
char *summary_content;
- argv_array_pushf(&sm_summary.env_array, "GIT_INDEX_FILE=%s",
- s->index_file);
+ strvec_pushf(&sm_summary.env_array, "GIT_INDEX_FILE=%s", s->index_file);
- argv_array_push(&sm_summary.args, "submodule");
- argv_array_push(&sm_summary.args, "summary");
- argv_array_push(&sm_summary.args, uncommitted ? "--files" : "--cached");
- argv_array_push(&sm_summary.args, "--for-status");
- argv_array_push(&sm_summary.args, "--summary-limit");
- argv_array_pushf(&sm_summary.args, "%d", s->submodule_summary);
+ strvec_push(&sm_summary.args, "submodule");
+ strvec_push(&sm_summary.args, "summary");
+ strvec_push(&sm_summary.args, uncommitted ? "--files" : "--cached");
+ strvec_push(&sm_summary.args, "--for-status");
+ strvec_push(&sm_summary.args, "--summary-limit");
+ strvec_pushf(&sm_summary.args, "%d", s->submodule_summary);
if (!uncommitted)
- argv_array_push(&sm_summary.args, s->amend ? "HEAD^" : "HEAD");
+ strvec_push(&sm_summary.args, s->amend ? "HEAD^" : "HEAD");
sm_summary.git_cmd = 1;
sm_summary.no_stdin = 1;
@@ -1484,6 +1483,18 @@ static void show_bisect_in_progress(struct wt_status *s,
wt_longstatus_print_trailer(s);
}
+static void show_sparse_checkout_in_use(struct wt_status *s,
+ const char *color)
+{
+ 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);
+ wt_longstatus_print_trailer(s);
+}
+
/*
* Extract branch information from rebase/bisect
*/
@@ -1623,6 +1634,31 @@ int wt_status_check_bisect(const struct worktree *wt,
return 0;
}
+static void wt_status_check_sparse_checkout(struct repository *r,
+ struct wt_status_state *state)
+{
+ int skip_worktree = 0;
+ int i;
+
+ if (!core_apply_sparse_checkout || r->index->cache_nr == 0) {
+ /*
+ * Don't compute percentage of checked out files if we
+ * aren't in a sparse checkout or would get division by 0.
+ */
+ state->sparse_checkout_percentage = SPARSE_CHECKOUT_DISABLED;
+ return;
+ }
+
+ for (i = 0; i < r->index->cache_nr; i++) {
+ struct cache_entry *ce = r->index->cache[i];
+ if (ce_skip_worktree(ce))
+ skip_worktree++;
+ }
+
+ state->sparse_checkout_percentage =
+ 100 - (100 * skip_worktree)/r->index->cache_nr;
+}
+
void wt_status_get_state(struct repository *r,
struct wt_status_state *state,
int get_detached_from)
@@ -1658,6 +1694,7 @@ void wt_status_get_state(struct repository *r,
}
if (get_detached_from)
wt_status_get_detached_from(r, state);
+ wt_status_check_sparse_checkout(r, state);
}
static void wt_longstatus_print_state(struct wt_status *s)
@@ -1681,6 +1718,9 @@ static void wt_longstatus_print_state(struct wt_status *s)
show_revert_in_progress(s, state_color);
if (state->bisect_in_progress)
show_bisect_in_progress(s, state_color);
+
+ if (state->sparse_checkout_percentage != SPARSE_CHECKOUT_DISABLED)
+ show_sparse_checkout_in_use(s, state_color);
}
static void wt_longstatus_print(struct wt_status *s)
@@ -1994,7 +2034,7 @@ static void wt_porcelain_print(struct wt_status *s)
* [# branch.upstream <upstream><eol>
* [# branch.ab +<ahead> -<behind><eol>]]
*
- * <commit> ::= the current commit hash or the the literal
+ * <commit> ::= the current commit hash or the literal
* "(initial)" to indicate an initialized repo
* with no commits.
*