fast-import: fix compilation on MinGW
[git/platforms.git] / cpio.sh
blob432903813bfd005c04e6f3a82d8b1fc5898f77dc
1 #!/bin/sh
3 # Emulates some cpio behavior using GNU tar
5 die() {
6 echo >&2 "$@"
7 exit 1
10 null=
12 while test $# -gt 0; do
13 case "$1" in
14 -0) null=--null;;
15 -o) mode=o;;
16 -iuv) ;;
17 -pumd|-pumdl)
18 mode=p
19 dir="$2"
20 shift
22 *) die "cpio emulation supports only -0, -o, -iuv, -pumdl";;
23 esac
24 shift
25 done
27 filterdirs() {
28 while read f; do
29 if test -d "$f"; then
30 # list only empty directories
31 if test -z "$(ls -A "$f")"; then
32 echo "$f"
34 else
35 echo "$f"
37 done
40 case $mode in
42 tar --create --file=- $null --files-from=-
45 test -z "$null" || die "cpio: cannot use -0 in pass-through mode"
46 filterdirs |
47 tr -d '\r' |
48 tar --create --file=- --files-from=- |
49 tar --extract --directory="$dir" --file=-
52 tar xvf -
53 esac