Skip to content

Commit ebb6ef5

Browse files
committed
Use "input" and "output" as names in script; tweak CI
In the copy-packetline.sh script: - Rename all identifiers with "source" to "input", and with "destination" or "target" to "output". This includes variables and functions. - Adjust messages accordingly. This is not a simple search and replace, since sometimes "target" becomes "output location" (to avoid giving the impression that it must always being as a dir). - Adjust comments accordingly, but use the word "destination" in a few comments that had said "target", where it's clear it applies to "output" and seems to be clearer wording than "output". - A couple very small unrelated comment rephrasings for clarity. In the copy-packetline job definition in ci.yml: - Put `fail-fast: false`, which has no effect on a matrix that only generates one job, but will aid in producing results for all three platforms if the other two have to be reenabled to test a change to the script. This is what I had been using `continue-on-error` for, but `fail-fast: false` is the better way to do it (and also avoids confusion with the other meanings of `continue-on-error`). - Tweak indentation so that removing the leading `# ` on the macos-latest and windows-latest entries would place them in the list (so that if they ever have to be reenabled to test changes to the script, then this will be slightly easier).
1 parent d25e5d3 commit ebb6ef5

File tree

2 files changed

+52
-52
lines changed

2 files changed

+52
-52
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,14 @@ jobs:
217217

218218
check-packetline:
219219
strategy:
220+
fail-fast: false
220221
matrix:
221222
os:
222223
- ubuntu-latest
223224
# We consider this script read-only and its effect is the same everywhere.
224225
# However, when changes are made to `etc/copy-packetline.sh`, re-enable the other platforms for testing.
225-
# - macos-latest
226-
# - windows-latest
226+
# - macos-latest
227+
# - windows-latest
227228
runs-on: ${{ matrix.os }}
228229
defaults:
229230
run:

etc/copy-packetline.sh

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
set -euC -o pipefail
44

5-
readonly source_dir='gix-packetline/src'
6-
readonly destination_parent_dir='gix-packetline-blocking'
7-
readonly destination_dir="$destination_parent_dir/src"
5+
readonly input_dir='gix-packetline/src'
6+
readonly output_parent_dir='gix-packetline-blocking'
7+
readonly output_dir="$output_parent_dir/src"
88

