From: Roel Janssen <roel@gnu.org>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: guix-devel <guix-devel@gnu.org>
Subject: Re: Display diffs between generations.
Date: Fri, 21 Oct 2016 11:37:00 +0200 [thread overview]
Message-ID: <87oa2eqc03.fsf@gnu.org> (raw)
In-Reply-To: <87wph2zu8z.fsf@gnu.org>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: 0001-guix-package-Display-generation-diffs.patch --]
[-- Type: text/x-patch, Size: 4123 bytes --]
From 7864ff2443f99fb227e90d0d176a977a30c88faa Mon Sep 17 00:00:00 2001
From: Roel Janssen <roel@gnu.org>
Date: Fri, 21 Oct 2016 11:31:52 +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 | 14 ++++++++++----
guix/ui.scm | 28 ++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index b87aee0..8b57f8d 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -667,24 +667,30 @@ 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)))
(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)))
+ (for-each (cut list-generation
+ display-profile-content-diff <>)
+ (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))
+ (unless (null-list? (cdr numbers))
+ (for-each (cut list-generation
+ display-profile-content-diff <>)
+ (cdr numbers)))))))
(else
(leave (_ "invalid syntax: ~a~%")
pattern)))
diff --git a/guix/ui.scm b/guix/ui.scm
index eb85df3..4af8d52 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,33 @@ DURATION-RELATION with the current time."
(format #t (_ "~a\t(current)~%") header)
(format #t "~a~%" header)))))
+(define (display-profile-content-diff profile number)
+ "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
+ (($ <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)
+ (if (or (= old 0)
+ #f) ; Or first profile specified as an argument.
+ (display-profile-content 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 (previous-generation-number profile number) number))
+
(define (display-profile-content profile number)
"Display the packages in PROFILE, generation NUMBER, in a human-readable
way."
--
2.10.0
[-- Attachment #2: Type: text/plain, Size: 1116 bytes --]
Ludovic Courtès writes:
> Roel Janssen <roel@gnu.org> skribis:
>
>> Ludovic Courtès writes:
>
> [...]
>
>>> I think what I’m suggesting is that the first matching generation should
>>> be displayed in full using ‘display-profile-content’, and subsequent
>>> generations would be displayed as a diff.
>>>
>>> Thus, when viewing a single generation, as with --list-generations=42,
>>> we’d only display the full contents of that generation.
>>>
>>> Does that make sense?
>>
>> Ah, sorry, I forgot about this. This makes sense. But then, what should we
>> see when we do:
>>
>> guix package --list-generations=42,46
>>
>> Should we see:
>> Generation 42 ...:
>> <full contents>
>>
>> Generation 46 ...:
>> <diff with 42>
>
> This one, IMO.
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:
guix package --list-generations=42,41,40
Any ideas on how to fix this? Otherwise I'll give it another go over
the weekend.
Kind regards,
Roel Janssen
next prev parent reply other threads:[~2016-10-21 9:35 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-27 23:02 Display diffs between generations Roel Janssen
2016-08-29 16:25 ` Ludovic Courtès
2016-08-29 19:08 ` Roel Janssen
2016-08-31 20:52 ` Ludovic Courtès
2016-08-31 21:11 ` Vincent Legoll
2016-09-01 12:12 ` Ludovic Courtès
2016-09-03 13:03 ` Vincent Legoll
2016-09-04 16:53 ` Roel Janssen
2016-10-10 20:30 ` Ludovic Courtès
2016-10-11 7:19 ` Roel Janssen
2016-10-18 12:43 ` Roel Janssen
2016-10-19 20:22 ` Ludovic Courtès
2016-10-19 21:48 ` Roel Janssen
2016-10-20 12:36 ` Ludovic Courtès
2016-10-20 12:56 ` Roel Janssen
2016-10-20 19:38 ` Ludovic Courtès
2016-10-21 9:37 ` Roel Janssen [this message]
2016-10-21 14:40 ` Benz Schenk
2016-10-24 20:33 ` Ludovic Courtès
2016-10-25 16:01 ` Roel Janssen
2016-10-26 11:13 ` Benz Schenk
2016-10-26 11:38 ` Ludovic Courtès
2016-10-26 12:58 ` Roel Janssen
2016-09-04 22:12 ` Ludovic Courtès
2016-09-05 7:52 ` Hartmut Goebel
2016-09-05 10:38 ` Vincent Legoll
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=87oa2eqc03.fsf@gnu.org \
--to=roel@gnu.org \
--cc=guix-devel@gnu.org \
--cc=ludo@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).