public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Joe Perches <joe@perches.com>
Cc: Greg KH <gregkh@linuxfoundation.org>,
	devel <devel@driverdev.osuosl.org>,
	Lidza Louina <lidza.louina@gmail.com>,
	DaeSeok Youn <daeseok.youn@gmail.com>,
	driverdev-devel@linuxdriverproject.org,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] staging: dgap: re-arrange functions for removing forward declarations.
Date: Tue, 14 Oct 2014 16:04:28 +0300	[thread overview]
Message-ID: <20141014130428.GW23154@mwanda> (raw)
In-Reply-To: <1413253178.3269.2.camel@joe-AO725>

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

On Mon, Oct 13, 2014 at 07:19:38PM -0700, Joe Perches wrote:
> I don't know of a way to compare objects when functions are
> rearranged in the source file.
> 
> Anyone else?

I have a perl script that I use to review function movement.  It barfed
on the DaeSeok's original patch so I re-wrote it, but it's still not
great.

Anyway, attached.

regards,
dan carpenter


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

#!/usr/bin/perl

use strict;
use File::Temp qw/ tempdir /;
use File::Path qw/ rmtree /;
use File::Compare;

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

    # remove the first char
    s/^[ +-]//;
    return $_;
}

sub break_out_blocks($)
{
    my $dir = shift();
    my $block_nr = 0;

    open FILE, "<", "$dir/full";
    open OUT, ">", "$dir/$block_nr";

    while (<FILE>) {

        if ($block_nr && $_ =~ /^}/) {
            print OUT $_;
            close(OUT);
            $block_nr++;
            open OUT, ">", "$dir/$block_nr";
            next;
        }

        if ($_ =~ /^{/ || ($_ =~ /^[a-zA-Z]/ && $_ =~ / {$/)) {
            close(OUT);
            $block_nr++;
            open OUT, ">", "$dir/$block_nr";
        }

        print OUT $_;
    }
    close(OUT);
}

sub files_same($$)
{
    my $one = shift();
    my $two = shift();
    my $size_one = (stat($one))[7];
    my $size_two = (stat($two))[7];

    if ($size_one != $size_two) {
        return 0;
    }
    return compare($one, $two) == 0;
}

sub is_block($)
{
    my $file = shift();
    open LINE, "<", "$file";
    my $line = <LINE>;

    if ($line =~ /^{/ || ($line =~ /^[a-zA-Z]/ && $line =~ / {$/)) {
        return 1;
    }
    return 0;
}

sub replace_exact_blocks($$) {
    my $olddir = shift();
    my $newdir = shift();

    my $i = -1;
    while (1) {
        $i++;
        if (! -e "$olddir/$i") {
            last;
        }

        if (!is_block("$olddir/$i")) {
            next;
        }

        my $j = -1;
        while (1) {
            $j++;
            if (! -e "$newdir/$j") {
                last;
            }

            if (files_same("$olddir/$i", "$newdir/$j")) {

                open OUT, ">", "$olddir/$i";
                print OUT "- MOVED {$i}\n";
                close OUT;

                open OUT, ">", "$newdir/$j";
                print OUT "+ MOVED {$j}\n";
                close OUT;
                last;
            }

        }
    }
}

sub merge_blocks($) {
    my $dir = shift();

    open MERGED, ">", "$dir/merged";
    my $i = -1;
    while (1) {
        $i++;
        if (! -e "$dir/$i") {
            last;
        }

        open FILE, "<", "$dir/$i";
        while (<FILE>) {
            print MERGED $_;
        }
        close(FILE);
    }
    close(MERGED);
}

sub show_diff($$) {
    my $olddir = shift();
    my $newdir = shift();

    open diff, "diff -uw $olddir/merged $newdir/merged |";
    while (<diff>) {
        print $_;
    }
}

my $output;
my $inside = 0;
my $olddir = tempdir();
my $newdir = tempdir();

open oldfh, ">", "$olddir/full";
open newfh, ">", "$newdir/full";

#recreate an old file and a new file
while (<>) {
    if ($_ =~ /^(---|\+\+\+)/) {
        next;
    }

    if ($_ =~ /^@/) {
        $inside = 1;
    }
    if ($inside && !(($_ =~ /^[- @+]/) || ($_ =~ /^$/))) {
        $inside = 0;
    }
    if (!$inside) {
        next;
    }

    $output = filter($_);

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

}

close(oldfh);
close(newfh);

break_out_blocks($olddir);
break_out_blocks($newdir);

replace_exact_blocks($olddir, $newdir);

merge_blocks($olddir);
merge_blocks($newdir);

show_diff($olddir, $newdir);

#print "old = $olddir/ new = $newdir/\n";
rmtree($olddir);
rmtree($newdir);

  parent reply	other threads:[~2014-10-14 13:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-13  2:34 [PATCH] staging: dgap: re-arrange functions for removing forward declarations Daeseok Youn
2014-10-13  3:25 ` Greg KH
2014-10-13  8:01   ` DaeSeok Youn
2014-10-13 14:56     ` Joe Perches
2014-10-13 23:44       ` DaeSeok Youn
2014-10-14  2:04       ` Greg KH
2014-10-14  2:19         ` Joe Perches
2014-10-14 11:10           ` DaeSeok Youn
2014-10-14 13:04           ` Dan Carpenter [this message]
     [not found]       ` <1441864556.1190074.1413252337243.JavaMail.root@mx2.compro.net>
2014-10-14 12:01         ` Mark Hounschell
     [not found]         ` <1480715134.1194532.1413288717130.JavaMail.root@mx2.compro.net>
2014-10-21 18:00           ` Mark Hounschell

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=20141014130428.GW23154@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=daeseok.youn@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=joe@perches.com \
    --cc=lidza.louina@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /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