Skip to content

Commit

Permalink
More updates to 'p'
Browse files Browse the repository at this point in the history
  • Loading branch information
neilbrown committed May 21, 2006
1 parent 0a8ebda commit c162347
Showing 1 changed file with 144 additions and 26 deletions.
170 changes: 144 additions & 26 deletions p
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ get_meta()

forget_one()
{
if cmp -s "$1" "$1~current~" && cmp -s "$1" "$1~orig~"
if true # || cmp -s "$1" "$1~current~" && cmp -s "$1" "$1~orig~"
then
rm -f "$1~current~" "$1~orig~"
chmod -w "$1"
Expand Down Expand Up @@ -140,7 +140,7 @@ all_files()
{
>> .patches/files
while read file
do eval $1 $file
do eval $1 $file $2
done < .patches/files
}

Expand All @@ -151,7 +151,12 @@ diff_one()
else
echo
echo "diff ./$1~current~ ./$1"
diff -N --show-c-function -u ./$1~current~ ./$1
if [ " $2" = " -R" ]
then
diff -N --show-c-function -u ./$1 ./$1~current~
else
diff -N --show-c-function -u ./$1~current~ ./$1
fi
fi
}

Expand Down Expand Up @@ -190,7 +195,7 @@ swap_one()
mv "$1.tmp" "$1~current~"
}

