2
2
3
3
set -euC -o pipefail
4
4
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"
8
8
9
9
function fail () {
10
10
printf ' %s: error: %s\n' " $0 " " $1 " >&2
@@ -14,7 +14,7 @@ function fail () {
14
14
function chdir_toplevel () {
15
15
local root_padded root
16
16
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.)
18
18
root_padded=" $( git rev-parse --show-toplevel && echo -n .) " ||
19
19
fail ' git-rev-parse failed to find top-level dir'
20
20
root=" ${root_padded% $' \n .' } "
@@ -25,38 +25,38 @@ function chdir_toplevel () {
25
25
function merging () {
26
26
local git_dir_padded git_dir
27
27
28
- # Find the .git directory. (Padding is for the trailing-newline case.)
28
+ # Find the .git directory. (Padding covers the trailing-newline case.)
29
29
git_dir_padded=" $( git rev-parse --git-dir && echo -n .) " ||
30
30
fail ' git-rev-parse failed to find git dir'
31
31
git_dir=" ${git_dir_padded% $' \n .' } "
32
32
33
33
test -e " $git_dir /MERGE_HEAD"
34
34
}
35
35
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 " ||
38
38
fail ' git-status failed'
39
39
}
40
40
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.
44
44
return
45
45
fi
46
46
47
47
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'
51
51
fi
52
52
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
56
56
# staged symlink or regular file with an unstaged directory is shown by
57
57
# 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'
60
60
fi
61
61
fi
62
62
}
@@ -81,71 +81,70 @@ function first_line_ends_crlf () {
81
81
}
82
82
83
83
function make_header () {
84
- local source_file endline
84
+ local input_file endline
85
85
86
- source_file =" $1 "
86
+ input_file =" $1 "
87
87
endline=" $2 "
88
88
89
89
# shellcheck disable=SC2016 # The backticks are intentionally literal.
90
90
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 "
92
92
}
93
93
94
94
function copy_with_header () {
95
- local source_file target_file endline
95
+ local input_file output_file endline
96
96
97
- source_file =" $1 "
98
- target_file =" $2 "
97
+ input_file =" $1 "
98
+ output_file =" $2 "
99
99
100
- if first_line_ends_crlf " $source_file " ; then
100
+ if first_line_ends_crlf " $input_file " ; then
101
101
endline=$' \r\n '
102
102
else
103
103
endline=$' \n '
104
104
fi
105
105
106
- make_header " $source_file " " $endline " |
107
- cat -- - " $source_file " > " $target_file "
106
+ make_header " $input_file " " $endline " | cat -- - " $input_file " > " $output_file "
108
107
}
109
108
110
109
function generate_one () {
111
- local source_file target_file
110
+ local input_file output_file
112
111
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 " }"
115
114
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
119
118
# 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
122
121
# 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 "
126
125
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 "
128
127
fi
129
128
}
130
129
131
130
function generate_all () {
132
- local source_file
131
+ local input_file
133
132
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 "
136
135
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 "
139
138
fi
140
- check_destination_dir
139
+ check_output_dir
141
140
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'
145
144
fi
146
145
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 "
149
148
done
150
149
}
151
150
0 commit comments