Subject: [bug#63874] [PATCH v2] gnu: git-filter-repo: Update to 2.38.0.

From: Hilton Chain <[email-masked]>
Date: Fri, 16 Feb 2024 01:34:59 +0800

From: Josselin Poiret <[email-masked]>

* gnu/packages/patches/git-filter-repo-generate-doc.patch: New file.
* gnu/local.mk (dist_patch_DATA): Regisiter it.
* gnu/packages/version-control.scm (git-filter-repo): Update to 2.38.0.
[source]: Switch to git-fetch.
Use the patch.
[build-system]: Switch to gnu-build-system.
[native-inputs]: Add asciidoc, docbook-xsl, libxml2, xmlto.

Modified-by: Hilton Chain <[email-masked]>
Change-Id: I7b15975ea56c44ae580d19cfe5a9e3eb75c6db0d
---

Hi Josselin, Ludo,

I adjusted the patch a bit, and added a phase to unpack git's source.  So that
the shipped patch only includes Makefiles now.

 gnu/local.mk                                  |  1 +
 .../git-filter-repo-generate-doc.patch        | 88 +++++++++++++++++++
 gnu/packages/version-control.scm              | 69 ++++++++++++---
 3 files changed, 144 insertions(+), 14 deletions(-)
 create mode 100644 gnu/packages/patches/git-filter-repo-generate-doc.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 4bd8e6ec6a..d9a4c8f204 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1308,6 +1308,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/ghostscript-no-header-id.patch		\
   %D%/packages/patches/ghostscript-no-header-uuid.patch		\
   %D%/packages/patches/ghostscript-no-header-creationdate.patch \
+  %D%/packages/patches/git-filter-repo-generate-doc.patch	\
   %D%/packages/patches/gitg-fix-positional-argument.patch	\
   %D%/packages/patches/gklib-suitesparse.patch			\
   %D%/packages/patches/glib-appinfo-watch.patch			\
diff --git a/gnu/packages/patches/git-filter-repo-generate-doc.patch b/gnu/packages/patches/git-filter-repo-generate-doc.patch
new file mode 100644
index 0000000000..e0bbc7831c
--- /dev/null
+++ b/gnu/packages/patches/git-filter-repo-generate-doc.patch
@@ -0,0 +1,88 @@
+From 56e6857e71d2b2a2236625f3c8b112bd40a8b164 Mon Sep 17 00:00:00 2001
+From: Josselin Poiret <[email-masked]>
+Date: Fri, 16 Feb 2024 00:21:06 +0800
+Subject: [PATCH] Add documentation generation.
+
+This requires the manpage XSL and asciidoc config files from git 2.41.0.
+
+Modified-by: Hilton Chain <[email-masked]>
+---
+ Documentation/Makefile | 34 ++++++++++++++++++++++++++++++++++
+ Makefile               | 17 +++--------------
+ 2 files changed, 37 insertions(+), 14 deletions(-)
+ create mode 100644 Documentation/Makefile
+
+diff --git a/Documentation/Makefile b/Documentation/Makefile
+new file mode 100644
+index 0000000..d81ffbe
+--- /dev/null
++++ b/Documentation/Makefile
+@@ -0,0 +1,34 @@
++MAN_BASE_URL := $(prefix)/share/doc/git-doc/
++VERSION := $(git log --pretty="%H" -n 1)
++
++ASCIIDOC := asciidoc
++ASCIIDOC_EXTRA :=
++ASCIIDOC_HTML := xhtml11
++ASCIIDOC_DOCBOOK := docbook
++ASCIIDOC_CONF := -f asciidoc.conf
++ASCIIDOC_COMMON := $(ASCIIDOC) $(ASCIIDOC_EXTRA) $(ASCIIDOC_CONF) \
++		-amanmanual='git-filter-repo Manual' -amansource='git-filter-repo $(VERSION)'
++ASCIIDOC_DEPS := asciidoc.conf
++TXT_TO_HTML := $(ASCIIDOC_COMMON) -b $(ASCIIDOC_HTML)
++TXT_TO_XML := $(ASCIIDOC_COMMON) -b $(ASCIIDOC_DOCBOOK)
++MANPAGE_XSL := manpage-normal.xsl
++XMLTO := xmlto
++XMLTO_EXTRA := -m manpage-bold-literal.xsl \
++		--stringparam man.base.url.for.relative.links='$(MAN_BASE_URL)'
++
++manpage-prereqs := $(wildcard manpage*.xsl)
++manpage-cmd := $(XMLTO) -m $(MANPAGE_XSL) $(XMLTO_EXTRA) man
++
++%.xml : %.txt $(ASCIIDOC_DEPS)
++	$(TXT_TO_XML) -d manpage -o $@ $<
++
++man1/%.1 : %.xml $(manpage-prereqs)
++	mkdir -p man1
++	$(manpage-cmd) -o man1 $<
++
++html/%.html : %.txt $(ASCIIDOC_DEPS)
++	mkdir -p html
++	$(TXT_TO_HTML) -d manpage -o $@ $<
++
++man: man1/git-filter-repo.1
++html: html/git-filter-repo.html
+diff --git a/Makefile b/Makefile
+index a443450..d965ae5 100644
+--- a/Makefile
++++ b/Makefile
+@@ -20,21 +20,10 @@ test:
+ fixup_locale:
+ 	sed -ie s%@@LOCALEDIR@@%$(localedir)% git-filter-repo
+
+-# People installing from tarball will already have man1/git-filter-repo.1 and
+-# html/git-filter-repo.html.  But let's support people installing from a git
+-# clone too; for them, just cheat and snag a copy of the built docs that I
+-# record in a different branch.
+-snag_docs: Documentation/man1/git-filter-repo.1 Documentation/html/git-filter-repo.html
++doc:
++	$(MAKE) -C Documentation man html
+
+-Documentation/man1/git-filter-repo.1:
+-	mkdir -p Documentation/man1
+-	git show origin/docs:man1/git-filter-repo.1 >Documentation/man1/git-filter-repo.1
+-
+-Documentation/html/git-filter-repo.html:
+-	mkdir -p Documentation/html
+-	git show origin/docs:html/git-filter-repo.html >Documentation/html/git-filter-repo.html
+-
+-install: snag_docs #fixup_locale
++install: doc #fixup_locale
+ 	install -Dm0755 git-filter-repo "$(DESTDIR)/$(bindir)/git-filter-repo"
+ 	install -dm0755 "$(DESTDIR)/$(pythondir)"
+ 	ln -sf "$(bindir)/git-filter-repo" "$(DESTDIR)/$(pythondir)/git_filter_repo.py"
+
+base-commit: cbc6535694380d3a3bf3e5c96410d4ce7e8de94f
+--
+2.41.0
+
diff --git a/gnu/packages/version-control.scm b/gnu/packages/version-control.scm
index 242e6dae2e..148349cb49 100644
--- a/gnu/packages/version-control.scm
+++ b/gnu/packages/version-control.scm
@@ -50,6 +50,8 @@
 ;;; Copyright © 2023 Nicolas Graves <[email-masked]>
 ;;; Copyright © 2023 Kjartan Oli Agustsson <[email-masked]>
 ;;; Copyright © 2023 Steve George <[email-masked]>
+;;; Copyright © 2023 Josselin Poiret <[email-masked]>
+;;; Copyright © 2024 Hilton Chain <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -3844,25 +3846,64 @@ (define-public qgit
 (define-public git-filter-repo
   (package
     (name "git-filter-repo")
-    (version "2.29.0")
+    (version "2.38.0")
     (source
      (origin
-       ;; Use a release tarball instead of 'git-fetch' because it contains
-       ;; pre-compiled man-pages which are too hard to build in this context
-       ;; as it depends on Git's Makefile.
-       (method url-fetch)
-       (uri (string-append "https://github.com/newren/git-filter-repo/releases/"
-                           "download/v" version
-                           "/git-filter-repo-" version ".tar.xz"))
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/newren/git-filter-repo")
+             (commit (string-append "v" version))))
+       (file-name (git-file-name name version))
        (sha256
         (base32
-         "00nn7k9jqrybb762486fmigsnbcn9lbvimgpfvvarz4ikdp9y9pb"))))
-    (build-system copy-build-system)
+         "1al43zpw1mdfy9i05w4xw178abypjwnkk52lqvmbl19lr1l47r4i"))
+       ;; Modified from <https://github.com/newren/git-filter-repo/pull/477>.
+       ;; Used with 'unpack-git-source phase.
+       (patches (search-patches "git-filter-repo-generate-doc.patch"))))
+    (build-system gnu-build-system)
     (arguments
-     `(#:install-plan
-       '(("git-filter-repo" "libexec/git-core/")
-         ("Documentation/man1/" "share/man/man1")
-         ("/" "" #:include ()))))
+     (list
+      #:tests? #f                       ;No tests.
+      #:imported-modules
+      `(,@%gnu-build-system-modules
+        (guix build python-build-system))
+      #:modules
+      '((guix build gnu-build-system)
+        ((guix build python-build-system) #:select (site-packages))
+        (guix build utils)
+        (srfi srfi-26))
+      #:make-flags
+      #~(list (string-append "prefix=" #$output)
+              (string-append "VERSION=" #$(package-version this-package)))
+      #:phases
+      #~(modify-phases %standard-phases
+          (delete 'configure)
+          (add-after 'unpack 'unpack-git-source
+            (lambda _
+              (let* ((old-path (getcwd))
+                     (doc-source (string-append old-path "/Documentation")))
+                (mkdir-p "git-source")
+                (chdir "git-source")
+                ((assoc-ref %standard-phases 'unpack)
+                 #:source #+(package-source git))
+                (for-each
+                 (cut install-file <> doc-source)
+                 (find-files "." "asciidoc\\.conf$|manpage.*\\.xsl$"))
+                (chdir old-path)
+                (delete-file-recursively "git-source"))))
+          (add-before 'build 'set-pythondir
+            (lambda* (#:key inputs outputs #:allow-other-keys)
+              (substitute* "Makefile"
+                (("(pythondir = ).*" _ pre)
+                 (string-append pre (site-packages inputs outputs))))))
+          (replace 'build
+            (lambda* (#:key make-flags #:allow-other-keys)
+              (apply invoke "make" "doc" make-flags))))))
+    (native-inputs
+     (list asciidoc
+           docbook-xsl
+           libxml2                        ;for XML_CATALOG_FILES
+           xmlto))
     (inputs (list python))                ;for the shebang
     (home-page "https://github.com/newren/git-filter-repo")
     (synopsis "Quickly rewrite Git repository history")

base-commit: 203344cc37c8a7df1ec1454381b5069d53ce7f9e
prerequisite-patch-id: bc542897db0e11da4c0f8da09ec31dd533cf2825
prerequisite-patch-id: fd7da036342f36a8c698f5c8975f9e48d3ade435
prerequisite-patch-id: a2c81c14423bb9858f33d7d26976e8eea61982b7
prerequisite-patch-id: e30fd25b1dc4aaaff76474153836cd48e8565eb9
prerequisite-patch-id: 1d070b26dc64ee2ec95f14c4f5fc23419f766810
prerequisite-patch-id: 03de992f0312d5f0ee3368ebc3c1fad7c955d095
prerequisite-patch-id: 82a04291e3a1bb33ced83672956934fbe98d31dc
--
2.41.0