-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommit.rkt
61 lines (47 loc) · 1.78 KB
/
commit.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
(module commit '#%kernel
(#%require (for-syntax '#%kernel (only '#%utils find-executable-path)))
(define-values (dir) (vector-ref (current-command-line-arguments) 0))
(define-values (commit)
(environment-variables-ref (current-environment-variables)
#"GIT_COMMIT"))
(define-values (relevants-file) (build-path dir "relevants.rktd"))
(define-values (relevants) (call-with-input-file relevants-file read))
;; Shortcut for irrelevant commits:
(if (not (hash-ref relevants commit #f))
(exit 1)
(void))
(define-syntaxes (git-exe-stx)
(lambda (stx)
(let-values ([(pth) (find-executable-path "git")])
(if (not pth)
(datum->syntax stx '(error 'git-commit "could not find `git` in path"))
(datum->syntax stx (cons 'quote (cons pth null)))))))
(define-values (git-exe) (git-exe-stx))
(define-values (in) (current-input-port))
(define-values (tree-args)
(cdr (vector->list (current-command-line-arguments))))
(define-values (p i o e) (apply subprocess
(current-output-port)
#f
(current-error-port)
git-exe
"commit-tree"
tree-args))
(define-values (bstr) (make-bytes 4096))
(define-values (copy-loop)
(lambda ()
(define-values (n) (read-bytes! bstr in))
(if (eof-object? n)
(void)
(begin
(write-bytes bstr o 0 n)
(copy-loop)))))
(copy-loop)
(write-bytes #"\noriginal commit: " o)
(write-bytes commit o)
(write-bytes #"\n" o)
(close-output-port o)
(subprocess-wait p)
;; to avoid raco test failures
(module test racket)
)