all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: 70132@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>,
	"Christopher Baines" <guix@cbaines.net>,
	"Josselin Poiret" <dev@jpoiret.xyz>,
	"Ludovic Courtès" <ludo@gnu.org>,
	"Mathieu Othacehe" <othacehe@gnu.org>,
	"Ricardo Wurmus" <rekado@elephly.net>,
	"Simon Tournier" <zimon.toutoune@gmail.com>,
	"Tobias Geerinckx-Rice" <me@tobias.gr>
Subject: [bug#70132] [PATCH 04/11] git: Add ‘tag->commit’ and use it in (guix channels).
Date: Mon,  1 Apr 2024 22:25:16 +0200	[thread overview]
Message-ID: <db8007e3c85705035d9f4f54753e36088f863b6b.1712002698.git.ludo@gnu.org> (raw)
In-Reply-To: <cover.1712002698.git.ludo@gnu.org>

* guix/git.scm (tag->commit): New procedure, taken from…
(resolve-reference): … here.  Use it in the ‘tag’ case.
* guix/channels.scm (resolve-channel-news-entry-tag): Use ‘tag->commit’
instead of custom code.

Change-Id: I46ea387345dc1b695ce0702991a52d0cde29e2f0
---
 guix/channels.scm | 11 +++--------
 guix/git.scm      | 24 +++++++++++++++---------
 2 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/guix/channels.scm b/guix/channels.scm
index 0b776ab211..70608561f9 100644
--- a/guix/channels.scm
+++ b/guix/channels.scm
@@ -26,6 +26,7 @@ (define-module (guix channels)
                            commit-difference
                            repository-info
                            commit-short-id
+                           tag->commit
                            with-repository)
   #:autoload   (guix git-authenticate) (authenticate-repository)
   #:autoload   (guix openpgp) (openpgp-public-key-fingerprint
@@ -1148,14 +1149,8 @@ (define (resolve-channel-news-entry-tag repository entry)
 cannot be found."
   (if (channel-news-entry-commit entry)
       entry
-      (let* ((tag       (channel-news-entry-tag entry))
-             (reference (reference-lookup repository
-                                          (string-append "refs/tags/" tag)))
-             (target    (reference-target reference))
-             (oid       (let ((obj (object-lookup repository target)))
-                          (if (= OBJ-TAG (object-type obj)) ;annotated tag?
-                              (tag-target-id (tag-lookup repository target))
-                              target))))
+      (let* ((tag (channel-news-entry-tag entry))
+             (oid (object-id (tag->commit repository tag))))
         (channel-news-entry (oid->string oid) tag
                             (channel-news-entry-title entry)
                             (channel-news-entry-body entry)))))
diff --git a/guix/git.scm b/guix/git.scm
index eab84ea798..8e1d863976 100644
--- a/guix/git.scm
+++ b/guix/git.scm
@@ -68,6 +68,7 @@ (define-module (guix git)
             commit-descendant?
             commit-id?
             commit-short-id
+            tag->commit
 
             remote-refs
 
@@ -237,6 +238,19 @@ (define (commit-id? str)
 (define commit-short-id
   (compose (cut string-take <> 7) oid->string commit-id))
 
+(define (tag->commit repository tag)
+  "Resolve TAG in REPOSITORY and return the corresponding object, usually a
+commit."
+  (let* ((oid (reference-name->oid repository
+                                   (string-append "refs/tags/" tag)))
+         (obj (object-lookup repository oid)))
+    ;; OID may designate an "annotated tag" object or a "commit" object.
+    ;; Return the commit object in both cases.
+    (if (= OBJ-TAG (object-type obj))
+        (object-lookup repository
+                       (tag-target-id (tag-lookup repository oid)))
+        obj)))
+
 (define (resolve-reference repository ref)
   "Resolve the branch, commit or tag specified by REF, and return the
 corresponding Git object."
@@ -283,15 +297,7 @@ (define (resolve-reference repository ref)
                   ;; There's no such tag, so it must be a commit ID.
                   (resolve `(commit . ,str)))))))
       (('tag    . tag)
-       (let* ((oid (reference-name->oid repository
-                                        (string-append "refs/tags/" tag)))
-              (obj (object-lookup repository oid)))
-         ;; OID may designate an "annotated tag" object or a "commit" object.
-         ;; Return the commit object in both cases.
-         (if (= OBJ-TAG (object-type obj))
-             (object-lookup repository
-                            (tag-target-id (tag-lookup repository oid)))
-             obj))))))
+       (tag->commit repository tag)))))
 
 (define (switch-to-ref repository ref)
   "Switch to REPOSITORY's branch, commit or tag specified by REF.  Return the
-- 
2.41.0





  parent reply	other threads:[~2024-04-01 20:26 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-01 20:22 [bug#70132] [PATCH 00/11] Improve startup time and memory footprint for short-lived commands Ludovic Courtès
2024-04-01 20:25 ` [bug#70132] [PATCH 01/11] channels: Use SRFI-71 instead of SRFI-11 Ludovic Courtès
2024-04-15 22:41   ` Simon Tournier
2024-04-01 20:25 ` [bug#70132] [PATCH 02/11] git: Add ‘repository-info’ and use it in (guix channels) Ludovic Courtès
2024-04-01 20:25 ` [bug#70132] [PATCH 03/11] channels: Move ‘commit-short-id’ to (guix git) Ludovic Courtès
2024-04-01 20:25 ` Ludovic Courtès [this message]
2024-04-01 20:25 ` [bug#70132] [PATCH 05/11] channels: Autoload (git …) modules Ludovic Courtès
2024-04-15 22:45   ` Simon Tournier
2024-04-01 20:25 ` [bug#70132] [PATCH 06/11] guix system: Autoload some more Ludovic Courtès
2024-04-01 20:25 ` [bug#70132] [PATCH 07/11] utils: Don’t re-export ‘call-with-temporary-output-file’ Ludovic Courtès
2024-04-01 20:25 ` [bug#70132] [PATCH 08/11] guix: Delay loading of (gnutls) Ludovic Courtès
2024-04-01 20:25 ` [bug#70132] [PATCH 09/11] ui: Delay use of (guix build syscalls) Ludovic Courtès
2024-04-01 20:25 ` [bug#70132] [PATCH 10/11] Autoload " Ludovic Courtès
2024-04-01 20:25 ` [bug#70132] [PATCH 11/11] Autoload (gcrypt hash) Ludovic Courtès
2024-04-15 21:43 ` bug#70132: [PATCH 00/11] Improve startup time and memory footprint for short-lived commands Ludovic Courtès
     [not found] ` <handler.70132.D70132.17132174197570.notifdone@debbugs.gnu.org>
2024-04-15 22:57   ` [bug#70132] Not receiving Emails from Debbugs (was Re: bug#70132: closed ...) Simon Tournier
2024-04-16 16:42     ` Ludovic Courtès

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

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

  git send-email \
    --in-reply-to=db8007e3c85705035d9f4f54753e36088f863b6b.1712002698.git.ludo@gnu.org \
    --to=ludo@gnu.org \
    --cc=70132@debbugs.gnu.org \
    --cc=dev@jpoiret.xyz \
    --cc=guix@cbaines.net \
    --cc=me@tobias.gr \
    --cc=othacehe@gnu.org \
    --cc=rekado@elephly.net \
    --cc=zimon.toutoune@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 external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.