git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: ZheNing Hu <adlternative@gmail.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: "ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com>,
	"Git List" <git@vger.kernel.org>,
	"Junio C Hamano" <gitster@pobox.com>,
	"Christian Couder" <christian.couder@gmail.com>,
	"Hariom Verma" <hariom18599@gmail.com>,
	"brian m. carlson" <sandals@crustytoothpaste.net>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>
Subject: Re: [PATCH 2/2] checkout: introduce "--to-branch" option
Date: Sat, 11 Dec 2021 15:11:24 +0800	[thread overview]
Message-ID: <CAOLTT8Qt57C41fiq0C+8szj9OMwUexJq_pV2QNwy8AsgoZscDg@mail.gmail.com> (raw)
In-Reply-To: <211210.86y24sdd7k.gmgdl@evledraar.gmail.com>

Ævar Arnfjörð Bjarmason <avarab@gmail.com> 于2021年12月10日周五 17:24写道:
> > +-w::
> > +--to-branch::
> > +     Rather than checking out a commit to work on it, checkout out
> > +     to the unique branch on it. If there are multiple branches on
> > +     the commit, the checkout will fail.
> > +
>
> So basically what this option implements is something that could be done
> as a shellscript of:
>
>         git_checkout_branch_from_oid () {
>                 rev=$1
>                 git for-each-ref --format='%(refname:strip=2)' --points-at $rev >/tmp/found
>                 if test $(wc -l </tmp/found) -ne 1
>                 then
>                         echo "Goldilocks error in finding $rev: $(cat /tmp/found)"
>                         return 1
>                 fi
>                 git checkout $found
>         }
>

Yes, this is the effect I expect, and it can indeed be done through
the shellscript.

> Which is not to say that it isn't useful, but that I think adding this
> to "git checkout" specifically is adding this to the wrong level. Isn't
> this useful to most things that parse revisions? I.e. wouldn't a better
> interface be via the peel syntax?
>
>     oid=$(git rev-parse HEAD)
>     git checkout $oid^{tobranch}
>
> Doing it that way would allow any arbitrary command that takes revisions
> now access to that, and we could have e.g. "^{tobranches}" too, so you
> could do:
>
>     git for-each-ref --format='%(refname:strip=2)' $oid^{tobranches}
>
> Or:
>
>     git log $oid^{tobranches}
>

Very good inspiration, putting "oid -> branches" in peel will be more elegant
and useful.

> I think implementing that is a bit harder. It's peel_onion() in
> object-name.c. I think parse_branchname_arg() via get_oid_mb() is now
> only capable of filling in an OID for a given name, and then checking
> out that name comes as a separate step, and you can't just return
> e.g. "master".
>
> But I don't think anything stops us from adjusting those functions a bit
> so that get_oid_with_context(() and friends could pass down say an
> optional "struct string_list *", and the "peel" could then be expanded
> to that.
>

I agree.

> Similar to how we have "git chekout -", and the "-" is understood by
> some commands, but not all (via some opt-in whose location I forget...).

"-" is parsed as "@{-1}".

Thanks.
--
ZheNing Hu

  reply	other threads:[~2021-12-11  7:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-10  6:22 [PATCH 0/2] checkout: introduce "--to-branch" option ZheNing Hu via GitGitGadget
2021-12-10  6:22 ` [PATCH 1/2] checkout: handling branch_info memory leak ZheNing Hu via GitGitGadget
2021-12-10  7:13   ` Ævar Arnfjörð Bjarmason
2021-12-10  6:22 ` [PATCH 2/2] checkout: introduce "--to-branch" option ZheNing Hu via GitGitGadget
2021-12-10  8:34   ` Christian Couder
2021-12-11  6:34     ` ZheNing Hu
2021-12-10  8:59   ` Ævar Arnfjörð Bjarmason
2021-12-11  7:11     ` ZheNing Hu [this message]
2021-12-10 11:51   ` Bagas Sanjaya
2021-12-11  7:12     ` ZheNing Hu
2021-12-10 22:14   ` Junio C Hamano
2021-12-11  7:51     ` ZheNing Hu
2021-12-12 18:46       ` Junio C Hamano
2021-12-13 19:55         ` Ævar Arnfjörð Bjarmason
2021-12-13 21:36           ` Junio C Hamano
2021-12-13 21:52             ` Junio C Hamano

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=CAOLTT8Qt57C41fiq0C+8szj9OMwUexJq_pV2QNwy8AsgoZscDg@mail.gmail.com \
    --to=adlternative@gmail.com \
    --cc=avarab@gmail.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=hariom18599@gmail.com \
    --cc=pclouds@gmail.com \
    --cc=sandals@crustytoothpaste.net \
    --cc=sunshine@sunshineco.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).