# [PATCH 0/3] contrib/subtree: doc fixes and support for Meson

4 messages from 2025-01-17 to 2025-01-17. Participants: Patrick Steinhardt.
Thread: https://gitlist.dev/t/62822

## Patrick Steinhardt, 2025-01-17 09:56

Subject: [PATCH 0/3] contrib/subtree: doc fixes and support for Meson
Message-ID: <20250117-b4-pks-build-subtree-v1-0-03c2ed6cc42e@pks.im>
URL: https://gitlist.dev/e/20250117-b4-pks-build-subtree-v1-0-03c2ed6cc42e%40pks.im

```
Hi,

this patch series fixes a broken build of documentation in
"contrib/subtree". While at it it also wires up support for the Meson
build system.

Thanks!

Patrick

---
Patrick Steinhardt (3):
      contrib/subtree: fix building docs
      meson: introduce build option for contrib
      meson: wire up the git-subtree(1) command

 contrib/meson.build         |  4 ++-
 contrib/subtree/.gitignore  |  2 ++
 contrib/subtree/Makefile    | 23 ++++++++++-----
 contrib/subtree/meson.build | 71 +++++++++++++++++++++++++++++++++++++++++++++
 meson.build                 |  3 +-
 meson_options.txt           |  2 ++
 6 files changed, 95 insertions(+), 10 deletions(-)


---
base-commit: 757161efcca150a9a96b312d9e780a071e601a03
change-id: 20250117-b4-pks-build-subtree-17f91144340f


```

## Patrick Steinhardt, 2025-01-17 09:56

Subject: [PATCH 2/3] meson: introduce build option for contrib
Message-ID: <20250117-b4-pks-build-subtree-v1-2-03c2ed6cc42e@pks.im>
URL: https://gitlist.dev/e/20250117-b4-pks-build-subtree-v1-2-03c2ed6cc42e%40pks.im
In-Reply-To: <20250117-b4-pks-build-subtree-v1-0-03c2ed6cc42e@pks.im>

```
We unconditionally wire up building command completion present in the
"contrib/" directory. This may or may not be what users want, and we
don't provide a way to disable it.

Introduce a new "contrib" build option. This option is introduced as an
array so that users can manually pick which exact features they want to
include from the "contrib" directory. By default, we build and install
shell completions, which is a commonly used feature and also the current
default.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 contrib/meson.build | 4 +++-
 meson_options.txt   | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/contrib/meson.build b/contrib/meson.build
index a7b77b87c2..d74b64a518 100644
--- a/contrib/meson.build
+++ b/contrib/meson.build
@@ -1 +1,3 @@
-subdir('completion')
+foreach feature : get_option('contrib')
+  subdir(feature)
+endforeach
diff --git a/meson_options.txt b/meson_options.txt
index f50bb40cdf..4f02c92524 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -27,6 +27,8 @@ option('version', type: 'string', value: '',
   description: 'Version string reported by git-version(1) and other tools.')
 
 # Features supported by Git.
+option('contrib', type: 'array', value: [ 'completion' ], choices: [ 'completion', 'subtree' ],
+  description: 'Contributed features to include.')
 option('curl', type: 'feature', value: 'enabled',
   description: 'Build helpers used to access remotes with the HTTP transport.')
 option('expat', type: 'feature', value: 'enabled',

-- 
2.48.0.257.gd3603152ad.dirty


```

## Patrick Steinhardt, 2025-01-17 09:56

Subject: [PATCH 1/3] contrib/subtree: fix building docs
Message-ID: <20250117-b4-pks-build-subtree-v1-1-03c2ed6cc42e@pks.im>
URL: https://gitlist.dev/e/20250117-b4-pks-build-subtree-v1-1-03c2ed6cc42e%40pks.im
In-Reply-To: <20250117-b4-pks-build-subtree-v1-0-03c2ed6cc42e@pks.im>

