-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-textconv-dvc.sh
executable file
·78 lines (73 loc) · 1.78 KB
/
git-textconv-dvc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
set -e
err() {
echo "$0: $*" >&2
}
# err "$# args:"
# for arg in "$@"; do
# err " $arg"
# done
# err
dvc_path=
if [ $# -eq 1 ]; then
dvc_path="$1"; shift
dvc_path_name="$(basename "$dvc_path")"
if ! [ -s "$dvc_path" ]; then
err "Error: $dvc_path_name not found"
exit 0
fi
md5="$(dvc_to_md5 "$dvc_path")"
path="${dvc_path%.dvc}"
name="$(basename "$path")"
blob_path="$(dvc_mdf_cache_path -r "$md5")"
if [ -z "$blob_path" ]; then
err "Error: $dvc_path_name blob path not found"
exit 0
fi
if ! [ -s "$blob_path" ]; then
err "Error: $dvc_path_name blob $blob_path ($md5) not found"
exit 0
fi
if [[ $md5 = *.dir ]]; then
cat "$dvc_path"
jq -r '.[] | [.relpath, .md5] | join(" ")' "$blob_path" | \
if which parallel &>/dev/null; then
parallel -k --colsep ' ' "$0" "\$(basename "$path/"'{1}'"")" "\$(dvc_mdf_cache_path -r {2})"
else
while read -r rel m; do
rel="$path/$rel"
f="$(dvc_mdf_cache_path -r "$m")"
n="$(basename "$rel")"
# err "Recursing: $rel $f"
"$0" "$n" "$f"
done
fi
exit 0
fi
elif [ $# -eq 2 ]; then
name="$1"; shift
blob_path="$1"; shift
else
err "Usage: $0 <dvc_path>"
err "Usage: $0 <basename> <blob_path>"
exit 1
fi
if [ -n "$dvc_path" ]; then
cat "$dvc_path"
fi
echo
echo "$name" "$blob_path"
diff_driver=$(git check-attr diff "$name" | sed -E 's/.*: diff: (.*)/\1/')
if [ "$diff_driver" != "unset" ] && [ "$diff_driver" != "unspecified" ]; then
textconv_cmd="$(git config "diff.${diff_driver}.textconv" || true)"
if [ -n "$textconv_cmd" ]; then
$textconv_cmd "$blob_path"
exit $?
fi
fi
if file -b --mime-encoding "$blob_path" | grep -q binary; then
echo "Binary file: $blob_path"
exit 0
else
cat "$blob_path"
fi