From b836c9fd5161eec573ed64cbe30bfe641af7d1af Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Mon, 10 Aug 2026 08:35:36 +0900 Subject: etc/committer: Sort changes in order of closure size. This is to make it more convenient to review updates with many dependents, e.g. by stopping on every commit to review things. It avoids having to rebuild the same things when reviewing later commits. * etc/committer.scm.in (new+old+hunks->package): New procedure. (sort-new+old+hunks-by-closure): Likewise. (main): Use it. Suggested-by: Liliana Marie Prikler --- etc/committer.scm.in | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/etc/committer.scm.in b/etc/committer.scm.in index bde26afa991..aec4d82a510 100755 --- a/etc/committer.scm.in +++ b/etc/committer.scm.in @@ -6,7 +6,7 @@ ;;; Copyright © 2020, 2021, 2022, 2023 Ricardo Wurmus ;;; Copyright © 2021 Sarah Morgensen ;;; Copyright © 2021 Xinglu Chen -;;; Copyright © 2022 Maxim Cournoyer +;;; Copyright © 2022, 2026 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -41,7 +41,9 @@ (ice-9 rdelim) (ice-9 regex) (ice-9 textual-ports) - (guix gexp)) + (guix gexp) + (guix modules) + (guix packages)) (define* (break-string str #:optional (max-line-length 70)) "Break the string STR into lines that are no longer than MAX-LINE-LENGTH. @@ -396,6 +398,26 @@ modifying." (cons* new (old-sexp (first hunks)) hunks))) (group-hunks-by-sexp hunks))) +(define (new+old+hunks->package new+old+hunks) + "Return the package object whose source is referenced in a new+old+hunks +tuple, which describes modifications to the package in a tuple containing the +new sexp, the old sexp as well as a tail of objects." + (match new+old+hunks + ((new-sexp old-sexp . hunks) + (let* ((hunk-file-name (hunk-file-name (first hunks))) + (variable-name (second new-sexp)) + (module-name (file-name->module-name hunk-file-name))) + (module-ref (resolve-module module-name) variable-name))))) + +(define (sort-new+old+hunks-by-closure new+old+hunks) + "Sort new+old+hunks by their package closure size." + (sort new+old+hunks + (match-lambda* + (((= new+old+hunks->package x-package) + (= new+old+hunks->package y-package)) + (< (length (package-closure (list x-package))) + (length (package-closure (list y-package)))))))) + (define %delay 1000) (define (main . args) @@ -457,7 +479,7 @@ modifying." hunks) (define copyright-line (any (lambda (line) (and=> (string-prefix? "+;;; Copyright ©" line) - (const line))) + (const line))) (hunk-diff-lines (first hunks)))) (cond (copyright-line @@ -472,13 +494,14 @@ modifying." (usleep %delay) (unless (eqv? 0 (status:exit-val (close-pipe port))) (error "Cannot commit"))))))) - (new+old+hunks (match definitions - ('() changes) ;reuse - (_ - ;; XXX: we recompute the hunks here because previous - ;; insertions lead to offsets. - (let-values (((definitions changes) - (partition hunk-type (diff-info)))) - changes))))))))) + (sort-new+old+hunks-by-closure + (new+old+hunks (match definitions + ('() changes) ;reuse + (_ + ;; XXX: we recompute the hunks here because previous + ;; insertions lead to offsets. + (let-values (((definitions changes) + (partition hunk-type (diff-info)))) + changes)))))))))) (apply main (cdr (command-line))) -- cgit v1.2.3