```
In a38edab7c8 (Makefile: generate doc versions via GIT-VERSION-GEN,
2024-12-06), we have refactored how we build our documentation by
injecting the Git version into the Asciidoc and AsciiDoctor config
files instead of doing so via arguments. As such, the original config
files were removed, where the expectation is that they get generated via
`GIT-VERSION-GEN` now.

Whie the git-subtree(1) command part of "contrib/" also builds docs
using these same config files, its Makefile wasn't adjusted accordingly
and thus building the docs is broken.

Fix this by using `GIT-VERSION-GEN` to generate those files.

Reported-by: Renato Botelho <garga@FreeBSD.org>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 contrib/subtree/.gitignore |  2 ++
 contrib/subtree/Makefile   | 23 +++++++++++++++--------
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/contrib/subtree/.gitignore b/contrib/subtree/.gitignore
index 0b9381abca..6deaf177c7 100644
--- a/contrib/subtree/.gitignore
+++ b/contrib/subtree/.gitignore
@@ -1,4 +1,6 @@
 *~
+asciidoc.conf
+asciidoctor-extensions.rb
 git-subtree
 git-subtree.1
 git-subtree.html
diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile
index 6fa7496bfd..8fe0bfd401 100644
--- a/contrib/subtree/Makefile
+++ b/contrib/subtree/Makefile
@@ -1,6 +1,7 @@
 # The default target of this Makefile is...
 all::
 
+-include ../../shared.mak
 -include ../../config.mak.autogen
 -include ../../config.mak
 
@@ -13,17 +14,16 @@ htmldir ?= $(prefix)/share/doc/git-doc
 ../../GIT-VERSION-FILE: FORCE
 	$(MAKE) -C ../../ GIT-VERSION-FILE
 
--include ../../GIT-VERSION-FILE
-
 # this should be set to a 'standard' bsd-type install program
 INSTALL  ?= install
 RM       ?= rm -f
 
 ASCIIDOC         = asciidoc
-ASCIIDOC_CONF    = -f ../../Documentation/asciidoc.conf
+ASCIIDOC_CONF    = -f asciidoc.conf
 ASCIIDOC_HTML    = xhtml11
 ASCIIDOC_DOCBOOK = docbook
 ASCIIDOC_EXTRA   =
+ASCIIDOC_DEPS    = asciidoc.conf
 XMLTO            = xmlto
 XMLTO_EXTRA      =
 
@@ -32,8 +32,9 @@ ASCIIDOC         = asciidoctor
 ASCIIDOC_CONF    =
 ASCIIDOC_HTML    = xhtml5
 ASCIIDOC_DOCBOOK = docbook
-ASCIIDOC_EXTRA  += -I../../Documentation -rasciidoctor-extensions
+ASCIIDOC_EXTRA  += -I. -rasciidoctor-extensions
 ASCIIDOC_EXTRA  += -alitdd='&\#x2d;&\#x2d;'
+ASCIIDOC_DEPS    = asciidoctor-extensions.rb
 XMLTO_EXTRA     += --skip-validation
 endif
 
@@ -82,13 +83,13 @@ install-html: $(GIT_SUBTREE_HTML)
 $(GIT_SUBTREE_DOC): $(GIT_SUBTREE_XML)
 	$(XMLTO) -m $(MANPAGE_XSL) $(XMLTO_EXTRA) man $^
 
-$(GIT_SUBTREE_XML): $(GIT_SUBTREE_TXT)
+$(GIT_SUBTREE_XML): $(GIT_SUBTREE_TXT) $(ASCIIDOC_DEPS)
 	$(ASCIIDOC) -b $(ASCIIDOC_DOCBOOK) -d manpage $(ASCIIDOC_CONF) \
-		-agit_version=$(GIT_VERSION) $(ASCIIDOC_EXTRA) $^
+		$(ASCIIDOC_EXTRA) $<
 
-$(GIT_SUBTREE_HTML): $(GIT_SUBTREE_TXT)
+$(GIT_SUBTREE_HTML): $(GIT_SUBTREE_TXT) $(ASCIIDOC_DEPS)
 	$(ASCIIDOC) -b $(ASCIIDOC_HTML) -d manpage $(ASCIIDOC_CONF) \
-		-agit_version=$(GIT_VERSION) $(ASCIIDOC_EXTRA) $^
+		$(ASCIIDOC_EXTRA) $<
 
 $(GIT_SUBTREE_TEST): $(GIT_SUBTREE)
 	cp $< $@
@@ -98,6 +99,12 @@ test: $(GIT_SUBTREE_TEST)
 
 clean:
 	$(RM) $(GIT_SUBTREE)
+	$(RM) asciidoc.conf asciidoctor-extensions.rb
 	$(RM) *.xml *.html *.1
 
+asciidoc.conf: ../../Documentation/asciidoc.conf.in ../../GIT-VERSION-FILE
+	$(QUIET_GEN)$(call version_gen,"$(shell pwd)/../..",$<,$@)
+asciidoctor-extensions.rb: ../../Documentation/asciidoctor-extensions.rb.in ../../GIT-VERSION-FILE
+	$(QUIET_GEN)$(call version_gen,"$(shell pwd)/../..",$<,$@)
+
 .PHONY: FORCE

-- 
2.48.0.257.gd3603152ad.dirty


```

