summaryrefslogtreecommitdiff
path: root/pbs-convert-absgit--filterarch
blob: 73fa96a2cb0774e6257cf01a458a889663c864b2 (plain)
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
#!/bin/bash -e
arch=$1

echo # newline
echo Preparing...

# generate map of all packages to their treehash
tree="$(mktemp)"
if [[ $arch = master ]]; then
	git ls-tree -d "$GIT_COMMIT" */trunk > "$tree"
else
	git ls-tree -d "$GIT_COMMIT" */repos/*-"$arch" */repos/*-any > "$tree"
fi

# generate map of all packages to their repo
repos="$(mktemp)"
printf '%s\n' */repos/*-"$arch" | sed -r 's@^([^/]*)/repos/(.*)-[^-]*$@\1 \2@' | sort -u > "$repos"

# clean the working directory
rm -rf *

# add the packages back in as remotes
count="$(wc -l < "$tree")"
cat -n "$tree" | while read n mode type treehash path; do
	printf '\r%s (%i/%i)' "$(gettext 'Adding package')" "$n" "$count"

	package="${path%%/*}"
	repo="$(sed -n "s/^${package} //p" "$repos")"
	commitfile="../packages-${package}.commits"
	if [[ -f "$commitfile" ]]; then
		commithash="$(sed -n "s/^${treehash} //p" "$commitfile")"
		mkdir -p "$repo"
		git submodule add ./ "${repo}/${package}"
		(
			cd "${repo}/${package}"
			git checkout "${commithash}"
		)
	else
		printf '%s\n' "$package" >> "${TMPDIR}/missing-packages/${arch}.tmp"
	fi
done
echo # newline

# clean up
rm -f "$repos" "$tree"