git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Derrick Stolee <stolee@gmail.com>
To: "René Scharfe" <l.s.r@web.de>, "Git Mailing List" <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>,
	Derrick Stolee <dstolee@microsoft.com>
Subject: Re: [PATCH] commit-graph: use commit_list_count()
Date: Sun, 15 Sep 2019 22:05:03 -0400	[thread overview]
Message-ID: <eb0aeb20-4fa0-7898-c3c8-139526667f5d@gmail.com> (raw)
In-Reply-To: <1d28fb89-6ed6-b70f-762c-b65cffeb6705@web.de>

On 9/15/2019 1:07 PM, René Scharfe wrote:
> Let commit_list_count() count the number of parents instead of
> duplicating it.  Also store the result in an unsigned int, as that's
> what the function returns, and the count is never negative.

I was unfamiliar with this method, but it obviously removes some
redundant code. We would have many more problems before the signed-ness
of the int was important, but good to use the type matching the
method.

Thanks,
-Stolee

> 
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
>  commit-graph.c | 17 ++++++-----------
>  1 file changed, 6 insertions(+), 11 deletions(-)
> 
> diff --git a/commit-graph.c b/commit-graph.c
> index 9b02d2c426..5b0d6b5adc 100644
> --- a/commit-graph.c
> +++ b/commit-graph.c
> @@ -1279,7 +1279,6 @@ static uint32_t count_distinct_commits(struct write_commit_graph_context *ctx)
>  static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
>  {
>  	uint32_t i;
> -	struct commit_list *parent;
> 
>  	ctx->num_extra_edges = 0;
>  	if (ctx->report_progress)
> @@ -1287,7 +1286,8 @@ static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
>  			_("Finding extra edges in commit graph"),
>  			ctx->oids.nr);
>  	for (i = 0; i < ctx->oids.nr; i++) {
> -		int num_parents = 0;
> +		unsigned int num_parents;
> +
>  		display_progress(ctx->progress, i + 1);
>  		if (i > 0 && oideq(&ctx->oids.list[i - 1], &ctx->oids.list[i]))
>  			continue;
> @@ -1301,10 +1301,7 @@ static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
> 
>  		parse_commit_no_graph(ctx->commits.list[ctx->commits.nr]);
> 
> -		for (parent = ctx->commits.list[ctx->commits.nr]->parents;
> -		     parent; parent = parent->next)
> -			num_parents++;
> -
> +		num_parents = commit_list_count(ctx->commits.list[ctx->commits.nr]->parents);
>  		if (num_parents > 2)
>  			ctx->num_extra_edges += num_parents - 1;
> 
> @@ -1616,8 +1613,7 @@ static int commit_compare(const void *_a, const void *_b)
> 
>  static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
>  {
> -	uint32_t i, num_parents;
> -	struct commit_list *parent;
> +	uint32_t i;
> 
>  	if (ctx->report_progress)
>  		ctx->progress = start_delayed_progress(
> @@ -1635,10 +1631,9 @@ static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
>  			die(_("unexpected duplicate commit id %s"),
>  			    oid_to_hex(&ctx->commits.list[i]->object.oid));
>  		} else {
> -			num_parents = 0;
> -			for (parent = ctx->commits.list[i]->parents; parent; parent = parent->next)
> -				num_parents++;
> +			unsigned int num_parents;
> 
> +			num_parents = commit_list_count(ctx->commits.list[i]->parents);
>  			if (num_parents > 2)
>  				ctx->num_extra_edges += num_parents - 1;
>  		}
> --
> 2.23.0
> 


      reply	other threads:[~2019-09-16  2:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-15 17:07 [PATCH] commit-graph: use commit_list_count() René Scharfe
2019-09-16  2:05 ` Derrick Stolee [this message]

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=eb0aeb20-4fa0-7898-c3c8-139526667f5d@gmail.com \
    --to=stolee@gmail.com \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).