summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@infradead.org>2006-06-20 00:24:50 -0300
committerMauro Carvalho Chehab <mchehab@infradead.org>2006-06-20 00:24:50 -0300
commit5da0337a0500257e93259472d26bca4ca9a6be9a (patch)
tree62c63cfeda86174f02331f33e951917104e92b73
parentd02b60987a9d04d3f7a58c04c1000797b8563b92 (diff)
downloadmediapointer-dvb-s2-5da0337a0500257e93259472d26bca4ca9a6be9a.tar.gz
mediapointer-dvb-s2-5da0337a0500257e93259472d26bca4ca9a6be9a.tar.bz2
Faster strip whitespace cleaning script
From: Trent Piepho <xyzzy@speakeasy.org> Faster script that doesn't use any temporary files. The old one would also miss cleaning four spaces in a row in places where it would clean one to eight spaces. Has two options: fast Only clean whitespace in files Hg thinks are modified or added. Used by make whitespace and much (about 100x) faster. manifest Clean all files controlled by Hg, using "hg manifest" The default with no options is the old behaviour, clean all files under the linux directory, except CVS files. Signed-off-by: Trent Piepho <xyzzy@speakeasy.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
-rw-r--r--Makefile2
-rwxr-xr-xv4l/scripts/strip-trailing-whitespaces.sh56
2 files changed, 24 insertions, 34 deletions
diff --git a/Makefile b/Makefile
index 1f11bcb3f..42c22f72a 100644
--- a/Makefile
+++ b/Makefile
@@ -43,5 +43,5 @@ push::
whitespace:
@echo "Cleaning bad whitespaces"
- @v4l/scripts/strip-trailing-whitespaces.sh | patch -p0
+ @v4l/scripts/strip-trailing-whitespaces.sh fast | patch -p0
diff --git a/v4l/scripts/strip-trailing-whitespaces.sh b/v4l/scripts/strip-trailing-whitespaces.sh
index 1a23e436d..5bd7784e4 100755
--- a/v4l/scripts/strip-trailing-whitespaces.sh
+++ b/v4l/scripts/strip-trailing-whitespaces.sh
@@ -1,37 +1,27 @@
#!/bin/sh
+# Strips trailing whitespace. Leading spaces and spaces after tabs are
+# converted to the equivalent sequence of tabs only.
-# tmp dir for my files
-WORK="${TMPDIR-/tmp}/${0##*/}-$$"
-mkdir "$WORK" || exit 1
-trap 'rm -rf "$WORK"' EXIT
+# Use the option "fast" to only check files Hg thinks are new or modified.
+# The option "manifest" will use Hg's manifest command to check all files
+# under Hg revision control.
+# Otherwise, all files under the linux tree are checked, except files in CVS
+# directories and .cvsignore files. This is the historical behavior.
-for file in `find linux -type d | grep -v CVS | grep -v .cvsignore` ; do
- mkdir -p "$WORK/${file}"
-done
-for file in `find linux -type f | grep -v CVS | grep -v .cvsignore` ; do
- tmpfile="$WORK/${file}.$$"
- perl -ne 's/[ \t]+$//;
- s/^\ \ \ \ \ \ \ \ /\t/;
- s/^\ \ \ \ \ \ \ \t/\t/;
- s/^\ \ \ \ \ \ \t/\t/;
- s/^\ \ \ \ \ \t/\t/;
- s/^\ \ \ \t/\t/;
- s/^\ \ \t/\t/;
- s/^\ \t/\t/;
- $m=1;
- while ($m>0) {
- $m=0;
- $m= s/\t\ \ \ \ \ \ \ \ /\t\t/g;
- $m=$m+s/\t\ \ \ \ \ \ \ \t/\t\t/g;
- $m=$m+s/\t\ \ \ \ \ \ \t/\t\t/g;
- $m=$m+s/\t\ \ \ \ \ \t/\t\t/g;
- $m=$m+s/\t\ \ \ \t/\t\t/g;
- $m=$m+s/\t\ \ \t/\t\t/g;
- $m=$m+s/\t\ \t/\t\t/g;
- }
- print' < "${file}" > "${tmpfile}"
- diff -u "${file}" "${tmpfile}" | sed \
- -e "s|^--- ${file}|--- ${file}.orig|" \
- -e "s|^+++ ${tmpfile}|+++ ${file}|"
- rm -f "$tmpfile"
+
+if [ "x$1" = "xfast" ]; then
+ files="hg status -man"
+elif [ "x$1" = "xmanifest" ]; then
+ files="hg manifest | cut '-d ' -f3"
+else
+ files="find linux -name CVS -prune -o -type f -not -name .cvsignore -print"
+fi
+
+for file in `eval $files`; do
+ perl -ne '
+ s/[ \t]+$//;
+ s<^ {8}> <\t>;
+ s<^ {1,7}\t> <\t>;
+ while( s<\t {8}> <\t\t>g || s<\t {1,7}\t> <\t\t>g ) {};
+ print' < "${file}" | diff -u "${file}" -
done