diff mbox series

[bug#53818,v3,1/7] upstream: Sort list of updaters.

Message ID 0f119f2aaf1f3d492bdf733136c310a9f1a6d85d.1644412701.git.public@yoctocell.xyz
State New
Headers show
Series Add Repology updater | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Xinglu Chen Feb. 9, 2022, 1:24 p.m. UTC
The order determines which updater gets used first when running ‘guix refresh’
on a package.  We want the most generic updaters to be last since they usually
don’t provide as much or accurate information as language-specific updaters.

* guix/upstream.scm (sort-updaters): New procedure.
(%updaters): Use it.
---
 guix/upstream.scm | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/guix/upstream.scm b/guix/upstream.scm
index 6666803a92..d5faf9d3ee 100644
--- a/guix/upstream.scm
+++ b/guix/upstream.scm
@@ -250,14 +250,31 @@  (define (importer-modules)
                           %load-path)
                      #:warn warn-about-load-error)))
 
+(define (sort-updaters updaters)
+  "Sort UPDATERS by putting the more generic ones last."
+  (define (genericity updater)
+    (cond
+     ((equal? 'repology (upstream-updater-name updater))
+      2)
+     ((string-prefix? "generic-"
+                      (symbol->string (upstream-updater-name updater)))
+      1)     
+     (else 0)))
+
+  (define (less a b)
+    (<= (genericity a) (genericity b)))
+
+  (stable-sort updaters less))
+
 (define %updaters
   ;; The list of publically-known updaters.
-  (delay (fold-module-public-variables (lambda (obj result)
-                                         (if (upstream-updater? obj)
-                                             (cons obj result)
-                                             result))
-                                       '()
-                                       (importer-modules))))
+  (delay (sort-updaters
+          (fold-module-public-variables (lambda (obj result)
+                                          (if (upstream-updater? obj)
+                                              (cons obj result)
+                                              result))
+                                        '()
+                                        (importer-modules)))))
 
 ;; Tests need to mock this variable so mark it as "non-declarative".
 (set! %updaters %updaters)