LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: devel@driverdev.osuosl.org
Subject: rename_rev.pl script for reviewing renames
Date: Thu, 3 Feb 2011 13:08:28 +0300	[thread overview]
Message-ID: <20110203100828.GO20606@bicker> (raw)

[-- 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);

             reply	other threads:[~2011-02-03 10:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-03 10:08 Dan Carpenter [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110203100828.GO20606@bicker \
    --to=error27@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: rename_rev.pl script for reviewing renames' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).