Compare commits

...

20 commits

Author SHA1 Message Date
ptrcnull 53441cb0fb fix: allow for using busybox grep 2022-07-30 09:25:54 +02:00
ptrcnull 8efb7c51b1 fix: print correct patch filename in 'failed to apply' error 2022-07-30 09:22:01 +02:00
ptrcnull 0ca9d1c380 fix: create header file manually to avoid mode 600 2022-07-30 07:55:18 +02:00
ptrcnull 24a42cdb5b fix: unset any functions set by apkbuild 2022-07-30 07:54:57 +02:00
ptrcnull aeae707886 fix: work around trailing newlines in headers
ugh
2022-07-30 06:18:01 +02:00
ptrcnull 4c668b6c04 fix: don't use $patch as the original patch 2022-07-30 06:10:25 +02:00
ptrcnull f80c534323 fix: don't exit when shell exits with errors
some shells keep exit code of the last executed process on ^D
2022-07-30 02:40:13 +02:00
ptrcnull 4e824d06f5 feat: even more fancy log messages 2022-07-30 02:40:01 +02:00
ptrcnull a85bf4c080 feat: keep original patch headers 2022-07-30 02:39:32 +02:00
ptrcnull 833280f1a9 feat: better log messages 2022-07-30 02:32:11 +02:00
ptrcnull 00d7fdace6 fix: exit on errors correctly 2022-07-30 02:28:33 +02:00
ptrcnull d1ccf0e1d4 feat: announce the wiggling 2022-07-25 07:43:52 +02:00
ptrcnull fbaf178502 fix: please show more info when patch doesn't apply 2022-07-25 07:42:34 +02:00
ptrcnull 42e63a4a56 feat: use git repo instead of arbitrary directories and busybox diff 2022-07-25 07:17:38 +02:00
ptrcnull 5710359960 chore: add .editorconfig 2022-07-25 07:06:29 +02:00
psykose 662ed43b24
don't destroy patch on failure to unpack/prepare 2022-05-22 18:44:16 +02:00
psykose dc90ce1d1b
fix: remove files in patch diff
closes #3
2022-05-02 17:15:27 +02:00
psykose 9a6ac8303b
fix: ensure src-old is always removed on exit 2022-04-29 08:56:03 +02:00
psykose 131c15e715
feat: improve patch updating 2022-04-29 08:56:03 +02:00
psykose a065129fdb
feat: allow updating a patch 2022-04-29 08:24:06 +02:00
2 changed files with 116 additions and 10 deletions

5
.editorconfig Normal file
View file

@ -0,0 +1,5 @@
root = true
[*]
indent_style = space
indent_size = 2

121
apatch Normal file → Executable file
View file

@ -1,19 +1,120 @@
#!/bin/sh
[ -f APKBUILD ] || ( echo "please run this in a package directory"; exit 1 )
[ ! -f "$1" ] || ( echo "patch $1 already exists"; exit 1 )
[ "$1" != "" ] || ( echo "usage: apatch <patch name>"; exit 1 )
# output functions from abuild/functions.sh
NORMAL="\033[1;0m"
STRONG="\033[1;1m"
RED="\033[1;31m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
BLUE="\033[1;34m"
abuild clean fetch unpack prepare
_prefix="${BLUE}${STRONG}apatch${NORMAL}:"
msg() {
local prompt="$GREEN>>> ${_prefix}"
printf "${prompt} %s\n" "$1" >&2
}
warning() {
local prompt="${YELLOW}>>> WARNING: ${_prefix}"
printf "${prompt} %s\n" "$1" >&2
}
error() {
local prompt="${RED}>>> ERROR: ${_prefix}"
printf "${prompt} %s\n" "$1" >&2
}
if [ ! -f APKBUILD ]; then
error "please run this in a package directory"
exit 1
fi
if [ "$1" == "" ]; then
echo "usage: apatch <patch name>"
exit 1
fi
set -e
msg "running abuild"
abuild clean fetch unpack default_prepare
# obtain builddir
startdir="$PWD"
srcdir="$startdir/src"
. APKBUILD
[ -z "$builddir" ] && builddir="/$pkgname-$pkgver"
unset -f grep cut head git rm mv
[ -n "$builddir" ] || builddir="$srcdir/$pkgname-$pkgver"
patchpath="$startdir/$1"
for patch in $source; do
if [ "$patch" = "$1" ]; then
# if the patch was in source, it was already applied in prepare() above,
# but we want the original src to not have it, so we can get a full diff of
# its original changes + our new ones
(
msg "reversing $patch"
cd "$builddir"
patch -R -p1 < "$patchpath"
)
break
fi
done
header=""
if [ -f "$patchpath" ]; then
msg "patch exists, trying to extract existing message"
# try to extract the original header from the patch
patch_start=$(grep -En '^(diff --git|--- )' "$patchpath" | cut -d: -f1 | head -n 1)
header_file="/tmp/$(mktemp -u apatch.XXXXXX)"
head -n $(( patch_start - 1 )) "$patchpath" > "$header_file"
fi
cp -r src src-old
(
cd "src$builddir"
$SHELL
cd "$builddir"
git init
git add .
git commit -m "$pkgver" >/dev/null
# if file exists, try to apply
if [ -e "$patchpath" ]; then
git apply --reject --whitespace=fix "$patchpath" || {
rejects="$(git status --porcelain | grep -F '??' | grep -F '.rej' | cut -c4-)"
if [ -n "$rejects" ]; then
warning "$1 partially applied with rejects"
for reject in $rejects; do
target="${reject%.rej}"
msg "trying to wiggle $target"
wiggle --merge --replace "$target" "$reject" || {
warning "could not merge $target, fix manually"
}
rm "$reject"
rm "$target.porig" # left by wiggle
done
else
warning "$1 failed to apply"
fi
}
fi
msg "you can edit now!"
$SHELL || true
git add .
msg "saving patch $1"
echo -n > "$patchpath" # empty the file first
if [ -n "$header_file" ]; then
mv "$header_file" "$patchpath"
fi
git diff --cached >> "$patchpath"
if [ ! -s "$patchpath" ]; then
msg "patch is empty, removing"
rm "$patchpath"
fi
rm -rf .git
)
busybox diff -U3 -r "src-old$builddir" "src$builddir" | sed "s|src-old$builddir|a|g;s|src$builddir|b|g" > $1
rm -rf src-old