unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: Ricardo Wurmus <rekado@elephly.net>, 49252@debbugs.gnu.org
Subject: [bug#49252] [PATCH] Channels defaulting to HEAD instead of ‘master’
Date: Tue, 10 Aug 2021 20:34:58 -0400	[thread overview]
Message-ID: <87czqkizt9.fsf@kyleam.com> (raw)
In-Reply-To: <87r1f1sp2x.fsf@gnu.org>

Ludovic Courtès writes:

> Right.  We can add the missing procedures in Guile-Git, but in the
> meantime, maybe we could create .git/refs/origin/HEAD “by hand”?

Yep, for the default branch $NAME, "ref: refs/remotes/origin/$NAME\n"
can be written to .git/refs/origin/HEAD.

With respect to getting the default branch, I said in my last message
that I thought it'd be possible to glean the target from the remote-ls
output.  To flesh that out a bit:

--8<---------------cut here---------------start------------->8---
(use-modules
 (git)
 (system foreign))

(define origin (remote-lookup (repository-open ".") "origin"))
(remote-connect origin)

(define head (car (remote-ls origin)))

(define target-pt
  (make-pointer
   ((record-accessor (record-type-descriptor head) 'symref-target)
    head)))

(if (not (null-pointer? target-pt))
    (display (pointer->string target-pt)))  ;; => refs/heads/master
--8<---------------cut here---------------end--------------->8---

And that looks like it matches what libgit2's
git_remote_default_branch() does for the non-guessing case (see below),
so stopping there may be sufficient for a compatibility kludge.

--8<---------------cut here---------------start------------->8---
	if ((error = git_remote_ls(&heads, &heads_len, remote)) < 0)
		goto done;

	if (heads_len == 0 || strcmp(heads[0]->name, GIT_HEAD_FILE)) {
		error = GIT_ENOTFOUND;
		goto done;
	}

	if ((error = git_buf_sanitize(out)) < 0)
		return error;

	/* the first one must be HEAD so if that has the symref info, we're done */
	if (heads[0]->symref_target) {
		error = git_buf_puts(out, heads[0]->symref_target);
		goto done;
	}

	/*
	 * If there's no symref information, we have to look over them
	 * and guess. We return the first match unless the default
	 * branch is a candidate. Then we return the default branch.
*/--8<---------------cut here---------------end--------------->8---




  reply	other threads:[~2021-08-11  0:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-28 12:56 [bug#49252] [PATCH] Channels defaulting to HEAD instead of ‘master’ Ludovic Courtès
2021-07-09  0:38 ` Kyle Meyer
2021-08-04 15:04   ` Ludovic Courtès
2021-08-08 23:28     ` Kyle Meyer
2021-08-09  9:12       ` Ludovic Courtès
2021-08-10  2:10         ` Kyle Meyer
2021-08-10  8:04           ` Ludovic Courtès
2021-08-11  0:34             ` Kyle Meyer [this message]
2021-08-08 13:53 ` Ricardo Wurmus
2021-08-08 23:08   ` Kyle Meyer

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: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87czqkizt9.fsf@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=49252@debbugs.gnu.org \
    --cc=ludo@gnu.org \
    --cc=rekado@elephly.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://git.savannah.gnu.org/cgit/guix.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).