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

Re: [PATCH 1/2] status: count stash entries in separate function

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 21, 2021, 23:38 UTC
Message-ID
<xmqq5ytqgd98.fsf@gitster.g>
In-Reply-To
<20211021222532.463375-2-oystwa@gmail.com>
Øystein Walle <oystwa@gmail.com> writes:
Show 17 quoted lines
> Make the counting of stash entries contained in one simple function as
> it will be used in the next commit.
>
> Signed-off-by: Øystein Walle <oystwa@gmail.com>
> ---
>  wt-status.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/wt-status.c b/wt-status.c
> index e4f29b2b4c..97230477b2 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -948,11 +948,17 @@ static int stash_count_refs(struct object_id *ooid, struct object_id *noid,
>  	return 0;
>  }
>  
> +static int count_stash_entries()

Probably "static int count_stash_entries(void)" was what was meant here.

> +{
> +	int n = 0;

Have a blank line between the block of decls at the beginning of the function and the first statement.

> +	for_each_reflog_ent("refs/stash", stash_count_refs, &n);
> +	return n;
> +}

I briefly wondered if this want to be size_t or some other unsigned integral type, but this is merely refactoring the existing code, so it is not just OK but is correct to use the same "int" as before.

Show 9 quoted lines
>  static void wt_longstatus_print_stash_summary(struct wt_status *s)
>  {
> -	int stash_count = 0;
> +	int stash_count = count_stash_entries();
>  
> -	for_each_reflog_ent("refs/stash", stash_count_refs, &stash_count);
>  	if (stash_count > 0)
>  		status_printf_ln(s, GIT_COLOR_NORMAL,
>  				 Q_("Your stash currently has %d entry",
OK.
Previous: Øystein WalleNext: Øystein Walle
Message 3 of 8 in “Print stash info in the v2 porcelain format”
  1. 0/2 Print stash info in the v2 porcelain formatØystein Walle, Oct 21, 2021
  2. 1/2 status: count stash entries in separate functionØystein Walle, Oct 21, 2021
  3. Junio C HamanoOct 21, 2021
  4. 2/2 status: print stash info with --porcelain=v2 --show-stashØystein Walle, Oct 21, 2021
  5. Junio C HamanoOct 21, 2021
  6. Eric SunshineOct 22, 2021
  7. Junio C HamanoOct 22, 2021
  8. Eric SunshineOct 22, 2021

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.