aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2013-05-29 23:09:42 +0200
committerGravatar Tom Willemse2013-05-29 23:10:26 +0200
commit62627e6cf63d25f1f78a030e67ca5b861798e1a8 (patch)
tree30661e0104077a4ebc2742930726902ed836830f
parent1027b3c7d654dd9f0dc988b66f14bffbdff97003 (diff)
downloadgitto-62627e6cf63d25f1f78a030e67ca5b861798e1a8.tar.gz
gitto-62627e6cf63d25f1f78a030e67ca5b861798e1a8.zip
Properly handle multiple values for settings
Fixes an error that would cause values to be duplicated when specifying multiple values for a setting. Prior to this commit specifying multiple values for a setting would blindly replace one occurrence and add the rest, leaving any possible other occurrences intact. When starting fresh this would not be a problem, but using it multiple times would add the same settings repeatedly. - gitto/config.scm (merge-setting): If the given value is a of type `list', replace the `%a' specifier for each item in it. - gitto/config.scm (merge-settings): Move the handling of the case of `v' being a list into `merge-setting'. - gitto/config.scm (split-setting): Rename `parse-setting' to `split-setting'. Return a cons cell instead of a list. - gitto/config.scm (read-setting): New function. - gitto/config.scm (read-config): Remove unused variable. Use `read-setting' to get the right value for each line of the config file. - gitto/config.scm (write-setting): In case we're dealing with a list, print each value separately.
-rw-r--r--gitto/config.scm41
1 files changed, 24 insertions, 17 deletions
diff --git a/gitto/config.scm b/gitto/config.scm
index ae0bf7b..5459d84 100644
--- a/gitto/config.scm
+++ b/gitto/config.scm
@@ -52,34 +52,38 @@
lst))
(define (merge-setting repo-name lst var val)
- (assoc-set! lst var (format #f val repo-name)))
+ (if (list? val)
+ (assoc-set! lst var (map (lambda (v) (format #f v repo-name)) val))
+ (assoc-set! lst var (format #f val repo-name))))
(define (merge-settings repo-name x y)
(let ((lst (if x (list-copy x) '())))
(for-each
(lambda (v)
- (if (list? v)
- (begin
- (set! lst (merge-setting repo-name lst (car v) (cadr v)))
- (set! lst (append lst (map (lambda (s)
- (cons (car v)
- (format #f s repo-name)))
- (cddr v)))))
- (set! lst (merge-setting repo-name lst (car v) (cdr v)))))
+ (set! lst (merge-setting repo-name lst (car v) (cdr v))))
y)
lst))
-(define (parse-setting line)
+(define (split-setting line)
(let ((idx (string-index line #\=)))
- (list (cons (string-trim-both (substring line 0 idx))
- (string-trim-both (substring line (1+ idx)))))))
+ (cons (string-trim-both (substring line 0 idx))
+ (string-trim-both (substring line (1+ idx))))))
+
+(define (read-setting settings line)
+ (let* ((new-setting (split-setting line))
+ (var (car new-setting)) (val (cdr new-setting))
+ (current-value (assoc-ref settings var)))
+ (if current-value
+ (if (list? current-value)
+ (assoc-set! settings var (append current-value (list val)))
+ (assoc-set! settings var (list current-value val)))
+ (assoc-set! settings var val))))
(define (read-config repo-location)
(let ((port (open-input-file
(string-append repo-location "/.git/config")))
(config '())
- (current-section #f)
- (assign-pos #f))
+ (current-section #f))
(do ((line (read-line port) (read-line port)))
((eof-object? line))
(cond ((string= line "[" 0 1)
@@ -89,8 +93,7 @@
(set! current-section section)))
((string-contains line "=")
(set-cdr! current-section
- (append (cdr current-section)
- (parse-setting line))))))
+ (read-setting (cdr current-section) line)))))
(close-port port)
config))
@@ -105,4 +108,8 @@
(for-each write-setting (cdr section)))
(define (write-setting setting)
- (format #t "~8t~a = ~a~%" (car setting) (cdr setting)))
+ (let ((value (cdr setting)))
+ (if (list? value)
+ (map (lambda (v)
+ (format #t "~8t~a = ~a~%" (car setting) v)) value)
+ (format #t "~8t~a = ~a~%" (car setting) (cdr setting)))))