feat: use git repo instead of arbitrary directories and busybox diff #9

Merged
ptrcnull merged 1 commit from wow-git-repo into master 2022-07-25 05:23:53 +00:00
Showing only changes of commit 42e63a4a56 - Show all commits

51
apatch
View file

@ -1,23 +1,21 @@
#!/bin/sh #!/bin/sh
cleanup() {
rm -rf src-old
}
trap 'cleanup' EXIT INT HUP
startdir="$PWD" startdir="$PWD"
[ -f APKBUILD ] || ( echo "please run this in a package directory"; exit 1 ) [ -f APKBUILD ] || ( echo "please run this in a package directory"; exit 1 )
[ "$1" != "" ] || ( echo "usage: apatch <patch name>"; exit 1 ) [ "$1" != "" ] || ( echo "usage: apatch <patch name>"; exit 1 )
abuild clean fetch unpack prepare || exit 1 set -e
abuild clean fetch unpack default_prepare
# obtain builddir # obtain builddir
startdir="$PWD"
srcdir="$startdir/src"
. APKBUILD . APKBUILD
[ -z "$builddir" ] && builddir="/$pkgname-$pkgver" test -n "$builddir" || builddir="$srcdir/$pkgname-$pkgver"
cp -r src src-old patchpath="$startdir/$1"
for patch in $source; do for patch in $source; do
if [ "$patch" = "$1" ]; then if [ "$patch" = "$1" ]; then
@ -25,16 +23,39 @@ for patch in $source; do
# but we want the original src to not have it, so we can get a full diff of # but we want the original src to not have it, so we can get a full diff of
# its original changes + our new ones # its original changes + our new ones
( (
cd "src-old/$builddir" cd "$builddir"
patch -R -p1 < "$startdir/$1" patch -R -p1 < "$patchpath"
) )
break break
fi fi
done done
( (
cd "src$builddir" cd "$builddir"
$SHELL git init
) git add .
git commit -m "$pkgver" >/dev/null
busybox diff -N -U3 -r "src-old$builddir" "src$builddir" | sed "s|src-old$builddir|a|g;s|src$builddir|b|g" > $1 # if file exists, try to apply
if [ -e "$patchpath" ]; then
git apply --reject --quiet --whitespace=fix "$patchpath" || {
git status --porcelain | grep '\?\? .*\.rej$' | cut -c4- | while read -r reject; do
target="${reject%.rej}"
wiggle --merge --replace "$target" "$reject" || {
echo "[!] could not merge $target, fix manually"
ptrcnull marked this conversation as resolved
Review

spaces are evil, use tabs

spaces are evil, use tabs
Review

yes i love you too darling

yes i love you too darling
}
rm "$reject"
rm "$target.porig" # left by wiggle
done
}
ptrcnull marked this conversation as resolved Outdated

wat

wat
fi
$SHELL
git add .
git diff --cached > "$patchpath"
if [ ! -s "$patchpath" ]; then
echo "[*] patch is empty, removing"
rm "$patchpath"
fi
)