Subject: [bug#77093] [PATCH rust-team v3 12/17] scripts: import: Skip existing definition for ‘--insert’ option.

From: Hilton Chain <[email-masked]>
Date: Sun, 23 Mar 2025 15:28:34 +0800

* guix/scripts/import.scm (guix-import): Skip existing definition for
‘--insert’ option.

Change-Id: I2c4242669f974b263a018ab0cf56538bd7c81d06
---
 guix/scripts/import.scm | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/guix/scripts/import.scm b/guix/scripts/import.scm
index 38349bff3a..1bddac15c6 100644
--- a/guix/scripts/import.scm
+++ b/guix/scripts/import.scm
@@ -136,16 +136,19 @@ (define-command (guix-import . args)
              (lambda (expr)
                (match expr
                  (((? define-prefix? define-prefix) term _ ...)
-                  (let ((source-properties
-                         (find-definition-insertion-location
-                          file term #:define-prefix define-prefix)))
-                    (if source-properties
-                      (insert-expression source-properties expr)
-                      (let ((port (open-file file "a")))
-                        (pretty-print-with-comments port expr)
-                        (newline port)
-                        (newline port)
-                        (close-port port)))))))))
+                  ;; Skip existing definition.
+                  (unless (find-definition-location
+                           file term #:define-prefix define-prefix)
+                    (let ((source-properties
+                           (find-definition-insertion-location
+                            file term #:define-prefix define-prefix)))
+                      (if source-properties
+                          (insert-expression source-properties expr)
+                          (let ((port (open-file file "a")))
+                            (pretty-print-with-comments port expr)
+                            (newline port)
+                            (newline port)
+                            (close-port port))))))))))
        (import-as-definitions importer
                               (cons (string-append "--file-to-insert=" file)
                                     args)
-- 
2.49.0