git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Denton Liu <liu.denton@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH 3/3] checkout: allow -b/-B to work on a merge base
Date: Fri, 26 Apr 2019 13:59:45 +0900	[thread overview]
Message-ID: <xmqqh8aluzsu.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <xmqqmukdv57q.fsf@gitster-ct.c.googlers.com> (Junio C. Hamano's message of "Fri, 26 Apr 2019 12:02:49 +0900")

Junio C Hamano <gitster@pobox.com> writes:

> Denton Liu <liu.denton@gmail.com> writes:
>
>> -	new_branch_info->name = arg;
>> +	new_branch_info->name = strstr(arg, "...") ?
>> +		xstrdup(oid_to_hex(rev)) :
>> +		arg;
>
> Can we do better?
>
> I am not sure why we want to hardcode the knowledge of "..." syntax
> like this here.  "git checkout A...B" introduced in 2009 needed only
> a single-liner change from get_sha1() to get_sha1_mb() without making
> the ugly implementation detail seep into this layer.

I _think_ what you are trying to work around is that a syntax that
is not understood as a reference to a single revision by get_oid()
but is understood as such by get_oid_mb() can be in the .name field,
and that eventually gets passed to branch.c::create_branch() as
"start_name" in the codepath.  The function ought to know that
start_name wants to name a single revision and never a revision
range, but fails to use get_oid_mb() but just a plain get_oid(),
and fails.

If that is the case, wouldn't a better fix be more like the
attached?  This hasn't even been compile tested, but I suspect that
without taking this approach, you would introduce a new "bug",
namely, that

	$ git checkout -b newbranch master...

ought to behave exactly like

	$ git branch newbranch master...
	$ git checkout newbranch

But the first step would hit the same branch.c::create_branch()
and would not work, no?

The reason I care about hiding syntax details like "..." from users
of get_*_mb() is because I anticipate that we'll want to extend it
to things other than just "merge base between two" with syntax
different from "..." (while probably renaming _mb suffix to
something else).

The codebase is not ready to replace get_oid() with get_oid_mb()
blindly and wholesale, I think, as the former is used as an
implementation detail of parsing range syntax like A..B but places
that are end user facing *and* expect to take only a single revision
(e.g. "rebase --onto <commit>", "checkout <commit>", etc.) and never
a range that currently use get_oid() should be able to get replaced
with get_oid_mb() to learn "A...B means their merge base, not a
symmetric range" semantics for free.

 branch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/branch.c b/branch.c
index 28b81a7e02..a84c8aaca2 100644
--- a/branch.c
+++ b/branch.c
@@ -268,7 +268,7 @@ void create_branch(struct repository *r,
 	}
 
 	real_ref = NULL;
-	if (get_oid(start_name, &oid)) {
+	if (get_oid_mb(start_name, &oid)) {
 		if (explicit_tracking) {
 			if (advice_set_upstream_failure) {
 				error(_(upstream_missing), start_name);


  reply	other threads:[~2019-04-26  4:59 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-25 21:10 [PATCH 0/3] checkout: allow -b/-B to work on a merge base Denton Liu
2019-04-25 21:10 ` [PATCH 1/3] t2018: cleanup in current test Denton Liu
2019-04-25 22:34   ` Eric Sunshine
2019-04-26  0:40     ` Denton Liu
2019-04-26  2:50     ` Junio C Hamano
2019-04-26  6:58       ` Eric Sunshine
2019-04-25 21:10 ` [PATCH 2/3] t2018: demonstrate checkout -b merge base bug Denton Liu
2019-04-25 21:10 ` [PATCH 3/3] checkout: allow -b/-B to work on a merge base Denton Liu
2019-04-26  3:02   ` Junio C Hamano
2019-04-26  4:59     ` Junio C Hamano [this message]
2019-04-26 19:21 ` [PATCH v2 0/3] allow checkout and branch to create branches " Denton Liu
2019-04-26 19:21   ` [PATCH v2 1/3] t2018: cleanup in current test Denton Liu
2019-04-26 19:21   ` [PATCH v2 2/3] t2018: demonstrate checkout -b merge base bug Denton Liu
2019-04-26 19:21   ` [PATCH v2 3/3] branch: make create_branch accept a merge base rev Denton Liu
2019-04-26 23:07   ` [PATCH v2 0/3] allow checkout and branch to create branches on a merge base Junio C Hamano
2019-04-26 23:40     ` Denton Liu
2019-04-26 23:52       ` Denton Liu
2019-04-27  0:01         ` Junio C Hamano
2019-04-27 12:02   ` [PATCH v3 0/2] " Denton Liu
2019-04-27 12:02     ` [PATCH v3 1/2] t2018: cleanup in current test Denton Liu
2019-04-27 12:02     ` [PATCH v3 2/2] branch: make create_branch accept a merge base rev Denton Liu

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=xmqqh8aluzsu.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=liu.denton@gmail.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.
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).