Skip to content

Commit f13b017

Browse files
committed
get-sources: auto-convert .git repositories
A handful of packages are built from tags, branches or commits in Git repositories. The way Pacman works is to bundle the entire .git repository in the source packages for such components. This is not only wasteful, it also makes it a bit harder to inspect code. Let's just re-package the respective revisions into individual .zip packages. To make things super-convenient, also edit the PKGBUILD file so that it uses the re-packaged .zip file. Currently Git for Windows uses 10 components which are affected by this: crypt, git-flow, mingw-w64-git, mingw-w64-libtre-git, mingw-w64-rtmpdump-git, mingw-w64-winpthreads-git, mingw-w64-zlib, msys2-runtime, rebase, and ssh-pageant-git. All but one of these packages list the used Git repository as first source entry, mingw-w64-zlib being the exception: it lists the minizip Git repository as second entry (the first entry does not refer to a Git repository). Speaking of mingw-w64-zlib's first source entry: it is a URL. This is a bit of a bummer because the zlib-<version>.tar.gz file referenced by this URL is actually already included in the source package. Therefore, while we are in the vicinity anyway, also edit those URL entries in all PKGBUILD files to refer to the already-downloaded and included files instead. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 7e6648d commit f13b017

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

get-sources.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,62 @@ tar2zip () {
6161
rm -rf $unpackdir &&
6262
mkdir $unpackdir &&
6363
(cd $unpackdir && tar xzf -) <"$1" &&
64+
(cd $unpackdir/* &&
65+
bash -c 'source PKGBUILD &&
66+
repo= &&
67+
case "${source[0]}" in
68+
*::git*)
69+
repo="${source[0]%%::*}" &&
70+
trailer="${source[0]##*#}" &&
71+
case "$trailer" in
72+
tag=*) rev=refs/tags/${trailer#tag=};;
73+
branch=*) rev=refs/heads/${trailer#branch=};;
74+
commit=*) rev=${trailer#commit=};;
75+
"${source[0]}") rev=HEAD;;
76+
*) echo "Unhandled trailer: $trailer" >&2; exit 1;;
77+
esac &&
78+
if test HEAD = $rev
79+
then
80+
zip=$repo.zip
81+
else
82+
zip=$repo-${rev##*/}.zip
83+
fi &&
84+
sed -i -e "s/^source=[^)]*/source=(\"$zip\"/" \
85+
-e "s/^\( *\)git am \(--[^ ]* \)\?/\1patch -p1 </" \
86+
PKGBUILD
87+
;;
88+
http:*|https:*)
89+
sed -i "s/^\(source=(.\).*\/\([^)]*\)/\1\2/" PKGBUILD
90+
;;
91+
esac &&
92+
case "${source[1]}" in
93+
git+https:*.git)
94+
test -z "$repo" || {
95+
echo "Cannot handle *two* Git repos" >&2
96+
exit 1
97+
} &&
98+
repo="${source[1]##*/}" &&
99+
repo="${repo%.git}" &&
100+
rev=HEAD &&
101+
zip=$repo.zip &&
102+
sed -i -e "s/git+https:.*$repo.git/$repo.zip/" \
103+
-e "s/^\( *\)git am \(--[^ ]* \)\?/\1patch -p1 </" \
104+
PKGBUILD
105+
106+
;;
107+
esac &&
108+
if test -n "$repo"
109+
then
110+
echo "Converting $repo to $zip" &&
111+
if test git = $repo &&
112+
! git -C $repo rev-parse -q --verify $rev
113+
then
114+
git -C "$repo" fetch origin $rev:$rev
115+
fi &&
116+
git -C "$repo" archive --prefix="$repo/" --format=zip \
117+
"$rev" >"$zip" &&
118+
rm -rf "$repo"
119+
fi') &&
64120
(cd $unpackdir && zip -9qr - .) >"$2" ||
65121
die "Could not transmogrify $1 to $2"
66122
}

0 commit comments

Comments
 (0)