Skip to content

Commit 8eafa15

Browse files
committed
Add a branchdiff target for reviewing changes
Add a script and Makefile target to generate a diff PDF comparing the current branch (and any uncommitted changes) against origin/main. It works by building latex files for the current source, then stashing any changes and returning to origin/main and building again, then producing the PDF. Finally it returns to the original branch and retrieves any stashed changes. This is useful for reviewing spec changes before submitting patches. The diff PDF shows additions in bold. An attempt to use change bars resulted in corrupted output. Usage: make branchdiff Co-developed-by: Claude <[email protected]> Signed-off-by: Simon Glass <[email protected]>
1 parent 1be2a60 commit 8eafa15

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ all: latexpdf html
1616
help:
1717
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
1818
@echo " latexdiff to make LaTeX files including changebars against previous release"
19+
@echo " branchdiff to make a diff PDF comparing current branch against origin/main"
1920

20-
.PHONY: all help latexdiff Makefile
21+
.PHONY: all help latexdiff branchdiff Makefile
2122

2223
latexdiff: latex
2324
@echo "Generating LaTeX changebars..."
@@ -30,6 +31,12 @@ latexdiff: latex
3031
@echo
3132
@echo "latexdiff finished; the PDF files are in $(BUILDDIR)/latex."
3233

34+
branchdiff:
35+
@echo "Generating diff PDF against origin/main..."
36+
@./scripts/make-diff-pdf
37+
@echo
38+
@echo "branchdiff finished; diff.pdf is in the top-level directory."
39+
3340
# Catch-all target: route all unknown targets to Sphinx using the new
3441
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
3542
%: Makefile

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,23 @@ Make commands:
7979
>$ make latexpdf # For generating pdf
8080
>$ make html # For generating a hierarchy of html pages
8181
>$ make singlehtml # For generating a single html page
82+
>$ make branchdiff # For generating a diff PDF against the main branch
8283
>```
8384
8485
Output goes in ./build subdirectory.
8586
87+
## Reviewing Changes
88+
89+
When working on a branch, you can generate a PDF showing changes against
90+
origin/main:
91+
92+
>```
93+
>$ make branchdiff
94+
>```
95+
96+
This produces `diff.pdf` in the top-level directory with additions shown in
97+
bold and deletions struck through. Requires `latexdiff` to be installed.
98+
8699
## License ##
87100
This project is licensed under the Apache V2 license. More information can be found
88101
in the LICENSE and NOTICE file or online at:

scripts/make-diff-pdf

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# Generate a diff PDF comparing the current branch against origin/main
5+
# Additions shown in bold, deletions struck through
6+
7+
set -e
8+
9+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
10+
ROOT_DIR="$(dirname "$SCRIPT_DIR")"
11+
BUILD_DIR="$ROOT_DIR/build/latex"
12+
OLD_TEX="/tmp/fit-spec-old.tex"
13+
14+
cd "$ROOT_DIR"
15+
16+
# Remember current branch
17+
CURRENT_BRANCH=$(git branch --show-current)
18+
if [ -z "$CURRENT_BRANCH" ]; then
19+
echo "Error: Not on a branch (detached HEAD?)"
20+
exit 1
21+
fi
22+
23+
echo "Generating diff: origin/main -> $CURRENT_BRANCH"
24+
25+
# Stash any uncommitted changes
26+
STASH_NEEDED=false
27+
if ! git diff --quiet || ! git diff --cached --quiet; then
28+
echo "Stashing uncommitted changes..."
29+
git stash push -m "make-diff-pdf temporary stash"
30+
STASH_NEEDED=true
31+
fi
32+
33+
# Function to restore state on exit
34+
cleanup() {
35+
echo "Returning to $CURRENT_BRANCH..."
36+
git checkout "$CURRENT_BRANCH" 2>/dev/null || true
37+
if [ "$STASH_NEEDED" = true ]; then
38+
echo "Restoring stashed changes..."
39+
git stash pop || true
40+
fi
41+
}
42+
trap cleanup EXIT
43+
44+
# Build origin/main
45+
echo "Building origin/main..."
46+
git checkout origin/main
47+
make latex > /dev/null 2>&1
48+
cp "$BUILD_DIR/fit-specification.tex" "$OLD_TEX"
49+
50+
# Build current branch (cleanup trap will checkout)
51+
echo "Building $CURRENT_BRANCH branch..."
52+
git checkout "$CURRENT_BRANCH"
53+
if [ "$STASH_NEEDED" = true ]; then
54+
git stash pop
55+
STASH_NEEDED=false
56+
fi
57+
make latex > /dev/null 2>&1
58+
59+
# Generate diff in build/latex directory (where Sphinx class files are)
60+
echo "Running latexdiff..."
61+
latexdiff --type=BOLD "$OLD_TEX" "$BUILD_DIR/fit-specification.tex" \
62+
> "$BUILD_DIR/diff.tex" 2>/dev/null
63+
64+
# Compile PDF (twice for cross-references)
65+
echo "Compiling PDF..."
66+
cd "$BUILD_DIR"
67+
pdflatex -interaction=nonstopmode diff.tex > /dev/null 2>&1
68+
pdflatex -interaction=nonstopmode diff.tex > /dev/null 2>&1
69+
70+
# Move PDF to root and clean up
71+
mv diff.pdf "$ROOT_DIR/"
72+
rm -f diff.aux diff.log diff.out diff.toc diff.idx diff.ind diff.ilg diff.tex 2>/dev/null
73+
74+
echo "Done: $ROOT_DIR/diff.pdf"

0 commit comments

Comments
 (0)