CERT='Signed-off-by: Neil Brown <neilb@cse.unsw.edu.au>'
CERT='Signed-off-by: Neil Brown <neilb@suse.de>'
make_diff()
{
{
Expand All @@ -201,7 +206,7 @@ make_diff()
else echo "$CERT"
fi
echo
all_files diff_one > .patches/tmp
all_files diff_one $1 > .patches/tmp
echo "### Diffstat output"
diffstat -p0 2> /dev/null < .patches/tmp
cat .patches/tmp
Expand All @@ -225,7 +230,7 @@ save_patch()
new=${new#1}
mv .patches/patch $dir/$new$name
}

find_prefix()
{
# set "prefix" to number for -pn by looking at first file in given patch.
Expand Down Expand Up @@ -253,7 +258,7 @@ extract_notes()
awk '
BEGIN { head= 1; blanks=0 ; }
head == 1 && ( $1 == "Status:" || $0 == "" ) {
next;
next;
}
{ head = 0; }
$0 == "" { blanks++; next; }
Expand Down Expand Up @@ -312,15 +317,20 @@ case $cmd in
if [ ! -f "$pfile" ]
then echo >&2 "Cannot find unique patch '$1' - found: $pfile"; exit 1;
fi
${PAGER-less} $pfile;
if grep -s '^+.*[ ]$' $pfile > /dev/null
then
${PAGER-less -p '^\+.*[ ]$'} $pfile
else
${PAGER-less} $pfile
fi
;;

all )
all_files diff_one_orig
;;
status | name )
case $# in
1 )
1 )
get_meta
if [ $cmd = name ] ; then
if [ -n "$name" ]; then
Expand Down Expand Up @@ -359,6 +369,11 @@ case $cmd in
if [ -s .patches/patch ]
then :
else echo >&2 No patch to $cmd ; exit 1
fi
if grep -s '^+.*[ ]$' .patches/patch > /dev/null
then
echo >&2 remove trailing spaces/tabs first !!
# exit 1
fi
if [ -s .patches/to-resolv ]
then echo "Please resolve outstanding conflicts first with 'p resolve'"
Expand Down Expand Up @@ -420,7 +435,7 @@ case $cmd in
make_diff
get_meta
if [ -s .patches/patch ]
then
then
echo >&2 Patch $name already open - please commit; exit 1;
fi
if [ $# -eq 0 ]
Expand Down Expand Up @@ -481,7 +496,7 @@ case $cmd in
*/* ) echo >&2 "Only local patches can have been included"; exit 1 ;;
*) pfile=`echo .patches/removed/*$1*`
esac
if [ ! -f "$pfile" ]
if [ ! -f "$pfile" ]
then echo >&2 "Cannot find unique patch '$1' - found $pfile"; exit 1
fi
echo "Using $pfile..."
Expand All @@ -498,6 +513,99 @@ case $cmd in
save_patch included $name
echo "Moved to $new$name"
;;
review )
# there are some patches in .removed that may be included in the current source
# we try to backout each one. If it backs out successfully, we move it to
# .reviewed and conitnue, else we abort
# Once this has been done often enough, 'reviewed' should be run to
# move stuff to 'included' and to revert those patches
force=
if [ " $1" = " -f" ] ; then
force=yes; shift
fi
make_diff; get_meta
if [ -s .patches/path ]
then
echo >&2 Patch $name already open, please deal with it; exit 1;
fi
if [ $# -eq 0 ]
then
echo "Pending patches are:"
ls .patches/removed
exit 0;
fi
if [ $# -ne 1 ]
then
echo >&2 "Usage: p review patchname"; exit 1
fi
case $1 in
*/* ) echo >&2 "Only local patches can have been included"; exit 1 ;;
*) pfile=`echo .patches/removed/*$1*`
esac
if [ ! -f "$pfile" ]
then echo >&2 "Cannot find unique patch '$1' - found $pfile"; exit 1
fi
echo "Starting from $pfile..."
found=
for fl in .patches/removed/*
do
if [ " $fl" = " $pfile" ]; then found=yes ; fi
if [ -n "$found" ]; then
echo Checking $fl
find_prefix "$fl"
lsdiff --strip=$prefix "$fl" | grep -v 'file.*changed' | while read a b
do check_out $a
done
if patch -s --fuzz=0 --dry-run -f -p$prefix -R < "$fl"
then echo Looks good..
elif [ -n "$force" ]
then echo "It doesn't backout cleanly, but you asked for it..."
cp $fl .patches/last-backed
else echo "Patch won't back out, sorry"
exit 1
fi
patch --fuzz=0 -f -p$prefix -R < "$fl" | tee .patches/tmp
sed -n -e '2q' -e 's/^Status: *//p' $fl > .patches/status
base=${fl##*/}
base=${base##[0-9][0-9][0-9]}
base=${base##patch-?-}
[ -s .patches/name ] || echo $base > .patches/name
extract_notes $fl >> .patches/notes
rm -f .patches/wiggled
sed -n -e 's/.*saving rejects to file \(.*\).rej/\1/p' .patches/tmp |
while read file
do echo Wiggling $file.rej into place
rm -f $file.porig
> .patches/wiggled
wiggle --replace --merge $file $file.rej ||
echo $file >> .patches/to-resolve
done

mv $fl .patches/patch
save_patch reviewed $base
if [ -f .patches/wiggled ]
then echo 'Some wiggling was needed. Please review and commit'
exit 0
fi
p commit || exit 1
fi
done
;;

reviewed )
# all the currently applied patches are patches that have been
# reviewed as included.
# rip them out and stick them (reversed) into included.
while p open last
do
make_diff -R
get_meta
save_patch included "$name"
echo Saved as "$new$name"
all_files discard_one
rm -f .patches/name .patches/status .patches/notes
done
;;
list )
echo "Applied patches are:"
ls .patches/applied
Expand Down Expand Up @@ -538,7 +646,7 @@ case $cmd in
then echo >&2 "Cannot find unique patch '$1' - found: $pfile"; exit 1
fi
find_prefix "$pfile"
lsdiff --strip=$prefix "$pfile" | grep -v 'file.*changed' | while read a b
lsdiff --strip=$prefix "$pfile" | grep -v 'file.*changed' | while read a b
do check_out $a
done
# lets see if it applies cleanly
Expand Down Expand Up @@ -588,7 +696,7 @@ case $cmd in
if [ -f .patches/get-version ] ;
then ./.patches/get-version > $target/version
fi
[ -f .config ] && cp .config $target
[ -f .config ] && cp .config $target
cp .patches/applied/* $target
mkdir $target/misc
cp 2> /dev/null .patches/removed/* $target/misc || rmdir $target/misc
Expand Down Expand Up @@ -691,7 +799,7 @@ case $cmd in
make_diff
get_meta
if [ -s .patches/patch ]
then
then
echo >&2 Patch $name already open - please commit; exit 1;
fi
p openall && p clean &&
Expand Down Expand Up @@ -733,21 +841,25 @@ case $cmd in
if [ $cnt -gt 1 ]
then
{
cat .patches/owner
if [ -s .patches/owner.$1 ] ; then
cat .patches/owner.$1
else
cat .patches/owner
fi
echo "To: `cat .patches/maintainer`"
if [ -s .patches/cc ] ; then
while read word prefix addr
do if [ " $word" = " $1" ] ; then
echo "Cc: $addr"
sprefix="$prefix "
echo "Cc: $addr"
sprefix="$prefix: "
fi
done < .patches/cc
fi
if [ $cnt = 1 ]
then
echo "Subject: [PATCH] $sprefix Intro"
echo "Subject: [PATCH] ${sprefix}Intro"
else
echo "Subject: [PATCH ${sprefix}0 of $cnt] Introduction"
echo "Subject: [PATCH 000 of $cnt] ${sprefix}Introduction"
fi
echo "Message-ID: $messid"
echo
Expand All @@ -763,22 +875,27 @@ case $cmd in
if [ -n "$3" ] && [ $3 -lt $n ] ; then continue; fi
{
sprefix=
cat .patches/owner
if [ -s .patches/owner.$1 ] ; then
cat .patches/owner.$1
else
cat .patches/owner
fi
echo "To: `cat .patches/maintainer`"
if [ -s .patches/cc ] ; then
while read word prefix addr
do if [ " $word" = " $1" ] ; then
echo "Cc: $addr"
sprefix="$prefix "
echo "Cc: $addr"
sprefix="$prefix: "
fi
done < .patches/cc
fi
head=`sed -e '/^Status/d' -e '/^$/d' -e q $patch`
zerothis=$(expr $this + 1000)
if [ $cnt = 1 ]
then
echo "Subject: [PATCH $sprefix] $head"
echo "Subject: [PATCH] $sprefix$head"
else
echo "Subject: [PATCH $sprefix$this of $cnt] $head"
echo "Subject: [PATCH ${zerothis#1} of $cnt] $sprefix$head"
fi
echo "References: $messid"
echo
Expand All @@ -789,6 +906,7 @@ case $cmd in
} > .patches/mail/${patch#.patches/applied/}
this=$(expr $this + 1)
done
if [ -f .patches/mail/000Intro ]; then cat .patches/mail/* | sed -n -e 's/^Subject://p' >> .patches/mail/000Intro ; fi
ls .patches/mail
;;

Expand All @@ -798,7 +916,7 @@ case $cmd in
;;

email )
PATH=/usr/lib:/usr/sbin:$PATH
PATH=$HOME/bin:/usr/lib:/usr/sbin:$PATH
for i in .patches/mail/*
do
if [ -f "$i" ]
Expand Down

0 comments on commit c162347

Please sign in to comment.