aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2013-05-12 20:38:58 +0200
committerGravatar Tom Willemse2013-05-12 20:50:10 +0200
commit44274838c5b86daf48dcb86a0552084ab6c81508 (patch)
treeb80ae9eb54e4f5b87edde917c11de0cfe772127c
parent964756b7308dbe0aecc30fe668ae6a2a24f449be (diff)
downloadgitto-44274838c5b86daf48dcb86a0552084ab6c81508.tar.gz
gitto-44274838c5b86daf48dcb86a0552084ab6c81508.zip
Add read-config
This function parses the config file in the .git/ sub-directory of a repository.
-rw-r--r--gitto/Makefile3
-rw-r--r--gitto/config.scm47
2 files changed, 49 insertions, 1 deletions
diff --git a/gitto/Makefile b/gitto/Makefile
index e9422aa..6d8f92d 100644
--- a/gitto/Makefile
+++ b/gitto/Makefile
@@ -3,7 +3,8 @@ SITEDIR = $(shell pkg-config guile-2.0 --variable=sitedir \
--define-variable=prefix=$(DESTDIR))
COMPDIR = $(DESTDIR)/lib/guile/2.0/site-ccache
-objects = git.scm git.go main.scm main.go path.scm path.go
+objects = config.scm config.go git.scm git.go main.scm main.go path.scm \
+ path.go
install-objects = $(addprefix install-,$(objects))
uninstall-objects = $(addprefix uninstall-,$(objects))
diff --git a/gitto/config.scm b/gitto/config.scm
new file mode 100644
index 0000000..1ba199e
--- /dev/null
+++ b/gitto/config.scm
@@ -0,0 +1,47 @@
+;; -*- coding: utf-8; -*-
+;; gitto -- Keep track of your git repositories
+;; Copyright (C) 2012 Tom Willemsen <tom at ryuslash dot org>
+
+;; This file is part of gitto.
+
+;; gitto is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; gitto is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with gitto. If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gitto config)
+ #:use-module (ice-9 rdelim)
+ #:export (read-config))
+
+(define (parse-setting line)
+ (let ((idx (string-index line #\=)))
+ (list (cons (string-trim-both (substring line 0 idx))
+ (string-trim-both (substring line (1+ idx)))))))
+
+(define (read-config repo-location)
+ (let ((port (open-input-file
+ (string-append repo-location "/.git/config")))
+ (config '())
+ (current-section #f)
+ (assign-pos #f))
+ (do ((line (read-line port) (read-line port)))
+ ((eof-object? line))
+ (cond ((string= line "[" 0 1)
+ (let ((section (cons (string-trim-both
+ line (char-set #\[ #\])) '())))
+ (set! config (append config (list section)))
+ (set! current-section section)))
+ ((string-contains line "=")
+ (set-cdr! current-section
+ (append (cdr current-section)
+ (parse-setting line))))))
+ (close-port port)
+ config))