diff options
author | Taru Karttunen <taruti@taruti.net> | 2011-03-30 17:14:36 +0300 |
---|---|---|
committer | Taru Karttunen <taruti@taruti.net> | 2011-03-30 17:14:36 +0300 |
commit | 2959e1ede0ebc6fdffd7b8660f43c2ce14c9696f (patch) | |
tree | f6343b1ce11a8c87251dd27cf3d3e26b50693fa7 /rc/bin/patch | |
parent | e463eb40363ff4c68b1d903f4e0cdd0ac1c5977f (diff) | |
download | plan9front-2959e1ede0ebc6fdffd7b8660f43c2ce14c9696f.tar.xz |
Import sources from 2011-03-30 iso image - rc
Diffstat (limited to 'rc/bin/patch')
-rwxr-xr-x | rc/bin/patch/applied | 8 | ||||
-rwxr-xr-x | rc/bin/patch/apply | 79 | ||||
-rwxr-xr-x | rc/bin/patch/create | 85 | ||||
-rwxr-xr-x | rc/bin/patch/diff | 45 | ||||
-rwxr-xr-x | rc/bin/patch/list | 54 | ||||
-rwxr-xr-x | rc/bin/patch/move | 31 | ||||
-rwxr-xr-x | rc/bin/patch/note | 35 | ||||
-rwxr-xr-x | rc/bin/patch/notify | 9 | ||||
-rwxr-xr-x | rc/bin/patch/okay | 14 | ||||
-rwxr-xr-x | rc/bin/patch/remove | 19 | ||||
-rwxr-xr-x | rc/bin/patch/save | 8 | ||||
-rwxr-xr-x | rc/bin/patch/sorry | 8 | ||||
-rwxr-xr-x | rc/bin/patch/undo | 35 |
13 files changed, 430 insertions, 0 deletions
diff --git a/rc/bin/patch/applied b/rc/bin/patch/applied new file mode 100755 index 000000000..e4bb2a5cf --- /dev/null +++ b/rc/bin/patch/applied @@ -0,0 +1,8 @@ +#!/bin/rc + +if(~ $#* 0){ + echo 'usage: patch/applied patch-name...' >[1=2] + exit usage +} + +patch/move applied $* diff --git a/rc/bin/patch/apply b/rc/bin/patch/apply new file mode 100755 index 000000000..16b71c84a --- /dev/null +++ b/rc/bin/patch/apply @@ -0,0 +1,79 @@ +#!/bin/rc + +rfork e + +if(! ~ $#* 1){ + echo 'usage: patch/apply patch-name' >[1=2] + exit usage +} + +if(! test -d /n/sources/patch){ + rfork n + 9fs sources +} + +if(! test -d /n/sources/patch/$1){ + echo 'no such patch' /n/sources/patch/$1 >[1=2] + exit nopatch +} + +builtin cd /n/sources/patch/$1 || exit nopatch +if(! patch/okay .){ + echo 'bad patch: '$status >[1=2] + exit badpatch +} + +if(! echo >.tmp || ! rm .tmp){ + echo no write permission >[1=2] + exit 'no write permission' +} + +echo -n merge... >[1=2] +fn xxx { + if(! test -f $1) + cp $2 $2.new + if not + ape/diff3 -m $1 $2.orig $2 >$2.new + if(grep -s '^<<<<' $2.new){ + echo conflicts merging $1';' see `{pwd}^/$2.new >[1=2] + + touch failed + } +} +rm -f failed +cat files | sed 's/^/xxx /' | rc +if(test -f failed){ + echo exiting without changes >[1=2] + exit failed +} + +echo -n backup... >[1=2] +fn xxx { + # echo cp $1 $2.backup + cp $1 $2.backup +} +cat files | sed 's/^/xxx /' |rc + +echo -n copy... >[1=2] +fn xxx { + # echo cp $2.new $1 + cp $2.new $1 || touch failed +} +cat files | sed 's/^/xxx /' | rc + +fn xxx { + # echo cp $2.backup $1 + cp $2.backup $1 +} + +if(test -f failed){ + echo copying failed, restoring backups >[1=2] + cat files | sed 's/^/xxx /' | rc + exit failed +} + +echo >[1=2] + +echo to update sources: >[1=2] +cat files | awk '{print " update " $1 }' >[1=2] + diff --git a/rc/bin/patch/create b/rc/bin/patch/create new file mode 100755 index 000000000..55e659a00 --- /dev/null +++ b/rc/bin/patch/create @@ -0,0 +1,85 @@ +#!/bin/rc +rfork e + +fn xchmod { + chmod $* >[2]/dev/null +} + +if(~ $#* 0 1 2){ + echo 'usage: patch/create name email file... [< description]' >[1=2] + exit usage +} + +if(! echo $1 | grep -s '^[a-z_0-9.\-]+$'){ + echo 'bad name: [a-z0-9._\-]+ only' >[1=2] + exit usage +} +if(! echo $2 | grep -s '^(-|[A-Za-z0-9.\-+]+@[A-Za-z0-9.\-+]+)$'){ + echo 'bad email: [a-z0-9.-+] only; use ''-'' to not leave an email address.' >[1=2] + exit usage +} + +if(! test -d /n/sources/patch){ + rfork n + 9fs sources +} + +patch=$1 +email=$2 +shift +shift +d=/n/sources/patch/$patch +if(! mkdir $d){ + echo mkdir $d failed >[1=2] + exit mkdir +} +if(! ~ $email -){ + echo $email >$d/email +} + +xchmod o-w $d +>$d/readme +>$d/files +>$d/notes +for(i in $*){ + i=`{cleanname -d `{pwd} $i} + if(! test -f $i){ + echo error: cannot find $i >[1=2] + rm -rf $d + exit oops + } + short=`{basename $i} + uniq=$short + n=0 + while(test -f $d/$uniq){ + uniq=$short.$n + n=`{echo 1+$n | hoc} + } + cp $i $d/$uniq + if(test -f /n/sources/plan9/$i){ + if(cmp -s /n/sources/plan9/$i $i) + echo warning: new file $i does not differ from sources >[1=2] + cp /n/sources/plan9/$i $d/$uniq.orig + } + if not + echo warning: new file $i not on sources >[1=2] + echo $i $uniq >>$d/files +} +@{builtin cd $d && xchmod ug+rw * && xchmod a+r *} + +if(~ `{cat /proc/$pid/fd | awk 'NR==2{print $NF}'} */dev/cons && test -w /dev/consctl){ + >/dev/consctl { + echo holdon + cat >$d/readme + } +} +if not + cat >$d/readme + +if(! test -s $d/readme){ + echo 'no description given; aborting' >[1=2] + rm -rf $d + exit oops +} + +echo $d diff --git a/rc/bin/patch/diff b/rc/bin/patch/diff new file mode 100755 index 000000000..944b5231b --- /dev/null +++ b/rc/bin/patch/diff @@ -0,0 +1,45 @@ +#!/bin/rc +# patch/diff [-w] patch-name +rfork e +fn usage { + echo 'usage: patch/diff [-bmnwz] patch-name' >[1=2] + exit usage +} + +dopts=(-c) +while (! ~ $#* 0 && ~ $1 -*) { + switch ($1) { + case -[bmnw] + dopts=($dopts $1) + case -z + dopts=() + case * + usage + } + shift +} +if(! ~ $#* 1) + usage + +if(! test -d /n/sources/patch){ + rfork n + 9fs sources +} + +if(! test -d /n/sources/patch/$1){ + echo 'no such patch' /n/sources/patch/$1 >[1=2] + exit nopatch +} + +builtin cd /n/sources/patch/$1 || exit nopatch +if(! patch/okay .){ + echo 'bad patch: '$status >[1=2] + exit badpatch +} + +d=/n/sources/patch/$1 +fn xxx { + echo $1 + diff $dopts $2.orig $d/$2 | sed 's/^/ /' +} +cat files | sed 's/^/xxx /' | rc diff --git a/rc/bin/patch/list b/rc/bin/patch/list new file mode 100755 index 000000000..5bd2dfe24 --- /dev/null +++ b/rc/bin/patch/list @@ -0,0 +1,54 @@ +#!/bin/rc + +rfork e +if(! test -d /n/sources/patch){ + rfork n + 9fs sources +} + +pref='' +builtin cd /n/sources/patch || { + echo 'can''t cd /n/sources/patch' >[2=1] + exit no-sources +} + +if(~ $1 applied saved sorry maybe){ + pref=$1^'/' + shift +} +if(~ $#* 0) + *=(`{ + if(~ $pref *?*) + builtin cd $pref + ls -t | grep -v '^(applied|saved|sorry|maybe)$' + }) + +trunc=(sed 5q) +if(~ $#* 1) + trunc=cat + +{ +for(i in $*){ + i=$pref^$i + if(test -f $i/origls) + cat $i/origls | awk '{$NF="'$i'"; print}' + if not + ls -ld $i + if(patch/okay $i){ + if(test -r $i/email) + echo from `{cat $i/email} + cat $i/files | awk '{print " " $1}' + cat $i/readme | sed 's/^/ /' | $trunc + if(test -f $i/notes){ + echo + cat $i/notes + } + } + if not + echo ' 'bad patch: $status >[2=1] + echo +} +} >/tmp/patchtmp.$pid + +cat /tmp/patchtmp.$pid +rm -f /tmp/patchtmp.$pid diff --git a/rc/bin/patch/move b/rc/bin/patch/move new file mode 100755 index 000000000..60dfb952c --- /dev/null +++ b/rc/bin/patch/move @@ -0,0 +1,31 @@ +#!/bin/rc +# patch/move target patch-tree... - move patch tree(s) to target dir +rfork e +pats=/n/sources/patch +if(~ $#* 0 1){ + echo 'usage: patch/move dst patch-name...' >[1=2] + exit usage +} + +if(! test -d $pats){ + rfork n + 9fs sources +} +cd $pats + +dst=$1 +shift +for(src){ + patbase = `{basename $src} + patdest = $dst/$patbase + if (~ $dst $src $patbase) + echo $0: skipping $src >[1=2] + if not if(! test -d $src) + echo $0: no such patch $pats/$src >[1=2] + if not if(test -d $patdest) + echo $0: already have $pats/$patdest >[1=2] + if not + ls -ldp $src >$src/origls && + mkdir $patdest && dircp $src $patdest && rm -rf $src && + test -s $patdest/email && patch/notify $patdest +} diff --git a/rc/bin/patch/note b/rc/bin/patch/note new file mode 100755 index 000000000..858e2f63f --- /dev/null +++ b/rc/bin/patch/note @@ -0,0 +1,35 @@ +#!/bin/rc + +rfork e +if(! ~ $#* 1){ + echo 'usage: patch/note patch-name' >[1=2] + exit usage +} + +if(! test -d /n/sources/patch){ + rfork n + 9fs sources +} + +if(! test -d /n/sources/patch/$1){ + echo 'no such patch' /n/sources/patch/$1 >[1=2] + exit nopatch +} + +builtin cd /n/sources/patch/$1 || exit nopatch +if(! patch/okay .){ + echo 'bad patch: '$status >[1=2] + exit badpatch +} + +if(~ `{cat /proc/$pid/fd | awk 'NR==2{print $NF}'} */dev/cons && ~ `{ls -l /dev/consctl | awk '{print $1}'} *w*){ + >/dev/consctl { + echo holdon + {echo `{date} `{cat /dev/user} + cat |sed 's/^/ /'; echo } >>notes + } +} +if not + {echo `{date} `{cat /dev/user} + cat |sed 's/^/ /'; echo } >>notes + diff --git a/rc/bin/patch/notify b/rc/bin/patch/notify new file mode 100755 index 000000000..14c07169c --- /dev/null +++ b/rc/bin/patch/notify @@ -0,0 +1,9 @@ +#!/bin/rc +# patch/notify +rfork e +for(i) + # don't flood sys when merely shuffling patches around + if (~ $i applied/* saved/* sorry/*) { + patch/list $i | mail -s 'patch/list '^$i sys \ + `{cat /n/sources/patch/$i/email} + } diff --git a/rc/bin/patch/okay b/rc/bin/patch/okay new file mode 100755 index 000000000..df7813d50 --- /dev/null +++ b/rc/bin/patch/okay @@ -0,0 +1,14 @@ +#!/bin/rc + +rfork e +if(! ~ $#* 1){ + echo usage: patch/okay dir >[1=2] + exit usage +} + +i=$1 +if(! test -s $i/files || ! test -s $i/readme) + exit 'missing files' +if(grep -v '^/[_a-zA-Z0-9.\-+/:]+ [_a-zA-Z0-9.\-+:]+$' $i/files) + exit 'bad file list' +exit 0 diff --git a/rc/bin/patch/remove b/rc/bin/patch/remove new file mode 100755 index 000000000..94a91f8f0 --- /dev/null +++ b/rc/bin/patch/remove @@ -0,0 +1,19 @@ +#!/bin/rc + +rfork e +if(~ $#* 0){ + echo 'usage: patch/remove patch-name...' >[1=2] + exit usage +} + +if(! test -d /n/sources/patch){ + rfork n + 9fs sources +} + +for(i){ + if(! test -d /n/sources/patch/$i) + echo 'no such patch' /n/sources/patch/$i >[1=2] + if not + rm -rf /n/sources/patch/$i +} diff --git a/rc/bin/patch/save b/rc/bin/patch/save new file mode 100755 index 000000000..ffec9d8b9 --- /dev/null +++ b/rc/bin/patch/save @@ -0,0 +1,8 @@ +#!/bin/rc + +if(~ $#* 0){ + echo 'usage: patch/save patch-name...' >[1=2] + exit usage +} + +patch/move saved $* diff --git a/rc/bin/patch/sorry b/rc/bin/patch/sorry new file mode 100755 index 000000000..5f0930c22 --- /dev/null +++ b/rc/bin/patch/sorry @@ -0,0 +1,8 @@ +#!/bin/rc + +if(~ $#* 0){ + echo 'usage: patch/sorry patch-name...' >[1=2] + exit usage +} + +patch/move sorry $* diff --git a/rc/bin/patch/undo b/rc/bin/patch/undo new file mode 100755 index 000000000..177c24ab1 --- /dev/null +++ b/rc/bin/patch/undo @@ -0,0 +1,35 @@ +#!/bin/rc + +rfork e +if(! ~ $#* 1){ + echo 'usage: patch/undo patch-name' >[1=2] + exit usage +} + +if(! test -d /n/sources/patch){ + rfork n + 9fs sources +} + +if(! test -d /n/sources/patch/$1){ + echo 'no such patch' /n/sources/patch/$1 >[1=2] + exit nopatch +} + +d=$1 +builtin cd /n/sources/patch/$1 || exit nopatch +if(! patch/okay .){ + echo 'bad patch: '$status >[1=2] + exit badpatch +} + +fn xxx { + if(cmp $2.new $1){ + echo cp /n/sources/patch/$d/$2.backup $1 + cp $2.backup $1 + } + if not + echo $1 has changed since patch was applied! >[2=1] +} +cat files | sed 's/^/xxx /' |rc + |