From 09c0720ee7f4d949f3f779bb26ccb60faad56cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Mon, 26 Jul 2021 19:32:37 +0200 Subject: Move patch utilities to bin/ --- Makefile | 4 ---- bin/Makefile | 4 ++++ bin/convpatch | 44 ++++++++++++++++++++++++++++++++++++++++++++ bin/pkgdiffs | 10 ++++++++++ bin/pkgpatch | 14 ++++++++++++++ bin/pkgundo | 12 ++++++++++++ bin/psu | 12 ++++++++++++ bin/psx | 26 ++++++++++++++++++++++++++ bin/savepatch | 36 ++++++++++++++++++++++++++++++++++++ bin/vipatch | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ convpatch | 44 -------------------------------------------- pkgdiffs | 10 ---------- pkgpatch | 14 -------------- pkgundo | 12 ------------ psu | 12 ------------ psx | 26 -------------------------- savepatch | 36 ------------------------------------ vipatch | 50 -------------------------------------------------- 18 files changed, 208 insertions(+), 208 deletions(-) delete mode 100644 Makefile create mode 100644 bin/Makefile create mode 100755 bin/convpatch create mode 100755 bin/pkgdiffs create mode 100755 bin/pkgpatch create mode 100755 bin/pkgundo create mode 100755 bin/psu create mode 100755 bin/psx create mode 100755 bin/savepatch create mode 100755 bin/vipatch delete mode 100755 convpatch delete mode 100755 pkgdiffs delete mode 100755 pkgpatch delete mode 100755 pkgundo delete mode 100755 psu delete mode 100755 psx delete mode 100755 savepatch delete mode 100755 vipatch diff --git a/Makefile b/Makefile deleted file mode 100644 index e6af53a..0000000 --- a/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -BIN != find . -type f -perm -111 -maxdepth 1 - -install: - install $(BIN) /usr/local/bin diff --git a/bin/Makefile b/bin/Makefile new file mode 100644 index 0000000..e6af53a --- /dev/null +++ b/bin/Makefile @@ -0,0 +1,4 @@ +BIN != find . -type f -perm -111 -maxdepth 1 + +install: + install $(BIN) /usr/local/bin diff --git a/bin/convpatch b/bin/convpatch new file mode 100755 index 0000000..2ebbcd8 --- /dev/null +++ b/bin/convpatch @@ -0,0 +1,44 @@ +#!/bin/sh -f + +# convpatch -- convert git diff -p output to pkgsrc patch + +IFS=' +' + +{ + echo '$NetBSD$' + echo + + # get patch description + if [ x"$1" = x"-i" ]; then + f=`mktemp -t ${0##*/}` || exit 1 + echo 'Edit patch description...' > $f + /dev/tty vi $f + c=`cat $f` + if [ x"$c" != x"Edit patch description..." ]; then + printf '%s\n\n' "$c" + fi + rm $f + fi + + sed ' + /^diff/d; + /^index/d; + s/^--- .*/&/; + ' +} | +while read -r line; do + case "$line" in + diff*) ;; + index*) ;; + '--- a/'*) + file=${line#--- a/} + echo -n "--- $file.orig " + file=$(git rev-parse --show-toplevel)/$file + echo "$(stat -x "$file")" | sed -n 's/^Access: //p' ;; + '+++ b/'*) + echo "+++ ${line#+++ b/}" ;; + *) + echo "$line" ;; + esac +done diff --git a/bin/pkgdiffs b/bin/pkgdiffs new file mode 100755 index 0000000..e39d5a0 --- /dev/null +++ b/bin/pkgdiffs @@ -0,0 +1,10 @@ +#!/bin/sh + +# pkgdiffs -- concatenate pkgdiffs + +[ x"$1" = "-a" ] || pkgdiff "${1%.orig}" +shift + +for f in "$@"; do + pkgdiff "${f%.orig}" | sed -n '2,$p' +done diff --git a/bin/pkgpatch b/bin/pkgpatch new file mode 100755 index 0000000..d59ea6a --- /dev/null +++ b/bin/pkgpatch @@ -0,0 +1,14 @@ +#!/bin/sh + +# pkgpatch -- patch, saving original files + +move() +{ + for orig in *.$1; do + mv -i "$orig" "${orig%.$1}".$2 + done +} + +move orig ~1~ +trap 'move ~1~ orig; trap -' INT QUIT TERM EXIT +patch -Vt -F3 "$@" diff --git a/bin/pkgundo b/bin/pkgundo new file mode 100755 index 0000000..9f3ad25 --- /dev/null +++ b/bin/pkgundo @@ -0,0 +1,12 @@ +#!/bin/sh + +# pkgundo -- restore original files + +[ $# -eq 0 ] && { echo "usage: ${0##*/} orig ..." 2>&1; exit 1; } + +n= +for orig in "$@"; do + : $((n++)) + mv "$orig" "${orig%.orig}" +done +echo "${0##*/}: moved $n files" 2>&1 diff --git a/bin/psu b/bin/psu new file mode 100755 index 0000000..a5ad636 --- /dev/null +++ b/bin/psu @@ -0,0 +1,12 @@ +#!/bin/sh -e + +# psu -- undo patches applied to pkgsrc build + +d=$(psx) || true +echo=echo +echo "${0##*/}: undoing patches..." 1>&2 +[ x"$1" = x"-x" ] && echo= || echo '(preview, no -x)' 1>&2 +find work -name '*.orig' | while read -r f; do + $echo cp "$d/${f#work/}" "${f%.orig}" + $echo rm "$f" +done diff --git a/bin/psx b/bin/psx new file mode 100755 index 0000000..1066c5f --- /dev/null +++ b/bin/psx @@ -0,0 +1,26 @@ +#!/bin/sh -e + +# psx -- fetch and extract pkgsrc archive + +case "$PWD" in +/usr/pkgsrc/*/*) ;; +*) echo "${0##*/}: not in package directory" 1>&2; exit 1 ;; +esac + +make fetch +f=/usr/pkgsrc/distfiles/$(sed -n '/.*(\(.*\)).*/{s//\1/;p;q}' distinfo) +d=$(tar -tf "$f" | head -1) + +opt= +if [ -e "$d" ]; then + printf "%s: $d already exists; overwrite? " "${0##*/}" 1>&2 + read ans &2 +tar -x $opt -f "$f" 1>&2 +echo "$d" diff --git a/bin/savepatch b/bin/savepatch new file mode 100755 index 0000000..f4c2bd6 --- /dev/null +++ b/bin/savepatch @@ -0,0 +1,36 @@ +#!/bin/sh + +# savepatch -- save patch on standard in to ~/patches + +root=/home/john/patches + +if [ -z "$1" ]; then + echo "usage: ${0##*/} patch-name" 1>&2 + exit 1 +fi + +case "$PWD" in +/usr/pkgsrc/*) dir=$(pwd | cut -d/ -f4,5) || dir= ;; +/usr/*src/*) dir=${PWD#/usr/} ;; +*) dir= +esac + +if [ -z "$dir" ]; then + echo "${0##*/}: could not determine package" 1>&2 + printf "package: " 1>&2 + read dir &2 + read ans "$root/$dir/$1" +echo "$root/$dir/$1" diff --git a/bin/vipatch b/bin/vipatch new file mode 100755 index 0000000..d860f93 --- /dev/null +++ b/bin/vipatch @@ -0,0 +1,50 @@ +#!/bin/sh + +# vipatch -- edit unified diff + +# This is a simple awk script that re-adjusts headers in +# a patch generated by diff -u, depending on the actual +# number of added/removed lines. + +ep | awk -vname=${0##*/} ' +/^@@ / { if (head) printpatch(); head = $0 "\n"; next } +head && /^---/ { print; next } +head && /^\+\+\+/ { print; next } +head && /^\+/ { plus++ } +head && /^-/ { minus++ } +head && /^ / { same++ } +head { body = body $0 "\n"; next } + { print } +END { if (head) printpatch() } + +function printpatch() { + match(head, /^@@ -[0-9]+,[0-9]+ \+[0-9]+,/) + prefix = substr(head, RSTART, RLENGTH) + + match(head, / @@.*/) + suffix = substr(head, RSTART, RLENGTH) + + match(head, /,[0-9]+/) + old = substr(head, RSTART+1, RLENGTH-1) + new = old + plus - minus + + diff = old - same - minus + if (diff != 0) { + printf "%s: %d %s incorrectly %s\n", name, abs(diff), + (abs(diff) > 1) ? "lines" : "line", + (diff > 0) ? "removed" : "added" > "/dev/stderr" + printf "under header%s\n", substr(suffix, 4) > "/dev/stderr" + head = "" + exit 1 + } + + printf "%s%d%s", prefix, new, suffix + printf "%s", body + + head = ""; body = ""; plus = 0; minus = 0; same = 0 +} + +function abs(n) { + return (n > 0) ? n : -n; +} +' diff --git a/convpatch b/convpatch deleted file mode 100755 index 2ebbcd8..0000000 --- a/convpatch +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh -f - -# convpatch -- convert git diff -p output to pkgsrc patch - -IFS=' -' - -{ - echo '$NetBSD$' - echo - - # get patch description - if [ x"$1" = x"-i" ]; then - f=`mktemp -t ${0##*/}` || exit 1 - echo 'Edit patch description...' > $f - /dev/tty vi $f - c=`cat $f` - if [ x"$c" != x"Edit patch description..." ]; then - printf '%s\n\n' "$c" - fi - rm $f - fi - - sed ' - /^diff/d; - /^index/d; - s/^--- .*/&/; - ' -} | -while read -r line; do - case "$line" in - diff*) ;; - index*) ;; - '--- a/'*) - file=${line#--- a/} - echo -n "--- $file.orig " - file=$(git rev-parse --show-toplevel)/$file - echo "$(stat -x "$file")" | sed -n 's/^Access: //p' ;; - '+++ b/'*) - echo "+++ ${line#+++ b/}" ;; - *) - echo "$line" ;; - esac -done diff --git a/pkgdiffs b/pkgdiffs deleted file mode 100755 index e39d5a0..0000000 --- a/pkgdiffs +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -# pkgdiffs -- concatenate pkgdiffs - -[ x"$1" = "-a" ] || pkgdiff "${1%.orig}" -shift - -for f in "$@"; do - pkgdiff "${f%.orig}" | sed -n '2,$p' -done diff --git a/pkgpatch b/pkgpatch deleted file mode 100755 index d59ea6a..0000000 --- a/pkgpatch +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -# pkgpatch -- patch, saving original files - -move() -{ - for orig in *.$1; do - mv -i "$orig" "${orig%.$1}".$2 - done -} - -move orig ~1~ -trap 'move ~1~ orig; trap -' INT QUIT TERM EXIT -patch -Vt -F3 "$@" diff --git a/pkgundo b/pkgundo deleted file mode 100755 index 9f3ad25..0000000 --- a/pkgundo +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -# pkgundo -- restore original files - -[ $# -eq 0 ] && { echo "usage: ${0##*/} orig ..." 2>&1; exit 1; } - -n= -for orig in "$@"; do - : $((n++)) - mv "$orig" "${orig%.orig}" -done -echo "${0##*/}: moved $n files" 2>&1 diff --git a/psu b/psu deleted file mode 100755 index a5ad636..0000000 --- a/psu +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -e - -# psu -- undo patches applied to pkgsrc build - -d=$(psx) || true -echo=echo -echo "${0##*/}: undoing patches..." 1>&2 -[ x"$1" = x"-x" ] && echo= || echo '(preview, no -x)' 1>&2 -find work -name '*.orig' | while read -r f; do - $echo cp "$d/${f#work/}" "${f%.orig}" - $echo rm "$f" -done diff --git a/psx b/psx deleted file mode 100755 index 1066c5f..0000000 --- a/psx +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -e - -# psx -- fetch and extract pkgsrc archive - -case "$PWD" in -/usr/pkgsrc/*/*) ;; -*) echo "${0##*/}: not in package directory" 1>&2; exit 1 ;; -esac - -make fetch -f=/usr/pkgsrc/distfiles/$(sed -n '/.*(\(.*\)).*/{s//\1/;p;q}' distinfo) -d=$(tar -tf "$f" | head -1) - -opt= -if [ -e "$d" ]; then - printf "%s: $d already exists; overwrite? " "${0##*/}" 1>&2 - read ans &2 -tar -x $opt -f "$f" 1>&2 -echo "$d" diff --git a/savepatch b/savepatch deleted file mode 100755 index f4c2bd6..0000000 --- a/savepatch +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh - -# savepatch -- save patch on standard in to ~/patches - -root=/home/john/patches - -if [ -z "$1" ]; then - echo "usage: ${0##*/} patch-name" 1>&2 - exit 1 -fi - -case "$PWD" in -/usr/pkgsrc/*) dir=$(pwd | cut -d/ -f4,5) || dir= ;; -/usr/*src/*) dir=${PWD#/usr/} ;; -*) dir= -esac - -if [ -z "$dir" ]; then - echo "${0##*/}: could not determine package" 1>&2 - printf "package: " 1>&2 - read dir &2 - read ans "$root/$dir/$1" -echo "$root/$dir/$1" diff --git a/vipatch b/vipatch deleted file mode 100755 index d860f93..0000000 --- a/vipatch +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/sh - -# vipatch -- edit unified diff - -# This is a simple awk script that re-adjusts headers in -# a patch generated by diff -u, depending on the actual -# number of added/removed lines. - -ep | awk -vname=${0##*/} ' -/^@@ / { if (head) printpatch(); head = $0 "\n"; next } -head && /^---/ { print; next } -head && /^\+\+\+/ { print; next } -head && /^\+/ { plus++ } -head && /^-/ { minus++ } -head && /^ / { same++ } -head { body = body $0 "\n"; next } - { print } -END { if (head) printpatch() } - -function printpatch() { - match(head, /^@@ -[0-9]+,[0-9]+ \+[0-9]+,/) - prefix = substr(head, RSTART, RLENGTH) - - match(head, / @@.*/) - suffix = substr(head, RSTART, RLENGTH) - - match(head, /,[0-9]+/) - old = substr(head, RSTART+1, RLENGTH-1) - new = old + plus - minus - - diff = old - same - minus - if (diff != 0) { - printf "%s: %d %s incorrectly %s\n", name, abs(diff), - (abs(diff) > 1) ? "lines" : "line", - (diff > 0) ? "removed" : "added" > "/dev/stderr" - printf "under header%s\n", substr(suffix, 4) > "/dev/stderr" - head = "" - exit 1 - } - - printf "%s%d%s", prefix, new, suffix - printf "%s", body - - head = ""; body = ""; plus = 0; minus = 0; same = 0 -} - -function abs(n) { - return (n > 0) ? n : -n; -} -' -- cgit v1.2.3