LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* rename_rev.pl script for reviewing renames
@ 2011-02-03 10:08 Dan Carpenter
  2011-02-03 10:22 ` Wolfram Sang
  0 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2011-02-03 10:08 UTC (permalink / raw)
  To: linux-kernel; +Cc: devel

[-- Attachment #1: Type: text/plain, Size: 535 bytes --]

There are a lot of refactoring patches where people change camel case
names to kernel style names etc.  I've written a script to make it
easier to review them.  It's attached.

For example the linked patch is about 7900 lines long.  It renames
A_BOOL to bool, TRUE to true and FALSE to false.
http://driverdev.linuxdriverproject.org/pipermail/devel/2011-February/011810.html

cat email.txt | ./rename_rev.pl A_BOOL bool TRUE true FALSE false | less

The resulting diff is 78 lines long (99% reduced).  Woohoo!

regards,
dan carpenter


[-- Attachment #2: rename_rev.pl --]
[-- Type: text/x-perl, Size: 1109 bytes --]

#!/usr/bin/perl

use File::Temp qw/ :mktemp  /;

sub usage() {
    print "cat diff | transform.pl old new old new old new...\n";
    die;
}

my @subs;

sub filter($) {
    my $line = shift();

    foreach my $sub (@subs) {
	$line =~ s/$sub->[0]/$sub->[1]/g;
    }

    # white space at the end of lines
    $line =~ s/ *$//g;
    $line =~ s/\t*$//g;

    # remove the first char
    $line =~ s/^[ +-]//;

    # tabs to spaces
    $line =~ s/\ {8}/\t/g;

    return $line;
}

($oldfh, $oldfile) = mkstemp("/tmp/oldXXXXX");
($newfh, $newfile) = mkstemp("/tmp/newXXXXX");

while (my $param1 = shift()) {
    my $param2 = shift;

    if ($param2 =~ /^$/) {
	usage();
    }
    push @subs, [$param1, $param2];
}

while (<>) {
    my $line = $_;

    if ($line =~ /^---/) {
	next;
    }
    if ($line =~ /^\+\+\+/) {
	next;
    }

    my $output = filter($line);
    if ($line =~ /^-/) {
	print $oldfh $output;
	next;
    }
    if ($line =~ /^\+/) {
	print $newfh $output;
	next;
    }
    print $oldfh $output;
    print $newfh $output;
}

system("diff -u $oldfile $newfile");

unlink($oldfile);
unlink($newfile);

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-02-07  3:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-03 10:08 rename_rev.pl script for reviewing renames Dan Carpenter
2011-02-03 10:22 ` Wolfram Sang
2011-02-03 10:35   ` Dan Carpenter
2011-02-03 10:50   ` Dan Carpenter
2011-02-06 12:25     ` Dan Carpenter
2011-02-07  3:39       ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).