Status: dontknow

Stuff.


Signed-off-by: Neil Brown <neilb@suse.de>

### Diffstat output
 ./merge2.c |   20 ++++---
 ./p        |  170 +++++++++++++++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 156 insertions(+), 34 deletions(-)

diff ./merge2.c~current~ ./merge2.c
--- ./merge2.c~current~	2005-03-08 12:35:57.000000000 +1100
+++ ./merge2.c	2005-03-08 13:13:03.000000000 +1100
@@ -116,7 +116,7 @@ inline int isolate_conflicts(struct file
 					m[j].in_conflict = 1;
 					m[j].lo = 0;
 				}
-				if (m[j].type == Unchanged) {
+				if (m[j].type == Unchanged || m[j].type == Changed) {
 					if (words) {
 						m[j].hi = m[j].al;
 						break;
@@ -145,7 +145,7 @@ inline int isolate_conflicts(struct file
 			/* now the forward search */
 			for (j=i+1; m[j].type != End; j++) {
 				m[j].in_conflict = 1;
-				if (m[j].type == Unchanged) {
+				if (m[j].type == Unchanged || m[j].type == Changed) {
 					m[j].hi = m[j].al;
 					if (words) {
 						m[j].lo = 0;
@@ -347,7 +347,10 @@ struct ci print_merge2(FILE *out, struct
 			 */
 			int st = m->hi;
 
-			printrange(out, a, m->a+m->lo, m->hi - m->lo);
+			if (m->type == Unchanged)
+				printrange(out, a, m->a+m->lo, m->hi - m->lo);
+			else
+				printrange(out, c, m->c, m->cl);
 
 #if 1
 		if (v)
@@ -370,7 +373,7 @@ struct ci print_merge2(FILE *out, struct
 
 			fputs(words?"<<<---":"<<<<<<<\n", out);
 			for (cm=m; cm->in_conflict; cm++) {
-				if (cm->type == Unchanged && cm != m && cm->lo < cm->hi) {
+				if ((cm->type == Unchanged || cm->type == Changed) && cm != m && cm->lo < cm->hi) {
 					printrange(out, a, cm->a, cm->lo);
 					break;
 				}
@@ -380,7 +383,7 @@ struct ci print_merge2(FILE *out, struct
 			fputs(words?"|||":"|||||||\n", out);
 			st = m->hi;
 			for (cm=m; cm->in_conflict; cm++) {
-				if (cm->type == Unchanged && cm != m && cm->lo < cm->hi) {
+				if ((cm->type == Unchanged || cm->type == Changed) && cm != m && cm->lo < cm->hi) {
 					printrange(out, b, cm->b, cm->lo);
 					break;
 				}
@@ -390,8 +393,9 @@ struct ci print_merge2(FILE *out, struct
 			fputs(words?"===":"=======\n", out);
 			st = m->hi;
 			for (cm=m; cm->in_conflict; cm++) {
-				if (cm->type == Unchanged && cm != m && cm->lo < cm->hi) {
-					printrange(out, c, cm->c, cm->lo);
+				if ((cm->type == Unchanged || cm->type == Changed) && cm != m && cm->lo < cm->hi) {
+					if (cm->type == Unchanged)
+						printrange(out, c, cm->c, cm->lo);
 					break;
 				}
 				printrange(out, c, cm->c+st, cm->cl-st);
@@ -399,7 +403,7 @@ struct ci print_merge2(FILE *out, struct
 			}
 			fputs(words?"--->>>":">>>>>>>\n", out);
 			m = cm;
-			if (m->in_conflict && m->hi >= m->al) {
+			if (m->type == Unchanged && m->in_conflict && m->hi >= m->al) {
 				printrange(out, a, m->a+m->lo, m->hi-m->lo);
 				m++;
 			}

diff ./p~current~ ./p
--- ./p~current~	2005-02-24 10:35:56.000000000 +1100
+++ ./p	2006-02-10 12:57:09.000000000 +1100
@@ -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"
@@ -140,7 +140,7 @@ all_files()
 {
         >> .patches/files
 	while read file
-	do eval $1 $file
+	do eval $1 $file $2
 	done < .patches/files
 }
 
@@ -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
 }
 
@@ -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()
 {
    {
@@ -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
@@ -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.
@@ -253,7 +258,7 @@ extract_notes()
  awk '
     BEGIN { head= 1; blanks=0 ; }
     head == 1 && ( $1 == "Status:" || $0 == "" ) {
-	    next; 
+	    next;
     }
     { head = 0; }
     $0 == "" { blanks++; next; }
@@ -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
@@ -360,6 +370,11 @@ case $cmd in
 	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'"
 	    exit 1
@@ -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 ]
@@ -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..."
@@ -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
@@ -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
@@ -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
@@ -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 &&
@@ -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
@@ -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
@@ -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
 	;;
 
@@ -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" ]
