git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Derrick Stolee <stolee@gmail.com>
To: Alex Henrie <alexhenrie24@gmail.com>,
	git@vger.kernel.org, dstolee@microsoft.com, gitster@pobox.com,
	davvid@gmail.com
Subject: Re: [PATCH 2/3] diffcore-break: use a goto instead of a redundant if statement
Date: Thu, 26 Sep 2019 09:12:17 -0400	[thread overview]
Message-ID: <5382f6cc-d699-0c99-6d61-60cae45f27c2@gmail.com> (raw)
In-Reply-To: <20190925020158.751492-3-alexhenrie24@gmail.com>

On 9/24/2019 10:01 PM, Alex Henrie wrote:
> Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
> ---
>  diffcore-break.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/diffcore-break.c b/diffcore-break.c
> index 875aefd3fe..f6ab74141b 100644
> --- a/diffcore-break.c
> +++ b/diffcore-break.c
> @@ -286,18 +286,17 @@ void diffcore_merge_broken(void)
>  					/* Peer survived.  Merge them */
>  					merge_broken(p, pp, &outq);
>  					q->queue[j] = NULL;
> -					break;
> +					goto done;
>  				}
>  			}
> -			if (q->nr <= j)
> -				/* The peer did not survive, so we keep
> -				 * it in the output.
> -				 */
> -				diff_q(&outq, p);
> +			/* The peer did not survive, so we keep
> +			 * it in the output.
> +			 */
>  		}
> -		else
> -			diff_q(&outq, p);
> +		diff_q(&outq, p);
>  	}
> +
> +done:
>  	free(q->queue);
>  	*q = outq;

This took a little more context to check.

The "if (q->nr <= j)" condition essentially means "did the
for loop above end via the sentinel, not a break?" This
means that the diff_q() call is run if the for loop finishes
normally OR if we hit the visible "else" call.

There is some subtlety with the if / else if / else conditions.
The 'if' condition has a 'continue' which avoids the diff_q in
its new position.

Something like the two paragraphs above would be good to add
to the commit message so we can more easily read this patch
in the future.

Here is the full method context (in master) to help others:

void diffcore_merge_broken(void)
{
        struct diff_queue_struct *q = &diff_queued_diff;
        struct diff_queue_struct outq;
        int i, j;

        DIFF_QUEUE_CLEAR(&outq);

        for (i = 0; i < q->nr; i++) {
                struct diff_filepair *p = q->queue[i];
                if (!p)
                        /* we already merged this with its peer */
                        continue;
                else if (p->broken_pair &&
                         !strcmp(p->one->path, p->two->path)) {
                        /* If the peer also survived rename/copy, then
                         * we merge them back together.
                         */
                        for (j = i + 1; j < q->nr; j++) {
                                struct diff_filepair *pp = q->queue[j];
                                if (pp->broken_pair &&
                                    !strcmp(pp->one->path, pp->two->path) &&
                                    !strcmp(p->one->path, pp->two->path)) {
                                        /* Peer survived.  Merge them */
                                        merge_broken(p, pp, &outq);
                                        q->queue[j] = NULL;
                                        break;
                                }
                        }
                        if (q->nr <= j)
                                /* The peer did not survive, so we keep
                                 * it in the output.
                                 */
                                diff_q(&outq, p);
                }
                else
                        diff_q(&outq, p);
        }
        free(q->queue);
        *q = outq;

        return;
}

  reply	other threads:[~2019-09-26 13:12 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-25  2:01 [PATCH 0/3] scan-build fixes Alex Henrie
2019-09-25  2:01 ` [PATCH 1/3] commit-graph: remove a duplicate assignment Alex Henrie
2019-09-26 13:02   ` Derrick Stolee
2019-09-26 18:05     ` Alex Henrie
2019-09-25  2:01 ` [PATCH 2/3] diffcore-break: use a goto instead of a redundant if statement Alex Henrie
2019-09-26 13:12   ` Derrick Stolee [this message]
2019-09-25  2:01 ` [PATCH 3/3] wrapper: use a loop instead of repetitive statements Alex Henrie
2019-09-26 13:13   ` Derrick Stolee
2019-09-26 20:14     ` Johannes Schindelin
2019-09-27  2:50       ` Jeff King
2019-09-29  0:51         ` Alex Henrie
2019-09-27  2:45   ` Jeff King
2019-09-27 11:48     ` Derrick Stolee

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=5382f6cc-d699-0c99-6d61-60cae45f27c2@gmail.com \
    --to=stolee@gmail.com \
    --cc=alexhenrie24@gmail.com \
    --cc=davvid@gmail.com \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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 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 NNTP newsgroup(s).