Subject: Re: [PATCH] show-branch: fix --no-sparse

From: Junio C Hamano <[email-masked]>
Date: Fri, 21 Jul 2023 07:42:26 -0700

René Scharfe <[email-masked]> writes:

> Since 57343652a5 (show-branch: migrate to parse-options API, 2009-05-21)
> git show-branch has accepted the option --no-sparse, but it does the
> same as --sparse.  That's because it's defined using OPT_SET_INT with a
> value of 0, which sets 0 when negated, too.

Hmph, am I expected to compare these patches with what I sent a few
days ago and pick whichever are the better ones?  Can I delegate
that task to somebody else ;-)?

        jc/am-parseopt-fix		<[email-masked]>
        jc/branch-parseopt-fix		<[email-masked]>
        jc/describe-parseopt-fix	<[email-masked]>
        jc/parse-options-reset		<[email-masked]>
        jc/parse-options-short-help	<[email-masked]>
        jc/parse-options-show-branch	<[email-masked]>
        jc/transport-parseopt-fix	<[email-masked]>

Some of them are already in 'next' as they were so trivial.

Thanks.

> Turn --no-sparse into the opposite of --sparse by using OPT_BOOL and
> storing the option's status directly in a variable named "sparse"
> instead of in negative form in "dense".
>
> Suggested-by: Junio C Hamano <[email-masked]>
> Signed-off-by: René Scharfe <[email-masked]>
> ---
>  builtin/show-branch.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/builtin/show-branch.c b/builtin/show-branch.c
> index a86b3c7677..99b3f4a09a 100644
> --- a/builtin/show-branch.c
> +++ b/builtin/show-branch.c
> @@ -649,7 +649,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
>  	int with_current_branch = 0;
>  	int head_at = -1;
>  	int topics = 0;
> -	int dense = 1;
> +	int sparse = 0;
>  	const char *reflog_base = NULL;
>  	struct option builtin_show_branch_options[] = {
>  		OPT_BOOL('a', "all", &all_heads,
> @@ -676,8 +676,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
>  			    REV_SORT_IN_GRAPH_ORDER),
>  		OPT_BOOL(0, "topics", &topics,
>  			 N_("show only commits not on the first branch")),
> -		OPT_SET_INT(0, "sparse", &dense,
> -			    N_("show merges reachable from only one tip"), 0),
> +		OPT_BOOL(0, "sparse", &sparse,
> +			 N_("show merges reachable from only one tip")),
>  		OPT_SET_INT(0, "date-order", &sort_order,
>  			    N_("topologically sort, maintaining date order "
>  			       "where possible"),
> @@ -940,7 +940,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
>  			    !is_merge_point &&
>  			    (this_flag & (1u << REV_SHIFT)))
>  				continue;
> -			if (dense && is_merge &&
> +			if (!sparse && is_merge &&
>  			    omit_in_dense(commit, rev, num_rev))
>  				continue;
>  			for (i = 0; i < num_rev; i++) {
> --
> 2.41.0