From 5da0337a0500257e93259472d26bca4ca9a6be9a Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Tue, 20 Jun 2006 00:24:50 -0300 Subject: Faster strip whitespace cleaning script From: Trent Piepho 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 Signed-off-by: Mauro Carvalho Chehab --- v4l/scripts/strip-trailing-whitespaces.sh | 56 +++++++++++++------------------ 1 file changed, 23 insertions(+), 33 deletions(-) (limited to 'v4l/scripts/strip-trailing-whitespaces.sh') 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 -- cgit v1.2.3 From 78d2d7a1fea8c058e3ffa9dae7b6f96c3491a7ac Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Thu, 22 Jun 2006 11:47:13 -0300 Subject: Adjust filenames in the strip whitespace script output From: Trent Piepho Before: --- Makefile +++ - 2006-06-20 22:16:36.320564000 -0700 Now: --- Makefile +++ Makefile patch handles both correctly, but diffstat will use the "+++" filename rather than the "---" filename, making diffstat output rather useless. Signed-off-by: Trent Piepho Signed-off-by: Mauro Carvalho Chehab --- v4l/scripts/strip-trailing-whitespaces.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'v4l/scripts/strip-trailing-whitespaces.sh') diff --git a/v4l/scripts/strip-trailing-whitespaces.sh b/v4l/scripts/strip-trailing-whitespaces.sh index 5bd7784e4..a546a0b9f 100755 --- a/v4l/scripts/strip-trailing-whitespaces.sh +++ b/v4l/scripts/strip-trailing-whitespaces.sh @@ -23,5 +23,6 @@ for file in `eval $files`; do 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}" - + print' < "${file}" | \ + diff -u --label="$file" "$file" --label="$file" - done -- cgit v1.2.3