]> arthur.barton.de Git - bup.git/commitdiff
update-doc-branches: add command to update man and html
authorRob Browning <rlb@defaultvalue.org>
Sat, 20 Oct 2018 17:35:11 +0000 (12:35 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sat, 20 Oct 2018 18:46:50 +0000 (13:46 -0500)
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 <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
Makefile
dev/update-doc-branches [new file with mode: 0755]

index 89b34e1015302d2ba16896d991d3e72b65412843..201af4c424722cb747c0fc0e9cc580aa318e0d3a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -247,25 +247,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 (executable)
index 0000000..226a152
--- /dev/null
@@ -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