Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/scripts/test_strip_shell_comments.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ else
ok "plain and indented comment lines are dropped"
fi

# #2386: blank lines stay, so the shipped script keeps its paragraph breaks.
printf '#!/bin/sh\necho one\n\necho two\n' > "$WORK/blank.sh"
if [ "$(strip "$WORK/blank.sh" | wc -l)" = 4 ]; then
ok "blank lines survive"
else
bad "a blank line was dropped"
fi

live=$(grep -c LIVE "$WORK/fixture.out")
if [ "$live" = 6 ]; then
ok "heredoc bodies, multi-line strings and continuations are left alone (6/6)"
Expand Down
5 changes: 3 additions & 2 deletions general/scripts/strip-shell-comments.awk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Drop whole-line comments and blank lines from a POSIX shell script.
# Drop whole-line comments from a POSIX shell script.
# Keep blank lines to preserve readability. See #2386.
#
# Comments are worth writing and worth keeping in the tree, but every byte of
# them is also flashed to an 8MB camera. sysupgrade alone reached 52KB, 57% of
Expand Down Expand Up @@ -104,7 +105,7 @@ BEGIN { nd = 0; sq = 0; dq = 0; cont = 0; prev_cont = 0 }
next
}

if (/^[ \t]*$/) next
if (/^[ \t]*$/) { print; next }
Comment thread
usa- marked this conversation as resolved.
Comment thread
usa- marked this conversation as resolved.
Comment thread
openipc-ai marked this conversation as resolved.

code = code_of($0)
if (code ~ /^[ \t]*$/) next # the line was only a comment
Expand Down
Loading