unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob 0abd5804603b4dc3b79081331a890e48670e7918 3232 bytes (raw)
name: build-aux/mdate-from-git.scm 	 # note: path name is non-authoritative(*)

 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
 
#! /bin/sh
# -*-scheme-*-
exec guile --no-auto-compile -L $srcdir -C $srcdir -e '(mdate-from-git)' -s "$0" "$@"
!#

;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2024 Janneke Nieuwenhuizen <janneke@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; This program 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.
;;;
;;; This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

;;;; Commentary:
;;;
;;; Usage: mdate-from-git FILE
;;;
;;; This script is compatible with Automake's `mdate-sh' but uses the timestamp
;;; from Git instead of from the file system.  Also, it can be appended to
;;; mdate-sh.

;;; As a special exception for Guix, it caters for doc/guix.LANG.texi files that
;;; are not stored in Git, by using po/doc/guix-manual.LANG.po for the Git
;;; timestamp.  Test doing something like:
;;;
;;; build-aux/mdate-from-git.scm doc/guix.de.texi
;;;
;;;; Code:

(define-module (mdate-from-git)
  #:use-module (ice-9 match)
  #:use-module (ice-9 popen)
  #:use-module (ice-9 rdelim)
  #:use-module (ice-9 regex)
  #:export (main))

(define (pipe-command command)
  (let* ((port (apply open-pipe* OPEN_READ command))
         (output (read-string port)))
    (close-port port)
    output))

(define (guix.LANG.texi->guix-manual.LANG.po file-name)
  "Translated manuals doc/guix.LANG.texi are not tracked in Git and are
generated from po/doc/guix-manual.LANG.po.  For such an untraced .TEXI file,
return its .PO counterpart."
  (let ((m (string-match "doc/guix.([^.]+).texi" file-name)))
    (if (not m) file-name
        (let ((lang (match:substring m 1)))
          (format #f "po/doc/guix-manual.~a.po" lang)))))

\f
;;;
;;; Entry point.
;;;
(define (main args)
  (setenv "LANG" "C")
  (setenv "LANGUAGE" "C")
  (setenv "LC_TIME" "C")
  (setenv "TZ" "UTC0")
  (match args
    ((script file-name)
     (let* ((command `("git" "ls-files" "--error-unmatch" "--" ,file-name))
            (tracked? (zero? (with-error-to-port (%make-void-port "w")
                               (lambda _ (apply system* command)))))
            (file-name (if tracked? file-name
                           (guix.LANG.texi->guix-manual.LANG.po file-name)))
            (command `("git" "log" "--pretty=format:%ct" "-n1" "--" ,file-name))
            (timestamp (pipe-command command))
            (source-date-epoch (or (getenv "SOURCE_DATE_EPOCH") "1"))
            (timestamp (if (string-null? timestamp) source-date-epoch
                           timestamp))
            (time (gmtime (string->number timestamp)))
            (d-y-m (strftime "%-d %B %Y" time)))
       (display d-y-m)))
    (_
     (format (current-error-port) "Usage: mdate-from-git.scm FILE\n")
     (exit 2))))

debug log:

solving 0abd580460 ...
found 0abd580460 in https://yhetil.org/guix-patches/bb7d78763d44b6f6b7b38e72f90db8f7208496d1.1713087991.git.janneke@gnu.org/

applying [1/1] https://yhetil.org/guix-patches/bb7d78763d44b6f6b7b38e72f90db8f7208496d1.1713087991.git.janneke@gnu.org/
diff --git a/build-aux/mdate-from-git.scm b/build-aux/mdate-from-git.scm
new file mode 100755
index 0000000000..0abd580460

Checking patch build-aux/mdate-from-git.scm...
Applied patch build-aux/mdate-from-git.scm cleanly.

index at:
100755 0abd5804603b4dc3b79081331a890e48670e7918	build-aux/mdate-from-git.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).