From mboxrd@z Thu Jan 1 00:00:00 1970 From: Benz Schenk Subject: Re: Display diffs between generations. Date: Fri, 21 Oct 2016 16:40:53 +0200 Message-ID: <20161021164053.2961bd6d@gondolin.arda> References: <87eg59izmw.fsf@gnu.org> <87d1kry22u.fsf@gnu.org> <87inuj5r5v.fsf@gnu.org> <87y43ck6dz.fsf@gnu.org> <87a8frq0n5.fsf@gnu.org> <87lgz78v4d.fsf@gnu.org> <87eg3ogd5l.fsf@gnu.org> <87r37nxshp.fsf@gnu.org> <8760opeskj.fsf@gnu.org> <87wph43x8x.fsf@gnu.org> <87vawo57sn.fsf@gnu.org> <87funrci3f.fsf@gnu.org> <87k2d3p4bf.fsf@gnu.org> <87wph2zu8z.fsf@gnu.org> <87oa2eqc03.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/TKNoE7/zdKme+5alVJI_D+c" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxb0P-0003DA-2T for guix-devel@gnu.org; Fri, 21 Oct 2016 10:41:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bxb0N-0007eN-Ni for guix-devel@gnu.org; Fri, 21 Oct 2016 10:41:09 -0400 Received: from idmx05.uzh.ch ([130.60.205.108]:54391) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bxb0N-0007bO-Do for guix-devel@gnu.org; Fri, 21 Oct 2016 10:41:07 -0400 Received: from idsmtp02.uzh.ch ([130.60.206.121]:38298) by idmx05.uzh.ch with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1bxb0I-00062R-3Y for guix-devel@gnu.org; Fri, 21 Oct 2016 16:41:02 +0200 In-Reply-To: <87oa2eqc03.fsf@gnu.org> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Roel Janssen Cc: guix-devel --MP_/TKNoE7/zdKme+5alVJI_D+c Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Fri, 21 Oct 2016 11:37:00 +0200 Roel Janssen wrote: > Ludovic Court=C3=A8s writes: >=20 > > Roel Janssen skribis: > > =20 > >> Ludovic Court=C3=A8s writes: =20 > > > > [...] > > =20 > [...] =20 > >> > >> Ah, sorry, I forgot about this. This makes sense. But then, what sho= uld we > >> see when we do: > >> > >> guix package --list-generations=3D42,46 > >> > >> Should we see: > >> Generation 42 ...: > >> > >> > >> Generation 46 ...: > >> =20 > > > > This one, IMO. =20 >=20 > The attached patch implements this behavior. However, because I use > @code{previous-generation-number} to determine which generation to diff > with, the following will not provide a diff as expected: >=20 > guix package --list-generations=3D42,41,40 >=20 > Any ideas on how to fix this? Otherwise I'll give it another go over > the weekend. >=20 > Kind regards, > Roel Janssen I adapted your patch to hopefully implement the desired behaviour, but it might need some cleaning up as I'm just getting started learning scheme. HANWE Benz --MP_/TKNoE7/zdKme+5alVJI_D+c Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0001-guix-package-Display-generation-diffs.patch >From f920c91e0572539790952d9c28aec547d7bc0000 Mon Sep 17 00:00:00 2001 From: Benz Schenk Date: Fri, 21 Oct 2016 16:20:30 +0200 Subject: [PATCH] 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. --- guix/scripts/package.scm | 16 ++++++++++++---- guix/ui.scm | 30 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index b87aee0..8d148d7 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -667,24 +667,32 @@ processed, #f otherwise." ((head tail ...) head)))) (match (assoc-ref opts 'query) (('list-generations pattern) - (define (list-generation number) + (define (list-generation display-function number) (unless (zero? number) (display-generation profile number) - (display-profile-content profile number) + (display-function profile number) (newline))) + (define (diff-profiles profile numbers) + (unless (null-list? (cdr numbers)) + (display-profile-content-diff profile (car numbers) (cadr numbers))) + (unless (null-list? (cdr numbers)) + (diff-profiles profile (cdr numbers)))) (cond ((not (file-exists? profile)) ; XXX: race condition (raise (condition (&profile-not-found-error (profile profile))))) ((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) => (lambda (numbers) (if (null-list? numbers) (exit 1) (leave-on-EPIPE - (for-each list-generation numbers))))) + (list-generation display-profile-content (car numbers)) + (diff-profiles profile numbers))))) (else (leave (_ "invalid syntax: ~a~%") pattern))) diff --git a/guix/ui.scm b/guix/ui.scm index eb85df3..c93b44f 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -87,6 +87,7 @@ matching-generations display-generation display-profile-content + display-profile-content-diff roll-back* switch-to-generation* delete-generation* @@ -1070,6 +1071,35 @@ DURATION-RELATION with the current time." (format #t (_ "~a\t(current)~%") header) (format #t "~a~%" header))))) +(define (display-profile-content-diff profile number1 number2) + "Display the changed packages in PROFILE compared to generation NUMBER." + + (define (equal-entry? first second) + (string= (manifest-entry-item first) (manifest-entry-item second))) + + (define (display-entry entry prefix) + (match 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) + (format #t (_ "Generation ~a\t~a ~%") new + (date->string + (time-utc->date + (generation-time profile new)) + "~b ~d ~Y ~T")) + (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 number1 number2)) + (define (display-profile-content profile number) "Display the packages in PROFILE, generation NUMBER, in a human-readable way." -- 2.10.1 --MP_/TKNoE7/zdKme+5alVJI_D+c--