LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: Wolfram Sang <w.sang@pengutronix.de>,
	linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org
Subject: Re: rename_rev.pl script for reviewing renames
Date: Sun, 6 Feb 2011 15:25:39 +0300	[thread overview]
Message-ID: <20110206122539.GB4384@bicker> (raw)
In-Reply-To: <20110203105048.GR20606@bicker>

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

I've added the some flags:
	-e : gets executed on old lines
	-ea: executed on everything
	-nc: strips one line comments

So say you have a patch that adds parenthesis around a bunch of macros
like this:
http://marc.info/?l=linux-kernel&m=129685142419550&w=2

Then you can just type:
cat /home/dcarpenter/tmp/html23/parens.patch | \
	./rename_rev.pl -e 's/(define \w+) (.*)/$1 ($2)/'

Or if you have a camel case script that changes "ThisVariable" to
"this_variable".  Then the command would be:
git show c659c38 | ./rename_rev.pl -ea '$_ = lc' -ea 's/_//g'
Which changes everything to lower case and strips out all the
underscores.  You might want to combine it with some other flags:
git show c659c38 | ./rename_rev.pl -nc \
	-e 's/TLanPrivateInfo/struct tlan_priv/' \
	-e 's/TLanList/struct tlan_list/' \
	-ea '$_ = lc' -ea 's/_//g'

What I would like is if there was some way to ignore changes which just
introduced new lines, but didn't affect runtime behavior.  I'm not sure
how to do that.

regards,
dan carpenter

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

#!/usr/bin/perl

use strict;
use File::Temp qw/ :mktemp  /;

sub usage() {
    print "usage: cat diff | $0 old new old new old new...\n";
    print "   or: cat diff | $0 -e 's/old/new/g'\n"; 
    print " -e : execute on old lines\n";
    print " -ea: execute on all lines\n";
    print " -nc: strip one line comments\n"; 
    exit(1);
}

my @subs;
my @cmds;
my $strip_comments;

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

    my $old = 0;
    if ($_ =~ /^-/) {
        $old = 1;
    }

    # remove the first char
    s/^[ +-]//;

    if ($strip_comments) {
        s/\/\*.*?\*\///g;
        s/\/\/.*//;
    }

    foreach my $cmd (@cmds) {
        if ($old || $cmd->[0] =~ /^-ea$/) {
		eval $cmd->[1];
	}
    }

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

    return $_;
}


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

while (my $param1 = shift()) {
    if ($param1 =~ /^-nc$/) {
        $strip_comments = 1;
        next;
    }

    my $param2 = shift;
    if ($param2 =~ /^$/) {
	usage();
    }

    if ($param1 =~ /^-e(a|)$/) {
        push @cmds, [$param1, $param2];
	next;
    }
    push @subs, [$param1, $param2];
}

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

    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 -uw $oldfile $newfile");

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

  reply	other threads:[~2011-02-06 12:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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=20110206122539.GB4384@bicker \
    --to=error27@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=w.sang@pengutronix.de \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).