From 172cccc8b0205122f3061a70d016f745950da00e Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Sat, 20 Oct 2018 12:35:11 -0500 Subject: [PATCH] update-doc-branches: add command to update man and html Create a new command to update the man and html branches, and move the related code there from the Makefile. Update the branches based on the current (clean) tree, rather than consulting the git origin, and rely on ls-files rather than globbing so that the file lists will always be correct -- we'll immediately notice deletions, avoid picking up stray files in the directory, etc. Signed-off-by: Rob Browning Tested-by: Rob Browning --- Makefile | 25 ++++++------------------ dev/update-doc-branches | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 19 deletions(-) create mode 100755 dev/update-doc-branches diff --git a/Makefile b/Makefile index c0c4366..5c00c29 100644 --- a/Makefile +++ b/Makefile @@ -244,25 +244,12 @@ Documentation/%.html: Documentation/%.md Documentation/substvars Documentation/clean: cd Documentation && rm -f *~ .*~ *.[0-9] *.html substvars -# update the local 'man' and 'html' branches with pregenerated output files, for -# people who don't have pandoc (and maybe to aid in google searches or something) -export-docs: Documentation/all - git update-ref refs/heads/man origin/man '' 2>/dev/null || true - git update-ref refs/heads/html origin/html '' 2>/dev/null || true - set -eo pipefail; \ - GIT_INDEX_FILE=gitindex.tmp; export GIT_INDEX_FILE; \ - rm -f $${GIT_INDEX_FILE} && \ - git add -f Documentation/*.1 && \ - git update-ref refs/heads/man \ - $$(echo "Autogenerated man pages for $$(git describe --always)" \ - | git commit-tree $$(git write-tree --prefix=Documentation) \ - -p refs/heads/man) && \ - rm -f $${GIT_INDEX_FILE} && \ - git add -f Documentation/*.html && \ - git update-ref refs/heads/html \ - $$(echo "Autogenerated html pages for $$(git describe --always)" \ - | git commit-tree $$(git write-tree --prefix=Documentation) \ - -p refs/heads/html) +# Note: this adds commits containing the current manpages in roff and +# html format to the man and html branches respectively. The version +# is determined by "git describe --always". +.PHONY: update-doc-branches +update-doc-branches: Documentation/all + dev/update-doc-branches refs/heads/man refs/heads/html # push the pregenerated doc files to origin/man and origin/html push-docs: export-docs diff --git a/dev/update-doc-branches b/dev/update-doc-branches new file mode 100755 index 0000000..226a152 --- /dev/null +++ b/dev/update-doc-branches @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +# Ensures that the working tree is clean, and Documentation/ is up to +# date, and then commits Documentation/*.1 to the man branch, and +# Documentation/*.html to the html branch. + +set -uexo pipefail + +test "$#" -eq 2 + +# Must be full ref name, i.e. refs/heads/man, etc. +man_ref="$1" +html_ref="$2" + +git diff-index --quiet HEAD -- # no uncommitted changes +git rev-parse --verify "$man_ref" +git rev-parse --verify "$html_ref" +echo "$man_ref" | grep -qE '^refs/heads' +echo "$html_ref" | grep -qE '^refs/heads' + +"${MAKE:-make}" + +tmpdir="$(mktemp -d "t/tmp/update-doc-branches-XXXXXX")" +trap "$(printf 'rm -rf %q' "$tmpdir")" EXIT +tmpidx="$tmpdir/git-index.tmp" + +for fmt in man html; do + rm -f "$tmpidx" + for f in $(git ls-files 'Documentation/*.md'); do + base="$(basename "$f" .md)" + if test "$fmt" = man; then + ref="$man_ref" + GIT_INDEX_FILE="$tmpidx" git add -f "Documentation/$base.1" + else + ref="$html_ref" + GIT_INDEX_FILE="$tmpidx" git add -f "Documentation/$base.html" + fi + done + msg="Update $fmt pages for $(git describe --always)" + tree=$(GIT_INDEX_FILE="$tmpidx" git write-tree --prefix=Documentation) + commit=$(echo "$msg" | git commit-tree "$tree" -p refs/heads/"$fmt") + git update-ref "$ref" "$commit" +done -- 2.39.2