1
0
dotfiles/.config/zsh/alias/quilt.zsh

80 lines
1.7 KiB
Bash
Raw Normal View History

2024-01-27 00:10:58 +03:00
#!/bin/zsh
quilt-series-strip-comments() {
sed -E '/^[[:space:]]*(#|$)/d' "$@"
}
quilt-series-auto() {
2024-03-04 15:35:55 +03:00
[ -n "${1:?}" ]
2024-01-27 00:10:58 +03:00
find "$1/" -follow -type f -printf '%P\0' \
| sed -zEn '/\.(diff|patch)$/p' \
| sort -zuV | xargs -0r -n1
}
krd-quilt() {
2024-03-04 15:35:55 +03:00
(( $+commands[quilt] )) || return 127
2024-01-27 00:10:58 +03:00
2024-03-04 15:35:55 +03:00
[ -n "${1:?}" ]
2024-01-27 00:10:58 +03:00
local patchdir series tmp_series
if [ -d "$1" ] ; then
patchdir="$1/debian/patches"
if [ -d "${patchdir}" ] ; then
2024-03-04 15:35:55 +03:00
[ -f "${patchdir}/series" ] || return 1
2024-01-27 00:10:58 +03:00
else
patchdir="$1"
fi
series="${patchdir}/series"
if ! [ -f "${series}" ] ; then
tmp_series=1
series=$(mktemp)
quilt-series-auto "${patchdir}" > "${series}"
fi
elif [ -f "$1" ] ; then
2024-03-04 15:35:55 +03:00
[ -s "$1" ] || return 2
2024-01-27 00:10:58 +03:00
series="$1"
patchdir=${series:h}
else
return 3
fi
local r
(
z-quilt-default-env
set -a
QUILT_SERIES="${series}"
QUILT_PATCHES="${patchdir}"
set +a
command quilt pop -a ; echo
r=0
2024-03-04 15:35:55 +03:00
while read -rs i ; do
2024-01-27 00:10:58 +03:00
[ -n "$i" ] || continue
k="${patchdir}/$i"
command quilt --fuzz=0 push "$k"
r=$? ; [ $r -eq 0 ] || exit $r
command quilt refresh "$k"
r=$? ; [ $r -eq 0 ] || exit $r
sed -E -i \
-e 's#^(-{3} )[^/][^/]*/(.*)$#\1a/\2#;' \
-e 's#^(\+{3} )[^/][^/]*/(.*)$#\1b/\2#' \
"$k"
rm -f "$k"'~'
done <<< $(quilt-series-strip-comments "${series}")
exit $r
)
r=$?
[ -z "${tmp_series}" ] || rm -f "${series}"
return $r
}