[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
09/11: utils: 'edit-expression' modifies the file only if necessary.
From: |
guix-commits |
Subject: |
09/11: utils: 'edit-expression' modifies the file only if necessary. |
Date: |
Tue, 22 Jun 2021 06:15:59 -0400 (EDT) |
civodul pushed a commit to branch wip-simplified-packages
in repository guix.
commit a6be21e1d1436eee8159e50e9fe54b936538e1ab
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Mon Jun 21 13:56:59 2021 +0200
utils: 'edit-expression' modifies the file only if necessary.
* guix/utils.scm (edit-expression): Check whether STR* equals STR.
---
guix/utils.scm | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/guix/utils.scm b/guix/utils.scm
index f8f6672..e6d0761 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -423,17 +423,19 @@ This procedure returns #t on success."
(port-encoding in)))
(post-bv (get-bytevector-all in))
(str* (proc str)))
- ;; Verify the edited expression is still a scheme expression.
- (call-with-input-string str* read)
- ;; Update the file with edited expression.
- (with-atomic-file-output file
- (lambda (out)
- (put-bytevector out pre-bv)
- (display str* out)
- ;; post-bv maybe the end-of-file object.
- (when (not (eof-object? post-bv))
- (put-bytevector out post-bv))
- #t))))))))
+ ;; Modify FILE only if there are changes.
+ (unless (string=? str* str)
+ ;; Verify the edited expression is still a scheme expression.
+ (call-with-input-string str* read)
+ ;; Update the file with edited expression.
+ (with-atomic-file-output file
+ (lambda (out)
+ (put-bytevector out pre-bv)
+ (display str* out)
+ ;; post-bv maybe the end-of-file object.
+ (when (not (eof-object? post-bv))
+ (put-bytevector out post-bv))
+ #t)))))))))
;;;
- branch wip-simplified-packages created (now b3063a8), guix-commits, 2021/06/22
- 01/11: records: Support field sanitizers., guix-commits, 2021/06/22
- 07/11: utils: 'edit-expression' no longer leaks file ports., guix-commits, 2021/06/22
- 11/11: Add 'guix style'., guix-commits, 2021/06/22
- 05/11: packages: Add 'modify-inputs'., guix-commits, 2021/06/22
- 10/11: utils: 'edit-expression' copies part of the original source map., guix-commits, 2021/06/22
- 09/11: utils: 'edit-expression' modifies the file only if necessary.,
guix-commits <=
- 06/11: gnu: Change inputs of core packages to plain lists., guix-commits, 2021/06/22
- 02/11: packages: Allow inputs to be plain package lists., guix-commits, 2021/06/22
- 03/11: lint: Add 'input-labels' checker., guix-commits, 2021/06/22
- 04/11: packages: Add 'lookup-package-input' & co., guix-commits, 2021/06/22
- 08/11: utils: Add 'go-to-location' with source location caching., guix-commits, 2021/06/22