Add simple git wrapper.
This commit is contained in:
parent
7fede3fd96
commit
62367d7f41
2 changed files with 80 additions and 1 deletions
|
@ -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-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 \
|
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 \
|
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
|
.PHONY: imports
|
||||||
imports: $(HACKERBASE-DEPS)
|
imports: $(HACKERBASE-DEPS)
|
||||||
|
@ -355,3 +355,8 @@ SPECIFICATION-SOURCES=specification.scm period.import.scm
|
||||||
|
|
||||||
specification.o: specification.import.scm
|
specification.o: specification.import.scm
|
||||||
specification.import.scm: $(SPECIFICATION-SOURCES)
|
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)
|
||||||
|
|
74
src/util-git.scm
Normal file
74
src/util-git.scm
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
;;
|
||||||
|
;; util-git.scm
|
||||||
|
;;
|
||||||
|
;; Support for simple git integration.
|
||||||
|
;;
|
||||||
|
;; ISC License
|
||||||
|
;;
|
||||||
|
;; Copyright 2023 Brmlab, z.s.
|
||||||
|
;; Dominik Pantůček <dominik.pantucek@trustica.cz>
|
||||||
|
;;
|
||||||
|
;; 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))))))
|
||||||
|
|
||||||
|
)
|
Loading…
Add table
Add a link
Reference in a new issue