diff options
Diffstat (limited to 'bin')
-rw-r--r-- | bin/Makefile | 4 | ||||
-rwxr-xr-x | bin/convpatch | 44 | ||||
-rwxr-xr-x | bin/pkgdiffs | 10 | ||||
-rwxr-xr-x | bin/pkgpatch | 14 | ||||
-rwxr-xr-x | bin/pkgundo | 12 | ||||
-rwxr-xr-x | bin/psu | 12 | ||||
-rwxr-xr-x | bin/psx | 26 | ||||
-rwxr-xr-x | bin/savepatch | 36 | ||||
-rwxr-xr-x | bin/vipatch | 50 |
9 files changed, 208 insertions, 0 deletions
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 >/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 @@ -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 @@ -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 </dev/tty + case $ans in + y*) opt=-U ;; + *) exit 1 ;; + esac +fi + +echo extracting archive... 1>&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 </dev/tty +fi + +mkdir -p "$root/$dir" + +if [ -e "$root/$dir/$1" ]; then + printf "%s: %s already exists; overwrite? " "${0##*/}" "$dir/$1" 1>&2 + read ans </dev/tty + case $ans in + y*) ;; + *) exit 1 ;; + esac +fi + +cat > "$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; +} +' |