[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Quilt-dev] trailing whitespace
From: |
Andreas Gruenbacher |
Subject: |
Re: [Quilt-dev] trailing whitespace |
Date: |
Fri, 29 Apr 2005 08:06:59 +0200 |
User-agent: |
KMail/1.7.1 |
On Friday 29 April 2005 01:26, Andrew Morton wrote:
> I think it would be good if quilt were to warn users when their patches add
> trailing whitespace. It's a silly thing to do.
Agreed.
> In patch-scripts I run this during `refpatch'
>
> check_patch()
> {
> if grep "^+.*[ ]$" $P/patches/$(stripit $1).patch
> then
> echo warning: $1 adds trailing whitespace
> fi
> }
So you also print the offending lines -- I'd rather not. How about adding a
--strip-whitespace option to the refresh command? Those who want can then
also add it to .quiltrc.
Index: quilt/refresh.in
===================================================================
--- quilt/refresh.in
+++ quilt/refresh.in
@@ -72,7 +72,8 @@
exit $status
}
-options=`getopt -o p:uU:cC:fh --long no-timestamps,diffstat,backup,sort --
"$@"`
+options=`getopt -o p:uU:cC:fh --long no-timestamps,diffstat,backup,sort \
+ --long strip-trailing-whitespace -- "$@"`
if [ $? -ne 0 ]
then
@@ -111,6 +112,9 @@
--sort)
opt_sort=1
shift ;;
+ --strip-trailing-whitespace)
+ opt_strip_whitespace=1
+ shift ;;
--)
shift
break ;;
@@ -201,6 +205,21 @@
die 1
fi
+# Check for trailing whitespace
+if grep -q '^+.*[ \t]$' $tmp_patch
+then
+ if [ -n "$opt_strip_whitespace" ]
+ then
+ tmp=$(gen_tempfile)
+ sed -e '/^+/s/[ '$'\t'']*$//' $tmp_patch > $tmp
+ cat $tmp > $tmp_patch
+ rm -f $tmp
+ else
+ printf $"Warning: %s adds trailing whitespace\n" \
+ "$(print_patch $patch)"
+ fi
+fi
+
patch_file=$(patch_file_name $patch)
trap "" SIGINT
Index: test/trailing-ws.test
===================================================================
--- /dev/null
+++ test/trailing-ws.test
@@ -0,0 +1,25 @@
+ $ mkdir d
+ $ cd d
+
+ $ echo a > a
+ $ quilt new test.diff
+ > Patch patches/test.diff is now on top
+
+ $ quilt add a
+ > File a added to patch patches/test.diff
+
+ $ echo "a " > a
+ $ quilt refresh
+ > Warning: patches/test.diff adds trailing whitespace
+ > Refreshed patch patches/test.diff
+
+ $ grep '[ \t]$' patches/test.diff
+ > +a
+
+ $ quilt refresh --strip-trailing-whitespace
+ > Refreshed patch patches/test.diff
+
+ $ grep '[ \t]$' patches/test.diff
+
+ $ cd ..
+ $ rm -rf d
Cheers,
--
Andreas Gruenbacher <address@hidden>
SUSE Labs, SUSE LINUX PRODUCTS GMBH