From: Junio C Hamano <gitster@pobox.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Rodrigo Silva Mendoza <rodrigosilvamendoza3@gmail.com>,
git@vger.kernel.org
Subject: Re: Best way to update `HEAD` in mirrored repos
Date: Fri, 10 Jun 2022 14:53:44 -0700 [thread overview]
Message-ID: <xmqq5yl8chhz.fsf@gitster.g> (raw)
In-Reply-To: <nycvar.QRO.7.76.6.2206102327540.353@tvgsbejvaqbjf.bet> (Johannes Schindelin's message of "Fri, 10 Jun 2022 23:46:37 +0200 (CEST)")
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> diff --git a/builtin/remote.c b/builtin/remote.c
> index eddd40c8f87..fead15adb97 100644
> --- a/builtin/remote.c
> +++ b/builtin/remote.c
> @@ -1344,7 +1344,7 @@ static int show(int argc, const char **argv)
>
> static int set_head(int argc, const char **argv)
> {
> - int i, opt_a = 0, opt_d = 0, result = 0;
> + int i, opt_a = 0, opt_d = 0, result = 0, is_mirror = 0;
> struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
> char *head_name = NULL;
>
> @@ -1357,8 +1357,16 @@ static int set_head(int argc, const char **argv)
> };
> argc = parse_options(argc, argv, NULL, options, builtin_remote_sethead_usage,
> 0);
> - if (argc)
> - strbuf_addf(&buf, "refs/remotes/%s/HEAD", argv[0]);
> + if (argc) {
> + struct remote *remote = remote_get(argv[0]);
> +
> + if (!remote || !remote->mirror)
> + strbuf_addf(&buf, "refs/remotes/%s/HEAD", argv[0]);
> + else {
> + is_mirror = 1;
> + strbuf_addstr(&buf, "HEAD");
> + }
> + }
Good.
Regardless of the "mirror" issue, it makes tons of sense to ask the
remote API how the remote-tracking refs for the given remote is set
up, instead of assuming that it must be "refs/remotes/<remote>"
blindly like in the original code.
That way, we could even handle a case like so:
[remote "frotz"]
fetch = +refs/heads/*:refs/remotes/nitfol/*
Their HEAD should be mapped to refs/remotes/nitfol/HEAD on our end,
so set-head should be able to notice that, too, if we go further
with your "do not assume, instead ask remote API" approach.
Thanks.
next prev parent reply other threads:[~2022-06-10 21:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-08 20:36 Best way to update `HEAD` in mirrored repos Rodrigo Silva Mendoza
2022-06-08 22:53 ` Junio C Hamano
2022-06-09 5:01 ` Rodrigo Silva Mendoza
2022-06-09 8:02 ` Johannes Schindelin
2022-06-09 14:46 ` Rodrigo Silva Mendoza
2022-06-10 21:46 ` Johannes Schindelin
2022-06-10 21:53 ` Junio C Hamano [this message]
2022-06-15 4:11 ` Rodrigo Silva Mendoza
2022-06-15 4:18 ` Rodrigo Silva Mendoza
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=xmqq5yl8chhz.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=rodrigosilvamendoza3@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).