unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: 54393@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>
Subject: [bug#54393] [PATCH 1/2] packages: Add 'package-unique-version-prefix'.
Date: Mon, 14 Mar 2022 22:51:45 +0100	[thread overview]
Message-ID: <20220314215146.24490-1-ludo@gnu.org> (raw)
In-Reply-To: <20220314215015.24435-1-ludo@gnu.org>

* gnu/packages.scm (package-unique-version-prefix): New procedure.
* guix/scripts/package.scm (manifest-entry-version-prefix): Use it.
* tests/packages.scm ("package-unique-version-prefix, gcc@8")
("package-unique-version-prefix, grep"): New tests.
---
 gnu/packages.scm         | 21 +++++++++++++++++++++
 guix/scripts/package.scm | 20 ++------------------
 tests/packages.scm       | 13 +++++++++++++
 3 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/gnu/packages.scm b/gnu/packages.scm
index 65ab7a7c1e..2ba838fd0a 100644
--- a/gnu/packages.scm
+++ b/gnu/packages.scm
@@ -66,6 +66,8 @@ (define-module (gnu packages)
             specification->location
             specifications->manifest
 
+            package-unique-version-prefix
+
             generate-package-cache))
 
 ;;; Commentary:
@@ -559,3 +561,22 @@ (define (specifications->manifest specs)
   ;; fiddle with multiple-value returns.
   (packages->manifest
    (map (compose list specification->package+output) specs)))
+
+(define (package-unique-version-prefix name version)
+  "Search among all the versions of package NAME that are available, and
+return the shortest unambiguous version prefix to designate VERSION.  If only
+one version of the package is available, return the empty string."
+  (match (map package-version (find-packages-by-name name))
+    ((_)
+     ;; A single version of NAME is available, so do not specify the version
+     ;; number, even if the available version doesn't match VERSION.
+     "")
+    (versions
+     ;; If VERSION is the latest version, don't specify any version.
+     ;; Otherwise return the shortest unique version prefix.  Note that this
+     ;; is based on the currently available packages so the result may vary
+     ;; over time.
+     (if (every (cut version>? version <>)
+                (delete version versions))
+         ""
+         (version-unique-prefix version versions)))))
diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index 9699c70c6d..22ee8a2485 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -334,24 +334,8 @@ (define (manifest-entry-version-prefix entry)
   "Search among all the versions of ENTRY's package that are available, and
 return the shortest unambiguous version prefix for this package.  If only one
 version of ENTRY's package is available, return the empty string."
-  (let ((name (manifest-entry-name entry)))
-    (match (map package-version (find-packages-by-name name))
-      ((_)
-       ;; A single version of NAME is available, so do not specify the
-       ;; version number, even if the available version doesn't match ENTRY.
-       "")
-      (versions
-       ;; If ENTRY uses the latest version, don't specify any version.
-       ;; Otherwise return the shortest unique version prefix.  Note that
-       ;; this is based on the currently available packages, which could
-       ;; differ from the packages available in the revision that was used
-       ;; to build MANIFEST.
-       (let ((current (manifest-entry-version entry)))
-         (if (every (cut version>? current <>)
-                    (delete current versions))
-             ""
-             (version-unique-prefix (manifest-entry-version entry)
-                                    versions)))))))
+  (package-unique-version-prefix (manifest-entry-name entry)
+                                 (manifest-entry-version entry)))
 
 (define* (export-manifest manifest
                           #:optional (port (current-output-port)))
diff --git a/tests/packages.scm b/tests/packages.scm
index 02bdba5f98..b228c9fc3b 100644
--- a/tests/packages.scm
+++ b/tests/packages.scm
@@ -1923,6 +1923,19 @@ (define (list->set* lst)
   (package-location (specification->package "guile@2"))
   (specification->location "guile@2"))
 
+(test-equal "package-unique-version-prefix, gcc@8"
+  "8"
+  (let ((gcc (specification->package "gcc-toolchain@8")))
+    (package-unique-version-prefix (package-name gcc)
+                                   (package-version gcc))))
+
+(test-equal "package-unique-version-prefix, grep"
+  ""
+  (let ((grep (specification->package "grep")))
+    (package-unique-version-prefix (package-name grep)
+                                   (package-version grep))))
+
+
 (test-eq "this-package-input, exists"
   hello
   (package-arguments
-- 
2.34.0





  reply	other threads:[~2022-03-14 21:53 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-14 21:50 [bug#54393] [PATCH 0/2] Add 'guix manifest' to "translate" commands to manifests Ludovic Courtès
2022-03-14 21:51 ` Ludovic Courtès [this message]
2022-03-14 21:51   ` [bug#54393] [PATCH 2/2] Add 'guix manifest' Ludovic Courtès
2022-03-15  7:18 ` [bug#54393] [PATCH 0/2] Add 'guix manifest' to "translate" commands to manifests Liliana Marie Prikler
2022-03-15  9:27   ` Ludovic Courtès
2022-03-15  9:53     ` Liliana Marie Prikler
2022-03-15 15:17       ` Ludovic Courtès
2022-03-15  9:00 ` zimoun
2022-03-15  9:23   ` Ludovic Courtès
2022-03-15 10:21     ` zimoun
2022-03-15 19:38       ` Ludovic Courtès
2022-03-31 11:09         ` [bug#54393] [PATCH v2 1/3] packages: Add 'package-unique-version-prefix' Ludovic Courtès
2022-03-31 11:09           ` [bug#54393] [PATCH v2 2/3] environment: Export 'load-manifest' Ludovic Courtès
2022-03-31 11:09           ` [bug#54393] [PATCH v2 3/3] shell: Add '--export-manifest' Ludovic Courtès
2022-04-04 14:37             ` [bug#54393] [PATCH 0/2] Add 'guix manifest' to "translate" commands to manifests Maxim Cournoyer
2022-04-04 21:16               ` bug#54393: " Ludovic Courtès
2022-04-05  5:48                 ` [bug#54393] " zimoun
2022-04-06  8:08                   ` Ludovic Courtès
2022-03-31 11:10         ` [bug#54393] [PATCH v2 0/3] Add '--export-manifest' to 'guix shell' Ludovic Courtès
2022-03-15 16:50 ` [bug#54393] [PATCH 0/2] Add 'guix manifest' to "translate" commands to manifests Greg Hogan
2022-03-16  9:58   ` 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

  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=20220314215146.24490-1-ludo@gnu.org \
    --to=ludo@gnu.org \
    --cc=54393@debbugs.gnu.org \
    /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).