]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
src/bin/duffman: Allow diffing git references, not just the working directory
authorAlejandro Colomar <alx@kernel.org>
Thu, 9 Jan 2025 12:27:23 +0000 (13:27 +0100)
committerAlejandro Colomar <alx@kernel.org>
Sat, 11 Jan 2025 18:58:53 +0000 (19:58 +0100)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
src/bin/duffman

index 48cd6d2348c5be4186e271a76bc94bdb448da3aa..a27cb2f06b4415a7949fa02a6ef60e73d053f0fb 100755 (executable)
@@ -22,7 +22,7 @@ while getopts "sU:w" opt; do
 done;
 shift $((OPTIND-1));
 
-if test $# -gt 0; then
+if test $# -gt 1; then
        >&2 echo "$(basename "$0"): error: Too many arguments.";
        exit 1;
 fi;
@@ -34,14 +34,22 @@ test -v MAN_KEEP_FORMATTING || export MAN_KEEP_FORMATTING=1;
 # shellcheck disable=SC2206  # We want only non-empty variables in the array.
 opts=($s $w $u);
 
-git diff --name-only \
+case $# in
+0)  git diff --name-only;
+*)  git diff --name-only "$1^..$1";
+esac \
 | grep -E '(\.[[:digit:]]([[:alpha:]][[:alnum:]]*)?\>|\.man)+(\.man|\.in)*$' \
 | sortman \
 | while read f; do \
-       old="HEAD:$f";
-       new="./$f";
+       case $# in
+       0)  old="HEAD:$f";  new="./$f";   ;;
+       *)  old="$1^:$f";   new="$1:$f";  ;;
+       esac;
 
-       cat "$new" \
+       case $# in
+       0)  cat "$new";       ;;
+       *)  git show "$new";  ;;
+       esac \
        | man /dev/stdin \
        | diff --label "$old" --label "$new" "${opts[@]}" \
                <(git show "$old" | man /dev/stdin) \