contrib/diffall: eliminate duplicate while loops
There were 3 instances of a 'while read; do' that used identical logic to populate '/tmp/right_dir'. This commit groups them into a single loop. Signed-off-by: Tim Henigan <tim.henigan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Tim Henigan committed
Mar 14, 2012 at 12:38 UTC
97549084f660c43fe4b6dc34bf60afef4948b432
1 file changed
+9
-15
contrib/diffall/git-diffall
+9
-15
@@ -179,38 +179,32 @@ fi
179
mkdir -p "$tmp/$left_dir" "$tmp/$right_dir"
180
181
# Populate the tmp/right_dir directory with the files to be compared
182
-if test -n "$right"
183
-then
184
- while read name
185
- do
182
+while read name
183
+do
184
+ if test -n "$right"
185
+ then
186
ls_list=$(git ls-tree $right "$name")
187
if test -n "$ls_list"
188
then
189
mkdir -p "$tmp/$right_dir/$(dirname "$name")"
190
git show "$right":"$name" >"$tmp/$right_dir/$name" || true
191
fi
192
- done < "$tmp/filelist"
193
-elif test -n "$compare_staged"
194
-then
195
- while read name
196
- do
192
+ elif test -n "$compare_staged"
193
+ then
194
ls_list=$(git ls-files -- "$name")
195
if test -n "$ls_list"
196
then
197
mkdir -p "$tmp/$right_dir/$(dirname "$name")"
198
git show :"$name" >"$tmp/$right_dir/$name"
199
fi
203
- done < "$tmp/filelist"
204
-else
205
- while read name
206
- do
200
+ else
201
if test -e "$name"
202
then
203
mkdir -p "$tmp/$right_dir/$(dirname "$name")"
204
cp "$name" "$tmp/$right_dir/$name"
205
fi
212
- done < "$tmp/filelist"
213
-fi
206
+ fi
207
+done < "$tmp/filelist"
208
209
# Populate the tmp/left_dir directory with the files to be compared
210
while read name