99
function fail () {
1010
printf '%s: error: %s\n' "$0" "$1" >&2
@@ -14,7 +14,7 @@ function fail () {
1414
function chdir_toplevel () {
1515
local root_padded root
1616

17-
# Find the working tree's root. (Padding is for the trailing-newline case.)
17+
# Find the working tree's root. (Padding covers the trailing-newline case.)
1818
root_padded="$(git rev-parse --show-toplevel && echo -n .)" ||
1919
fail 'git-rev-parse failed to find top-level dir'
2020
root="${root_padded%$'\n.'}"
@@ -25,38 +25,38 @@ function chdir_toplevel () {
2525
function merging () {
2626
local git_dir_padded git_dir
2727

28-
# Find the .git directory. (Padding is for the trailing-newline case.)
28+
# Find the .git directory. (Padding covers the trailing-newline case.)
2929
git_dir_padded="$(git rev-parse --git-dir && echo -n .)" ||
3030
fail 'git-rev-parse failed to find git dir'
3131
git_dir="${git_dir_padded%$'\n.'}"
3232

3333
test -e "$git_dir/MERGE_HEAD"
3434
}
3535

36-
function target_dir_status () {
37-
git status --porcelain --ignored=traditional -- "$destination_dir" ||
36+
function output_dir_status () {
37+
git status --porcelain --ignored=traditional -- "$output_dir" ||
3838
fail 'git-status failed'
3939
}
4040

41-
function check_destination_dir () {
42-
if ! test -e "$destination_dir"; then
43-
# The target does not exist on disk, so nothing will be lost. Proceed.
41+
function check_output_dir () {
42+
if ! test -e "$output_dir"; then
43+
# The destination does not exist on disk, so nothing will be lost. Proceed.
4444
return
4545
fi
4646

4747
if merging; then
48-
# In a merge, it would be confusing to replace anything at the target.
49-
if target_dir_status | grep -q '^'; then
50-
fail 'target exists, and a merge is in progress'
48+
# In a merge, it would be confusing to replace anything at the destination.
49+
if output_dir_status | grep -q '^'; then
50+
fail 'output location exists, and a merge is in progress'
5151
fi
5252
else
53-
# We can lose data if anything of value at the target is not in the index.
54-
# (This includes unstaged deletions, for two reasons. One is that we could
55-
# lose track of which files had been deleted. More importantly, replacing a
53+
# We can lose data if anything of value at the destination is not in the
54+
# index. (This includes unstaged deletions, for two reasons. We could lose
55+
# track of which files had been deleted. More importantly, replacing a
5656
# staged symlink or regular file with an unstaged directory is shown by
5757
# git-status as only a deletion, even if the directory is non-empty.)
58-
if target_dir_status | grep -q '^.[^ ]'; then
59-
fail 'target exists, with unstaged changes or ignored files'
58+
if output_dir_status | grep -q '^.[^ ]'; then
59+
fail 'output location exists, with unstaged changes or ignored files'
6060
fi
6161
fi
6262
}
@@ -81,71 +81,70 @@ function first_line_ends_crlf () {
8181
}
8282

8383
function make_header () {
84-
local source_file endline
84+
local input_file endline
8585

86-
source_file="$1"
86+
input_file="$1"
8787
endline="$2"
8888

8989
# shellcheck disable=SC2016 # The backticks are intentionally literal.
9090
printf '// DO NOT EDIT - this is a copy of %s. Run `just copy-packetline` to update it.%s%s' \
91-
"$source_file" "$endline" "$endline"
91+
"$input_file" "$endline" "$endline"
9292
}
9393

9494
function copy_with_header () {
95-
local source_file target_file endline
95+
local input_file output_file endline
9696

97-
source_file="$1"
98-
target_file="$2"
97+
input_file="$1"
98+
output_file="$2"
9999

100-
if first_line_ends_crlf "$source_file"; then
100+
if first_line_ends_crlf "$input_file"; then
101101
endline=$'\r\n'
102102
else
103103
endline=$'\n'
104104
fi
105105

106-
make_header "$source_file" "$endline" |
107-
cat -- - "$source_file" >"$target_file"
106+
make_header "$input_file" "$endline" | cat -- - "$input_file" >"$output_file"
108107
}
109108

110109
function generate_one () {
111-
local source_file target_file
110+
local input_file output_file
112111

113-
source_file="$1"
114-
target_file="$destination_dir${source_file#"$source_dir"}"
112+
input_file="$1"
113+
output_file="$output_dir${input_file#"$input_dir"}"
115114

116-
if test -d "$source_file"; then
117-
mkdir -p -- "$target_file"
118-
elif test -L "$source_file"; then
115+
if test -d "$input_file"; then
116+
mkdir -p -- "$output_file"
117+
elif test -L "$input_file"; then
119118
# Cover this case separately, for more useful error messages.
120-
fail "source file is symbolic link: $source_file"
121-
elif ! test -f "$source_file"; then
119+
fail "input file is symbolic link: $input_file"
120+
elif ! test -f "$input_file"; then
122121
# This covers less common kinds of files we can't or shouldn't process.
123-
fail "source file neither regular file nor directory: $source_file"
124-
elif [[ "$source_file" =~ \.rs$ ]]; then
125-
copy_with_header "$source_file" "$target_file"
122+
fail "input file neither regular file nor directory: $input_file"
123+
elif [[ "$input_file" =~ \.rs$ ]]; then
124+
copy_with_header "$input_file" "$output_file"
126125
else
127-
fail "source file not named as Rust source code: $source_file"
126+
fail "input file not named as Rust source code: $input_file"
128127
fi
129128
}
130129

131130
function generate_all () {
132-
local source_file
131+
local input_file
133132

134-
if ! test -d "$source_dir"; then
135-
fail "no source directory: $source_dir"
133+
if ! test -d "$input_dir"; then
134+
fail "no input directory: $input_dir"
136135
fi
137-
if ! test -d "$destination_parent_dir"; then
138-
fail "no target parent directory: $destination_parent_dir"
136+
if ! test -d "$output_parent_dir"; then
137+
fail "no output parent directory: $output_parent_dir"
139138
fi
140-
check_destination_dir
139+
check_output_dir
141140

142-
rm -rf -- "$destination_dir" # It may be a directory, symlink, or regular file.
143-
if test -e "$destination_dir"; then
144-
fail 'unable to remove target location'
141+
rm -rf -- "$output_dir" # It may be a directory, symlink, or regular file.
142+
if test -e "$output_dir"; then
143+
fail 'unable to remove output location'
145144
fi
146145

147-
find "$source_dir" -print0 | while IFS= read -r -d '' source_file; do
148-
generate_one "$source_file"
146+
find "$input_dir" -print0 | while IFS= read -r -d '' input_file; do
147+
generate_one "$input_file"
149148
done
150149
}
151150

0 commit comments

Comments
 (0)