All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: dstolee@microsoft.com, Elijah Newren <newren@gmail.com>,
	Elijah Newren <newren@gmail.com>
Subject: [PATCH 1/2] [RFC] wt-status: show sparse checkout status as well
Date: Tue, 16 Jun 2020 23:33:32 +0000	[thread overview]
Message-ID: <462cee857ef30c413eda0abe655b123f32b3877e.1592350413.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.808.git.git.1592350413.gitgitgadget@gmail.com>

From: Elijah Newren <newren@gmail.com>

Some of the early feedback of folks trying out sparse-checkouts at
$dayjob is that sparse checkouts can sometimes be disorienting; users
can forget that they had a sparse-checkout and then wonder where files
went.  Add some output to 'git status' in the form of a simple line that
states:

    You are in a sparse checkout with 35% of files present.

where, obviously, the exact figure changes depending on what percentage
of files from the index do not have the SKIP_WORKTREE bit set.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 wt-status.c | 35 +++++++++++++++++++++++++++++++++++
 wt-status.h |  1 +
 2 files changed, 36 insertions(+)

diff --git a/wt-status.c b/wt-status.c
index 98dfa6f73f9..687d2ab1ba1 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1484,6 +1484,16 @@ 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 != -1)
+		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 +1633,27 @@ 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) {
+		state->sparse_checkout_percentage = -1;
+		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 +1689,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 +1713,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 != -1)
+		show_sparse_checkout_in_use(s, state_color);
 }
 
 static void wt_longstatus_print(struct wt_status *s)
diff --git a/wt-status.h b/wt-status.h
index 73ab5d4da1c..4550004003a 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -90,6 +90,7 @@ struct wt_status_state {
 	int bisect_in_progress;
 	int revert_in_progress;
 	int detached_at;
+	int sparse_checkout_percentage; /* -1 == not in sparse checkout */
 	char *branch;
 	char *onto;
 	char *detached_from;
-- 
gitgitgadget


  reply	other threads:[~2020-06-16 23:33 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-16 23:33 [PATCH 0/2] Sparse checkout status Elijah Newren via GitGitGadget
2020-06-16 23:33 ` Elijah Newren via GitGitGadget [this message]
2020-06-17 14:50   ` [PATCH 1/2] [RFC] wt-status: show sparse checkout status as well Derrick Stolee
2020-06-17 15:46     ` Elijah Newren
2020-06-16 23:33 ` [PATCH 2/2] [RFC] git-prompt: include sparsity state " Elijah Newren via GitGitGadget
2020-06-18 20:49 ` [PATCH v2 0/2] Sparse checkout status Elijah Newren via GitGitGadget
2020-06-18 20:49   ` [PATCH v2 1/2] wt-status: show sparse checkout status as well Elijah Newren via GitGitGadget
2020-06-18 20:49   ` [PATCH v2 2/2] git-prompt: include sparsity state " Elijah Newren via GitGitGadget
2020-06-19 16:15     ` SZEDER Gábor
2020-06-19 16:33       ` Junio C Hamano
2020-06-19 16:35         ` Junio C Hamano
2020-06-18 21:45   ` [PATCH v2 0/2] Sparse checkout status Junio C Hamano
2020-06-18 23:18     ` Elijah Newren
2020-06-21  1:34       ` Elijah Newren
2020-06-21  5:21   ` [PATCH v3 0/3] " Elijah Newren via GitGitGadget
2020-06-21  5:21     ` [PATCH v3 1/3] wt-status: show sparse checkout status as well Elijah Newren via GitGitGadget
2020-06-21  5:21     ` [PATCH v3 2/3] git-prompt: document how in-progress operations affect the prompt Elijah Newren via GitGitGadget
2020-06-21  5:21     ` [PATCH v3 3/3] git-prompt: include sparsity state as well Elijah Newren via GitGitGadget
2020-06-22 16:35       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=462cee857ef30c413eda0abe655b123f32b3877e.1592350413.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=newren@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.