diff options
author | Andreas Gruenbacher <agruen@suse.de> | 2005-06-18 18:03:57 +0000 |
---|---|---|
committer | Andreas Gruenbacher <agruen@suse.de> | 2005-06-18 18:03:57 +0000 |
commit | 31a5851d6372712fa6bafd4a6081f21ecee1c570 (patch) | |
tree | af8dbbacc1dfadd0423f1b443b93f037de2b0b9e | |
parent | 442b3debff33d2d0f13214abf42bd53525557ff9 (diff) | |
download | quilt-31a5851d6372712fa6bafd4a6081f21ecee1c570.tar.gz |
- Add fix for refresh --strip-trailing-whitespace option: now
refresh always checks for trailing whitespace and reports it
per file and line number. With --strip-trailing-whitespace it
strips the whitespace from the patch and from the affected files
in the working tree.
-rw-r--r-- | Makefile.in | 3 | ||||
-rw-r--r-- | doc/.cvsignore | 2 | ||||
-rw-r--r-- | po/de.po | 15 | ||||
-rw-r--r-- | po/fr.po | 15 | ||||
-rw-r--r-- | po/ja.po | 15 | ||||
-rw-r--r-- | po/quilt.pot | 13 | ||||
-rw-r--r-- | quilt.changes | 9 | ||||
-rw-r--r-- | quilt/refresh.in | 24 | ||||
-rw-r--r-- | scripts/.cvsignore | 1 | ||||
-rw-r--r-- | scripts/remove-trailing-ws.in | 112 | ||||
-rw-r--r-- | test/trailing-ws.test | 62 |
11 files changed, 230 insertions, 41 deletions
diff --git a/Makefile.in b/Makefile.in index d174f0a..e99f33d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -65,7 +65,8 @@ QUILT := $(QUILT_IN) SRC += $(QUILT_SRC:%=quilt/%) DIRT += $(QUILT_IN:%=quilt/%) -SCRIPTS_IN := patchfns parse-patch inspect dependency-graph edmail +SCRIPTS_IN := patchfns parse-patch inspect dependency-graph edmail \ + remove-trailing-ws SCRIPTS_SRC := $(SCRIPTS_IN:%=%.in) SCRIPTS := $(SCRIPTS_IN) SRC += $(SCRIPTS_SRC:%=scripts/%) diff --git a/doc/.cvsignore b/doc/.cvsignore index b5c3d34..fca2547 100644 --- a/doc/.cvsignore +++ b/doc/.cvsignore @@ -1 +1 @@ -quilt.1 quilt.dvi quilt.ps README main.aux main.log +quilt.1 quilt.dvi quilt.ps README quilt.aux quilt.log @@ -951,19 +951,20 @@ msgstr "" "Später angewandte Patches verändern Dateien von $patch. Auffrischen mit -f " "erzwingen.\\n" -#: ../quilt/refresh.in:214 +#: ../quilt/refresh.in:213 +msgid "" +"Cannot use --strip-trailing-whitespace on a patch that has shadowed files.\\n" +msgstr "" + +#: ../quilt/refresh.in:219 msgid "Nothing in patch %s\\n" msgstr "Patch %s is leer\\n" -#: ../quilt/refresh.in:228 -msgid "Warning: %s adds trailing whitespace\\n" -msgstr "" - -#: ../quilt/refresh.in:290 +#: ../quilt/refresh.in:296 msgid "Patch %s is unchanged\\n" msgstr "Patch %s ist unverändert\\n" -#: ../quilt/refresh.in:295 +#: ../quilt/refresh.in:301 msgid "Refreshed patch %s\\n" msgstr "Patch %s aufgefrischt\\n" @@ -915,19 +915,20 @@ msgstr "" "Des fichiers plus rcents modifient les mmes fichiers que %s.\n" "Forcez le rafrachissement avec -f.\\n" -#: ../quilt/refresh.in:214 +#: ../quilt/refresh.in:213 +msgid "" +"Cannot use --strip-trailing-whitespace on a patch that has shadowed files.\\n" +msgstr "" + +#: ../quilt/refresh.in:219 msgid "Nothing in patch %s\\n" msgstr "Le patch %s ne contient rien\\n" -#: ../quilt/refresh.in:228 -msgid "Warning: %s adds trailing whitespace\\n" -msgstr "" - -#: ../quilt/refresh.in:290 +#: ../quilt/refresh.in:296 msgid "Patch %s is unchanged\\n" msgstr "Le patch %s n'a pas t modifi\\n" -#: ../quilt/refresh.in:295 +#: ../quilt/refresh.in:301 msgid "Refreshed patch %s\\n" msgstr "Le patch %s a t rafraichi.\\n" @@ -942,19 +942,20 @@ msgstr "" "より最近のパッチがパッチ %sのファイルに変更を加えています。リフレッシュを実行" "する場合は -f オプションを使用してください。\\n" -#: ../quilt/refresh.in:214 +#: ../quilt/refresh.in:213 +msgid "" +"Cannot use --strip-trailing-whitespace on a patch that has shadowed files.\\n" +msgstr "" + +#: ../quilt/refresh.in:219 msgid "Nothing in patch %s\\n" msgstr "パッチ %s にはなにも含まれていません\\n" -#: ../quilt/refresh.in:228 -msgid "Warning: %s adds trailing whitespace\\n" -msgstr "" - -#: ../quilt/refresh.in:290 +#: ../quilt/refresh.in:296 msgid "Patch %s is unchanged\\n" msgstr "パッチ % に変更はありません\\n" -#: ../quilt/refresh.in:295 +#: ../quilt/refresh.in:301 msgid "Refreshed patch %s\\n" msgstr "パッチ %s をリフレッシュしました\\n" diff --git a/po/quilt.pot b/po/quilt.pot index 9b3df87..d221b81 100644 --- a/po/quilt.pot +++ b/po/quilt.pot @@ -669,19 +669,20 @@ msgid "" "More recent patches modify files in patch %s. Enforce refresh with -f.\\n" msgstr "" -#: ../quilt/refresh.in:214 -msgid "Nothing in patch %s\\n" +#: ../quilt/refresh.in:213 +msgid "" +"Cannot use --strip-trailing-whitespace on a patch that has shadowed files.\\n" msgstr "" -#: ../quilt/refresh.in:228 -msgid "Warning: %s adds trailing whitespace\\n" +#: ../quilt/refresh.in:219 +msgid "Nothing in patch %s\\n" msgstr "" -#: ../quilt/refresh.in:290 +#: ../quilt/refresh.in:296 msgid "Patch %s is unchanged\\n" msgstr "" -#: ../quilt/refresh.in:295 +#: ../quilt/refresh.in:301 msgid "Refreshed patch %s\\n" msgstr "" diff --git a/quilt.changes b/quilt.changes index 9e851e8..514adeb 100644 --- a/quilt.changes +++ b/quilt.changes @@ -1,4 +1,13 @@ ------------------------------------------------------------------- +Sat Jun 18 19:51:36 CEST 2005 - agruen@suse.de + +- Add fix for refresh --strip-trailing-whitespace option: now + refresh always checks for trailing whitespace and reports it + per file and line number. With --strip-trailing-whitespace it + strips the whitespace from the patch and from the affected files + in the working tree. + +------------------------------------------------------------------- Sat Jun 18 15:03:13 CEST 2005 - agruen@suse.de - Add new annotate command. diff --git a/quilt/refresh.in b/quilt/refresh.in index 4cbb8dd..2bf70e0 100644 --- a/quilt/refresh.in +++ b/quilt/refresh.in @@ -207,6 +207,11 @@ do printf $"More recent patches modify files in patch %s. Enforce refresh with -f.\n" "$(print_patch $patch)" >&2 die 1 fi + + if [ -n "$files_were_shadowed" -a -n "$opt_strip_whitespace" ] + then + printf $"Cannot use --strip-trailing-whitespace on a patch that has shadowed files.\n" >&2 + fi done if ! [ -s $tmp_patch ] @@ -216,19 +221,20 @@ then fi # Check for trailing whitespace -if grep -q '^+.*[ '$'\t'']$' $tmp_patch +if [ -z "$opt_strip_whitespace" ] then - if [ -n "$opt_strip_whitespace" ] + @SCRIPTS@/remove-trailing-ws -n -p$opt_strip_level \ + < $tmp_patch +else + tmp_patch2=$(gen_tempfile) + if @SCRIPTS@/remove-trailing-ws -p$opt_strip_level \ + < $tmp_patch > $tmp_patch2 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)" + rm -f $tmp_patch + tmp_patch=$tmp_patch2 fi fi +# FIXME: no stripping of non-topmost patch !!! patch_file=$(patch_file_name $patch) diff --git a/scripts/.cvsignore b/scripts/.cvsignore index c1afe90..4ab2912 100644 --- a/scripts/.cvsignore +++ b/scripts/.cvsignore @@ -5,3 +5,4 @@ inspect parse-patch patchfns rpatch +remove-trailing-ws diff --git a/scripts/remove-trailing-ws.in b/scripts/remove-trailing-ws.in new file mode 100644 index 0000000..f14de5d --- /dev/null +++ b/scripts/remove-trailing-ws.in @@ -0,0 +1,112 @@ +#! @PERL@ -w + +# Remove trailing whitespace from modified lines in working files. +# +# Input: diff between original and working files (unified or context +# format). + +use strict; +use FileHandle; +use File::Temp qw( :mktemp ); +use Getopt::Std; +use vars qw($opt_p $opt_n); + +$opt_p = 0; +getopts('np:') + or die "SYNOPSIS: $0 [-p num] [-n] [patch]\n"; + +my %files; +my $file; +while (<>) { + print unless $opt_n; + if (/^--- ./) { + # unified diff + while (<>) { + print unless $opt_n; + if (/^\+\+\+ (.+?)(?:[ \t][^\t]*)?$/) { + $file = $1; + $file =~ s<^([^/]+/+){$opt_p}><>; + #print STDERR "[$file]\n"; + } elsif ($file && /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/) { + my $removed = defined $2 ? $2 : 1; + my $added = defined $4 ? $4 : 1; + my $line_number = $3; + + while ($removed || $added) { + $_ = <>; + defined $_ + or die "$0: I'm confused.\n"; + if (/^\+/) { + push @{$files{$file}}, $line_number + if s/(^\+.*?)[ \t]+$/$1/; + $added--; + $line_number++; + } elsif (/^-/) { + $removed--; + } elsif (/^ / || /^$/) { + $removed--; + $added--; + $line_number++; + } + print unless $opt_n; + } + } + } + } elsif (/^\*\*\* ./) { + # context diff + while (<>) { + print unless $opt_n; + if ($file && /^--- (\d+)(?:,(\d+))? ----$/) { + my $line_number = $1; + my $last_line = defined $2 ? $2 : $1; + while ($line_number <= $last_line) { + $_ = <>; + defined $_ + or die "$0: I'm confused.\n"; + if (s/(^[+!] .*?)[ \t]+$/$1/) { + push @{$files{$file}}, $line_number; + } + $line_number++; + print unless $opt_n; + last if (/^\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*$/); + } + } elsif (/^--- (.+?)(?:[ \t][^\t]*)?$/) { + $file = $1; + $file =~ s<^([^/]+/+){$opt_p}><>; + #print STDERR "[$file]\n"; + } + } + } +} + +foreach my $file (keys %files) { + my @lines = @{$files{$file}}; + if ($opt_n) { + print STDERR "Warning: trailing whitespace in line"; + } else { + print STDERR "Removing trailing whitespace from line"; + } + print STDERR "s" if @lines > 1; + print STDERR " " . join(',', @lines) . " of $file\n"; + + unless ($opt_n) { + my $fh = new FileHandle("< $file") + or die "$file: $!\n"; + my ($tmp, $tmpname) = mkstemp("$file.XXXXXX") + or die "$file.XXXXXX: $!\n"; + while (<$fh>) { + if (@lines && $lines[0] == $.) { + s/[ \t]+$//; + shift @lines; + } + print $tmp $_; + } + $fh->close; + $tmp->close + or die "$tmpname: $!\n"; + rename $tmpname, $file + or die "Renaming $tmpname to $file: $!\n"; + } +} + +#exit (%files ? 1 : 0); diff --git a/test/trailing-ws.test b/test/trailing-ws.test index 4d63a4b..2053062 100644 --- a/test/trailing-ws.test +++ b/test/trailing-ws.test @@ -1,25 +1,81 @@ $ mkdir d $ cd d - $ echo a > a + $ cat > a + < a + < b + < c + $ 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 + $ cat > a + < a + < b + < c + $ quilt refresh - > Warning: patches/test.diff adds trailing whitespace + > Warning: trailing whitespace in lines 1,3 of a > Refreshed patch patches/test.diff $ grep '[ \t]$' patches/test.diff > +a + > +c + + $ quilt refresh -U0 + > Warning: trailing whitespace in lines 1,3 of a + > Refreshed patch patches/test.diff $ quilt refresh --strip-trailing-whitespace + > Removing trailing whitespace from lines 1,3 of a > Refreshed patch patches/test.diff $ grep '[ \t]$' patches/test.diff + $ quilt pop -q + > Removing patch patches/test.diff + > No patches applied + + $ cat > a + < a + < b + < c + + $ quilt new test2.diff + > Patch patches/test2.diff is now on top + + $ quilt add a + > File a added to patch patches/test2.diff + + $ cat > a + < a + < b + < c + + $ quilt refresh -c + > Warning: trailing whitespace in lines 1,3 of a + > Refreshed patch patches/test2.diff + + $ grep '[ \t]$' patches/test2.diff + > ! a + > ! c + + $ quilt refresh -C0 + > Warning: trailing whitespace in lines 1,3 of a + > Refreshed patch patches/test2.diff + + $ quilt refresh -c --strip-trailing-whitespace + > Removing trailing whitespace from lines 1,3 of a + > Refreshed patch patches/test2.diff + + $ grep '[ \t]$' patches/test2.diff + + $ quilt pop -q + > Removing patch patches/test2.diff + > No patches applied + $ cd .. $ rm -rf d |