git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 0/2] Sparse checkout status

From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Date
Jun 18, 2020, 20:49 UTC
Message-ID
<pull.808.v2.git.git.1592513398.gitgitgadget@gmail.com>
In-Reply-To
<pull.808.git.git.1592350413.gitgitgadget@gmail.com>

Some of the 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. This series adds some output to 'git status' and modifies git-prompt slightly as an attempt to help.

Note that as per discussion on v1, we may want to later add a git sparse-checkout subcommand named something like 'stats' or 'info' or 'status' that provides more detailed information for users to dig deeper. That would be an additional improvement for helping users find out more information once they realize or remember they are in a sparse checkout, this is just aimed at giving them a simple reminder.

Changes since v1:
 * Replaced the -1 magic constant with SPARSE_CHECKOUT_DISABLED
 * Fixed a possible division by 0 (when there are no entries in the index
   AND sparse checkout is enabled; not sure when that'd ever happen but
   still better to guard against...)
 * Slight wording tweaks for the git-prompt commit message
 * Removed the RFC label
Elijah Newren (2):
  wt-status: show sparse checkout status as well
  git-prompt: include sparsity state as well
 contrib/completion/git-prompt.sh |  7 +++++-
 wt-status.c                      | 41 ++++++++++++++++++++++++++++++++
 wt-status.h                      |  2 ++
 3 files changed, 49 insertions(+), 1 deletion(-)
base-commit: b3d7a52fac39193503a0b6728771d1bf6a161464
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-808%2Fnewren%2Fsparse-checkout-status-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-808/newren/sparse-checkout-status-v2
Pull-Request: https://github.com/git/git/pull/808
Range-diff vs v1:
 1:  462cee857ef ! 1:  e266bc39d99 [RFC] wt-status: show sparse checkout status as well
     @@ Metadata
      Author: Elijah Newren <newren@gmail.com>
      
       ## Commit message ##
     -    [RFC] wt-status: show sparse checkout status as well
     +    wt-status: show sparse checkout status as well
      
          Some of the early feedback of folks trying out sparse-checkouts at
          $dayjob is that sparse checkouts can sometimes be disorienting; users
     @@ wt-status.c: static void show_bisect_in_progress(struct wt_status *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);
     ++	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);
      +}
      +
     @@ wt-status.c: int wt_status_check_bisect(const struct worktree *wt,
      +	int skip_worktree = 0;
      +	int i;
      +
     -+	if (!core_apply_sparse_checkout) {
     -+		state->sparse_checkout_percentage = -1;
     ++	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;
      +	}
      +
     @@ wt-status.c: static void wt_longstatus_print_state(struct wt_status *s)
       	if (state->bisect_in_progress)
       		show_bisect_in_progress(s, state_color);
      +
     -+	if (state->sparse_checkout_percentage != -1)
     ++	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)
      
       ## wt-status.h ##
     +@@ wt-status.h: enum wt_status_format {
     + 
     + #define HEAD_DETACHED_AT _("HEAD detached at ")
     + #define HEAD_DETACHED_FROM _("HEAD detached from ")
     ++#define SPARSE_CHECKOUT_DISABLED -1
     + 
     + struct wt_status_state {
     + 	int merge_in_progress;
      @@ wt-status.h: struct wt_status_state {
       	int bisect_in_progress;
       	int revert_in_progress;
       	int detached_at;
     -+	int sparse_checkout_percentage; /* -1 == not in sparse checkout */
     ++	int sparse_checkout_percentage; /* SPARSE_CHECKOUT_DISABLED if not sparse */
       	char *branch;
       	char *onto;
       	char *detached_from;
 2:  64613ad7ad6 ! 2:  17254b30a5b [RFC] git-prompt: include sparsity state as well
     @@ Metadata
      Author: Elijah Newren <newren@gmail.com>
      
       ## Commit message ##
     -    [RFC] git-prompt: include sparsity state as well
     +    git-prompt: include sparsity state as well
      
     -    The current git prompt includes a lot of possible state information, from
     -    various flavors of rebases to cherry-picks, or merges, or bisects.  Add
     +    The current git prompt includes a lot of possible state information from
     +    cherry-picks, merges, bisects, and various flavors of rebases.  Add
          sparsity as another state flavor (though one which can be present
          simultaneously with any of rebase/cherry-pick/merge/bisect).  This extra
          state is shown with an extra
              |SPARSE
     -    substring before the other states.  (Sparsity is probably not going to
     -    change much within a repository, while temporary operations will.  So we
     -    want the temporary operation related state changes to be listed last, to
     -    make them appear closer to where the user types and make them more
     -    likely to be noticed.)  Thus, for example, the prompt might look like:
     +    substring before the other states, providing a prompt that looks like:
              (branchname|SPARSE|REBASE 6/10)
      
     +    The reason for showing the "|SPARSE" substring before other states is to
     +    emphasize those other states.  Sparsity is probably not going to change
     +    much within a repository, while temporary operations will.  So we want
     +    the state changes related to temporary operations to be listed last, to
     +    make them appear closer to where the user types and make them more
     +    likely to be noticed.
     +
          Signed-off-by: Elijah Newren <newren@gmail.com>
      
       ## contrib/completion/git-prompt.sh ##
-- 
gitgitgadget
Previous: Elijah Newren via GitGitGadgetNext: Elijah Newren via GitGitGadget
Message 6 of 19 in “Sparse checkout status”
  1. 0/2 Sparse checkout statusElijah Newren via GitGitGadget, Jun 16, 2020
  2. 1/2 [RFC] wt-status: show sparse checkout status as wellElijah Newren via GitGitGadget, Jun 16, 2020
  3. Derrick StoleeJun 17, 2020
  4. Elijah NewrenJun 17, 2020
  5. 2/2 [RFC] git-prompt: include sparsity state as wellElijah Newren via GitGitGadget, Jun 16, 2020
  6. 0/2 Sparse checkout statusElijah Newren via GitGitGadget, Jun 18, 2020
  7. 1/2 wt-status: show sparse checkout status as wellElijah Newren via GitGitGadget, Jun 18, 2020
  8. 2/2 git-prompt: include sparsity state as wellElijah Newren via GitGitGadget, Jun 18, 2020
  9. SZEDER GáborJun 19, 2020
  10. Junio C HamanoJun 19, 2020
  11. Junio C HamanoJun 19, 2020
  12. Junio C HamanoJun 18, 2020
  13. Elijah NewrenJun 18, 2020
  14. Elijah NewrenJun 21, 2020
  15. 0/3 Sparse checkout statusElijah Newren via GitGitGadget, Jun 21, 2020
  16. 1/3 wt-status: show sparse checkout status as wellElijah Newren via GitGitGadget, Jun 21, 2020
  17. 3/3 git-prompt: include sparsity state as wellElijah Newren via GitGitGadget, Jun 21, 2020
  18. Junio C HamanoJun 22, 2020
  19. 2/3 git-prompt: document how in-progress operations affect the promptElijah Newren via GitGitGadget, Jun 21, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.