| 1 | #! /bin/sh
|
| 2 | # -*-scheme-*-
|
| 3 | export LANG=C LANGUAGE=C LC_TIME=C
|
| 4 | export TZ=UTC0
|
| 5 | exec guile --no-auto-compile -L $srcdir -C $srcdir -e '(mdate-from-git)' -s "$0" "$@"
|
| 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 | (define-module (mdate-from-git)
|
| 43 | #:use-module (ice-9 match)
|
| 44 | #:use-module (ice-9 popen)
|
| 45 | #:use-module (ice-9 rdelim)
|
| 46 | #:use-module (ice-9 regex)
|
| 47 | #:export (main))
|
| 48 |
|
| 49 | (define (pipe-command command)
|
| 50 | (let* ((port (apply open-pipe* OPEN_READ command))
|
| 51 | (output (read-string port)))
|
| 52 | (close-port port)
|
| 53 | output))
|
| 54 |
|
| 55 | (define (guix.LANG.texi->guix-manual.LANG.po file-name)
|
| 56 | "Translated manuals doc/guix.LANG.texi are not tracked in Git and are
|
| 57 | generated from po/doc/guix-manual.LANG.po. For such an untraced .TEXI file,
|
| 58 | return its .PO counterpart."
|
| 59 | (let ((m (string-match "doc/guix.([^.]+).texi" file-name)))
|
| 60 | (if (not m) file-name
|
| 61 | (let ((lang (match:substring m 1)))
|
| 62 | (format #f "po/doc/guix-manual.~a.po" lang)))))
|
| 63 |
|
| 64 |
|
| 65 | |
| 66 | |
| 67 | |
| 68 | (define (main args)
|
| 69 | (match args
|
| 70 | ((script file-name)
|
| 71 | (let* ((command `("git" "ls-files" "--error-unmatch" "--" ,file-name))
|
| 72 | (tracked? (zero? (with-error-to-port (%make-void-port "w")
|
| 73 | (lambda _
|
| 74 | (with-output-to-port (%make-void-port "w")
|
| 75 | (lambda _ (apply system* command)))))))
|
| 76 | (file-name (if tracked? file-name
|
| 77 | (guix.LANG.texi->guix-manual.LANG.po file-name)))
|
| 78 | (command `("git" "log" "--pretty=format:%ct" "-n1" "--" ,file-name))
|
| 79 | (timestamp (with-error-to-port (%make-void-port "w")
|
| 80 | (lambda _ (pipe-command command))))
|
| 81 | (source-date-epoch (or (getenv "SOURCE_DATE_EPOCH") "1"))
|
| 82 | (timestamp (if (string-null? timestamp) source-date-epoch
|
| 83 | timestamp))
|
| 84 | (time (gmtime (string->number timestamp)))
|
| 85 | (d-m-y (strftime "%-d %B %Y" time)))
|
| 86 | (display d-m-y)))
|
| 87 | (_
|
| 88 | (format (current-error-port) "Usage: mdate-from-git.scm FILE\n")
|
| 89 | (exit 2))))
|