From 62367d7f412e115fb2fc45a0de532ca0515fe3bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Sun, 16 Apr 2023 19:16:33 +0200 Subject: [PATCH] Add simple git wrapper. --- src/Makefile | 7 ++++- src/util-git.scm | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 src/util-git.scm diff --git a/src/Makefile b/src/Makefile index 1e761e0..af82812 100644 --- a/src/Makefile +++ b/src/Makefile @@ -49,7 +49,7 @@ HACKERBASE-OBJS=hackerbase.o testing.o listing.o month.o period.o \ util-set-list.o util-time.o util-tag.o util-io.o \ util-string.o util-io.o util-list.o util-parser.o texts.o \ tests.o util-proc.o util-mail.o reminders.o util-format.o \ - brmember-format.o logging.o specification.o + brmember-format.o logging.o specification.o util-git.o .PHONY: imports imports: $(HACKERBASE-DEPS) @@ -355,3 +355,8 @@ SPECIFICATION-SOURCES=specification.scm period.import.scm specification.o: specification.import.scm specification.import.scm: $(SPECIFICATION-SOURCES) + +UTIL-GIT-SOURCES=util-git.scm util-io.import.scm + +util-git.o: util-git.import.scm +util-git.import.scm: $(UTIL-GIT-SOURCES) diff --git a/src/util-git.scm b/src/util-git.scm new file mode 100644 index 0000000..aa43822 --- /dev/null +++ b/src/util-git.scm @@ -0,0 +1,74 @@ +;; +;; util-git.scm +;; +;; Support for simple git integration. +;; +;; ISC License +;; +;; Copyright 2023 Brmlab, z.s. +;; Dominik Pantůček +;; +;; Permission to use, copy, modify, and/or distribute this software +;; for any purpose with or without fee is hereby granted, provided +;; that the above copyright notice and this permission notice appear +;; in all copies. +;; +;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +;; WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +;; WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE +;; AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR +;; CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +;; OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +;; NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +;; CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +;; + +(declare (unit util-git)) + +(module + util-git + ( + git + ) + + (import scheme + (chicken base) + util-io) + + ;; Valid git operating modes + (define git-modes + '((#:exit exit) + (#:output output) + (#:exit+output exit+output))) + + ;; Used for actual invocation of git binary, returns two values: exit + ;; code and output lines + (define (invoke-git repo args) + (apply get-process-exit+output-lines + "git" + "-C" + repo + args)) + + ;; Curried git repo command wrapper + (define (git repo . defargs) + (let ((defmode (if (null? defargs) + 'output + ;; Raises an error if not valid + (cadr (assq (car defargs) git-modes))))) + (case defmode + ((exit) + (lambda args + (let-values (((exit-code _) + (invoke-git repo args))) + exit-code))) + ((output) + (lambda args + (let-values (((_ output) + (invoke-git repo args))) + output))) + ((exit+output) + (lambda args + (invoke-git repo args)))))) + + )