guix package: Display generation diffs.

* guix/ui.scm (display-profile-content-diff): New variable.
* guix/scripts/package.scm (process-query): Use display-profile-content-diff.

In collaboration with Benz Schenk.
This commit is contained in:
Roel Janssen 2016-10-26 14:53:29 +02:00
parent b2a2232c33
commit e95ae7c223
No known key found for this signature in database
GPG key ID: C3EC1DCA843072E1
2 changed files with 41 additions and 5 deletions

View file

@ -3,6 +3,8 @@
;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org> ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
;;; Copyright © 2013, 2015 Mark H Weaver <mhw@netris.org> ;;; Copyright © 2013, 2015 Mark H Weaver <mhw@netris.org>
;;; Copyright © 2014, 2016 Alex Kost <alezost@gmail.com> ;;; Copyright © 2014, 2016 Alex Kost <alezost@gmail.com>
;;; Copyright © 2016 Roel Janssen <roel@gnu.org>
;;; Copyright © 2016 Benz Schenk <benz.schenk@uzh.ch>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -667,24 +669,30 @@ (define (process-query opts)
((head tail ...) head)))) ((head tail ...) head))))
(match (assoc-ref opts 'query) (match (assoc-ref opts 'query)
(('list-generations pattern) (('list-generations pattern)
(define (list-generation number) (define (list-generation display-function number)
(unless (zero? number) (unless (zero? number)
(display-generation profile number) (display-generation profile number)
(display-profile-content profile number) (display-function profile number)
(newline))) (newline)))
(define (diff-profiles profile numbers)
(unless (null-list? (cdr numbers))
(display-profile-content-diff profile (car numbers) (cadr numbers))
(diff-profiles profile (cdr numbers))))
(cond ((not (file-exists? profile)) ; XXX: race condition (cond ((not (file-exists? profile)) ; XXX: race condition
(raise (condition (&profile-not-found-error (raise (condition (&profile-not-found-error
(profile profile))))) (profile profile)))))
((string-null? pattern) ((string-null? pattern)
(for-each list-generation (profile-generations profile))) (list-generation display-profile-content
(car (profile-generations profile)))
(diff-profiles profile (profile-generations profile)))
((matching-generations pattern profile) ((matching-generations pattern profile)
=> =>
(lambda (numbers) (lambda (numbers)
(if (null-list? numbers) (if (null-list? numbers)
(exit 1) (exit 1)
(leave-on-EPIPE (leave-on-EPIPE
(for-each list-generation numbers))))) (list-generation display-profile-content (car numbers))
(diff-profiles profile numbers)))))
(else (else
(leave (_ "invalid syntax: ~a~%") (leave (_ "invalid syntax: ~a~%")
pattern))) pattern)))

View file

@ -7,6 +7,8 @@
;;; Copyright © 2014, 2015 Alex Kost <alezost@gmail.com> ;;; Copyright © 2014, 2015 Alex Kost <alezost@gmail.com>
;;; Copyright © 2015 David Thompson <davet@gnu.org> ;;; Copyright © 2015 David Thompson <davet@gnu.org>
;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org> ;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org>
;;; Copyright © 2016 Roel Janssen <roel@gnu.org>
;;; Copyright © 2016 Benz Schenk <benz.schenk@uzh.ch>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -87,6 +89,7 @@ (define-module (guix ui)
matching-generations matching-generations
display-generation display-generation
display-profile-content display-profile-content
display-profile-content-diff
roll-back* roll-back*
switch-to-generation* switch-to-generation*
delete-generation* delete-generation*
@ -1070,6 +1073,31 @@ (define (display-generation profile number)
(format #t (_ "~a\t(current)~%") header) (format #t (_ "~a\t(current)~%") header)
(format #t "~a~%" header))))) (format #t "~a~%" header)))))
(define (display-profile-content-diff profile gen1 gen2)
"Display the changed packages in PROFILE GEN2 compared to generation GEN2."
(define (equal-entry? first second)
(string= (manifest-entry-item first) (manifest-entry-item second)))
(define (display-entry entry prefix)
(match entry
(($ <manifest-entry> name version output location _)
(format #t " ~a ~a\t~a\t~a\t~a~%" prefix name version output location))))
(define (list-entries number)
(manifest-entries (profile-manifest (generation-file-name profile number))))
(define (display-diff profile old new)
(display-generation profile new)
(let ((added (lset-difference
equal-entry? (list-entries new) (list-entries old)))
(removed (lset-difference
equal-entry? (list-entries old) (list-entries new))))
(for-each (cut display-entry <> "+") added)
(for-each (cut display-entry <> "-") removed)))
(display-diff profile gen1 gen2))
(define (display-profile-content profile number) (define (display-profile-content profile number)
"Display the packages in PROFILE, generation NUMBER, in a human-readable "Display the packages in PROFILE, generation NUMBER, in a human-readable
way." way."