]> git.neil.brown.name Git - wiggle.git/commitdiff
Still more updates to 'p' origin
authorNeil Brown <neilb@suse.de>
Sun, 21 May 2006 23:34:17 +0000 (09:34 +1000)
committerNeil Brown <neilb@suse.de>
Sun, 21 May 2006 23:34:17 +0000 (09:34 +1000)
p

diff --git a/p b/p
index 06de4abb23b9a4f52d0a09023be6d5f5425d7ccb..41660001e2a7747951ef313176af1b4c0786d7a4 100755 (executable)
--- a/p
+++ b/p
@@ -183,8 +183,7 @@ commit_one()
 
 discard_one()
 {
-       rm -f "$1"
-       cp "$1~current~" $1
+       cmp -s "$1~current~" $1 || { rm -f "$1" ; cp "$1~current~" $1; }
        chmod u+w $1
 }
 
@@ -234,7 +233,8 @@ save_patch()
 find_prefix()
 {
        # set "prefix" to number for -pn by looking at first file in given patch.
-       file=`lsdiff $1 | head -1`
+       n=${2-1}
+       file=`lsdiff $1 | head -$n | tail -1`
        orig=$file
        prefix=0
        while [ \( -n "$file" -a ! -f "$file" \) -o " $file" != " ${file#/}" ]
@@ -243,7 +243,11 @@ find_prefix()
            prefix=`expr $prefix + 1`
        done
        if [ -z "$file" ]
-       then echo "Cannot find $orig" >&2 ; exit 1;
+       then echo "Cannot find $orig" >&2 
+          if [ $n -gt 4 ]
+          then exit 2;
+          else find_prefix "$1" $[n+1]
+          fi
        fi
        if [ " $orig" != " $file" ]
        then