## Patrick Steinhardt, 2025-01-17 09:56

Subject: [PATCH 3/3] meson: wire up the git-subtree(1) command
Message-ID: <20250117-b4-pks-build-subtree-v1-3-03c2ed6cc42e@pks.im>
URL: https://gitlist.dev/e/20250117-b4-pks-build-subtree-v1-3-03c2ed6cc42e%40pks.im
In-Reply-To: <20250117-b4-pks-build-subtree-v1-0-03c2ed6cc42e@pks.im>

```
Wire up the git-subtree(1) command, which is part of "contrib/". Note
that we have to move around the exact location where we include the
"contrib/" subdirectory so that it comes after building the docs so that
we have access to some of the common functionality.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 contrib/subtree/meson.build | 71 +++++++++++++++++++++++++++++++++++++++++++++
 meson.build                 |  3 +-
 2 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/contrib/subtree/meson.build b/contrib/subtree/meson.build
new file mode 100644
index 0000000000..a752a188df
--- /dev/null
+++ b/contrib/subtree/meson.build
@@ -0,0 +1,71 @@
+git_subtree = custom_target(
+  input: 'git-subtree.sh',
+  output: 'git-subtree',
+  command: [
+    shell,
+    meson.project_source_root() / 'generate-script.sh',
+    '@INPUT@',
+    '@OUTPUT@',
+    meson.project_build_root() / 'GIT-BUILD-OPTIONS',
+  ],
+  install: true,
+  install_dir: get_option('libexecdir') / 'git-core',
+)
+
+subtree_test_environment = test_environment
+subtree_test_environment.prepend('PATH', meson.current_build_dir())
+
+test('t7900-subtree', shell,
+  args: [ 't7900-subtree.sh' ],
+  env: subtree_test_environment,
+  workdir: meson.current_source_dir() / 't',
+  depends: test_dependencies + bin_wrappers + [ git_subtree ],
+  timeout: 0,
+)
+
+if get_option('docs').contains('man')
+  subtree_xml = custom_target(
+    command: asciidoc_common_options + [
+      '--backend=' + asciidoc_docbook,
+      '--doctype=manpage',
+      '--out-file=@OUTPUT@',
+      '@INPUT@',
+    ],
+    depends: documentation_deps,
+    input: 'git-subtree.txt',
+    output: 'git-subtree.xml',
+  )
+
+  custom_target(
+    command: [
+      xmlto,
+      '-m', '@INPUT@',
+      'man',
+      subtree_xml,
+      '-o',
+      meson.current_build_dir(),
+    ] + xmlto_extra,
+    input: [
+      '../../Documentation/manpage-normal.xsl',
+    ],
+    output: 'git-subtree.1',
+    install: true,
+    install_dir: get_option('mandir') / 'man1',
+  )
+endif
+
+if get_option('docs').contains('html')
+  custom_target(
+    command: asciidoc_common_options + [
+      '--backend=' + asciidoc_html,
+      '--doctype=manpage',
+      '--out-file=@OUTPUT@',
+      '@INPUT@',
+    ],
+    depends: documentation_deps,
+    input: 'git-subtree.txt',
+    output: 'git-subtree.html',
+    install: true,
+    install_dir: get_option('datadir') / 'doc/git-doc',
+  )
+endif
diff --git a/meson.build b/meson.build
index 0064eb64f5..ac7f6ef38b 100644
--- a/meson.build
+++ b/meson.build
@@ -1857,7 +1857,6 @@ endforeach
 if intl.found()
   subdir('po')
 endif
-subdir('contrib')
 
 # Gitweb requires Perl, so we disable the auto-feature if Perl was not found.
 # We make sure further up that Perl is required in case the gitweb option is
@@ -1884,6 +1883,8 @@ if get_option('docs') != []
   subdir('Documentation')
 endif
 
+subdir('contrib')
+
 foreach key, value : {
   'DIFF': diff.full_path(),
   'GIT_TEST_CMP': diff.full_path() + ' -u',

-- 
2.48.0.257.gd3603152ad.dirty


```
