git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Stepan Kasal <kasal@ucw.cz>, John Keeping <john@keeping.me.uk>,
	git@vger.kernel.org
Subject: Re: [PATCH] merge-base: handle --fork-point without reflog
Date: Wed, 12 Oct 2016 14:29:49 -0700	[thread overview]
Message-ID: <xmqqd1j52r3m.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20161012201040.pyrp6bktz3fgmqzn@sigill.intra.peff.net> (Jeff King's message of "Wed, 12 Oct 2016 16:10:40 -0400")

Jeff King <peff@peff.net> writes:

> Subject: merge-base: handle --fork-point without reflog
>
> The --fork-point option looks in the reflog to try to find
> where a derived branch forked from a base branch. However,
> if the reflog for the base branch is totally empty (as it
> commonly is right after cloning, which does not write a
> reflog entry), then our for_each_reflog call will not find
> any entries, and we will come up with no merge base, even
> though there may be one with the current tip of the base.
>
> We can fix this by just adding the current tip to
> our list of collected entries.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> It would actually be correct to just unconditionally add the ref tip, as
> add_one_commit already drops duplicates. But it would only be necessary
> in other cases if you have a broken reflog which is missing the entry
> that moved us to the current tip.

Makes sense.  And doing conditionally is not much more work ;-)

Thanks.

>
>  builtin/merge-base.c  | 3 +++
>  t/t6010-merge-base.sh | 6 ++++++
>  2 files changed, 9 insertions(+)
>
> diff --git a/builtin/merge-base.c b/builtin/merge-base.c
> index c0d1822..b572a37 100644
> --- a/builtin/merge-base.c
> +++ b/builtin/merge-base.c
> @@ -173,6 +173,9 @@ static int handle_fork_point(int argc, const char **argv)
>  	revs.initial = 1;
>  	for_each_reflog_ent(refname, collect_one_reflog_ent, &revs);
>  
> +	if (!revs.nr && !get_sha1(refname, sha1))
> +		add_one_commit(sha1, &revs);
> +
>  	for (i = 0; i < revs.nr; i++)
>  		revs.commit[i]->object.flags &= ~TMP_MARK;
>  
> diff --git a/t/t6010-merge-base.sh b/t/t6010-merge-base.sh
> index e0c5f44..31db7b5 100755
> --- a/t/t6010-merge-base.sh
> +++ b/t/t6010-merge-base.sh
> @@ -260,6 +260,12 @@ test_expect_success 'using reflog to find the fork point' '
>  	test_cmp expect3 actual
>  '
>  
> +test_expect_success '--fork-point works with empty reflog' '
> +	git -c core.logallrefupdates=false branch no-reflog base &&
> +	git merge-base --fork-point no-reflog derived &&
> +	test_cmp expect3 actual
> +'
> +
>  test_expect_success 'merge-base --octopus --all for complex tree' '
>  	# Best common ancestor for JE, JAA and JDD is JC
>  	#             JE

  reply	other threads:[~2016-10-12 21:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-12 10:37 Bug with git merge-base and a packed ref Stepan Kasal
2016-10-12 16:32 ` Jeff King
2016-10-12 19:33   ` Stepan Kasal
2016-10-12 20:10   ` [PATCH] merge-base: handle --fork-point without reflog Jeff King
2016-10-12 21:29     ` Junio C Hamano [this message]
2016-10-13  6:34     ` Stepan Kasal

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=xmqqd1j52r3m.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=john@keeping.me.uk \
    --cc=kasal@ucw.cz \
    --cc=peff@peff.net \
    /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).