From 659534ea4af9dd22ec5650f84e47ec8b1f8b1485 Mon Sep 17 00:00:00 2001 From: vapier Date: Mon, 30 Nov 2009 22:58:51 +0000 Subject: [PATCH] ekeyword: store keywords internally rather than using external diff to better handle multiline changes and output control simpler svn path=/trunk/gentoolkit-dev/; revision=701 --- src/ekeyword/ekeyword | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/ekeyword/ekeyword b/src/ekeyword/ekeyword index 244a054..e38801d 100755 --- a/src/ekeyword/ekeyword +++ b/src/ekeyword/ekeyword @@ -7,11 +7,8 @@ # ekeyword: Update the KEYWORDS in an ebuild. For example: # # $ ekeyword ~alpha oaf-0.6.8-r1.ebuild -# 12c12 -# < KEYWORDS="ppc sparc x86" -# --- -# > KEYWORDS="~alpha ppc sparc x86" - +# - ppc sparc x86 +# + ~alpha ppc sparc x86 my ($kw_re) = '^(?:([-~^]?)(\w[\w-]*)|([-^]\*))$'; my (@kw); @@ -43,6 +40,8 @@ for my $f (@ARGV) { open O, ">$f.new" or die "Can't create $f.new: $!\n"; select O; + my $keys_before; + my $keys_after; while () { if (/^\s*KEYWORDS=/) { @@ -53,6 +52,7 @@ for my $f (@ARGV) { $_ = join " ", $_, $next; } (my $quoted = $_) =~ s/^.*?["'](.*?)["'].*/$1/s; + $keys_before = $quoted; # replace -* with -STAR for our convenience below $quoted =~ s/-\*/-STAR/; @@ -109,6 +109,8 @@ for my $f (@ARGV) { $sa cmp $sb; } split " ", $quoted; + $keys_after = $quoted; + # re-insert quoted to KEYWORDS s/(["']).*?["']/$1$quoted$1/; @@ -122,7 +124,18 @@ for my $f (@ARGV) { close O; select STDOUT; - system "diff -U 0 $f $f.new | sed -n '/KEYWORDS=/s:^: :p'"; + if ($keys_before ne $keys_after) { + # This gives uniform output, but actually seems to make + # it harder to pick out differences, and doesn't work so + # well when adding/removing keywords + #$keys_before =~ s/(^| )/ /g; + #$keys_before =~ s/ ([-~])/$1/g; + #$keys_after =~ s/(^| )/ /g; + #$keys_after =~ s/ ([-~])/$1/g; + print " - $keys_before\n + $keys_after\n"; + #system "diff -U 0 $f $f.new | sed -n -r 's:^(.)[[:space:]]*KEYWORDS=\"(.*)\": \\1 \\2:p'"; + #system "diff -U 0 $f $f.new | sed -n '/KEYWORDS=/s:^: :p'"; + } rename "$f.new", "$f" or die "Can't rename: $!\n"; $files++; } -- 2.26.2