summaryrefslogtreecommitdiffstats
path: root/dts/scripts/flatten-symlinks.sh
blob: 84d007f40f34c7df0326bafd4d734f2771a8b22d (plain) (blame)
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
#!/bin/bash

set -e

while read mode object stage path ; do
    case "$mode" in
	120000)
	    # symbolic link
	    deref=$(echo $GIT_COMMIT:$path | git cat-file --batch-check='deref-ok %(objectname)' --follow-symlinks)
	    case "$deref" in
		deref-ok*)
		    echo -e "100644 ${deref#deref-ok } $stage\t$path"
		    ;;
		dangling*) # skip
		    ;;
		*) # the rest, missing etc
		    echo >&2 "Failed to parse symlink $GIT_COMMIT:$path $deref"
		    exit 1
		    ;;
	    esac
	    ;;
	100*)
	    # Regular file, just pass through
	    echo -e "$mode $object $stage\t$path"
	    ;;
	*)
	    echo >&2 "Unhandled ls-tree entry: $line"
	    exit 1
	    ;;
    esac
done