Skip to content

Commit

Permalink
update-doc-branches: add command to update man and html
Browse files Browse the repository at this point in the history
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 <[email protected]>
Tested-by: Rob Browning <[email protected]>
  • Loading branch information
rlbdv committed Oct 20, 2018
1 parent d90aaa8 commit 178805d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 19 deletions.
25 changes: 6 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions dev/update-doc-branches
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 178805d

Please sign in to comment.