diff --git a/contrib/search_compare.pl b/contrib/search_compare.pl index 902c51076a..f004ac3987 100755 --- a/contrib/search_compare.pl +++ b/contrib/search_compare.pl @@ -10,7 +10,6 @@ # University of Stuttgart. All rights reserved. # Copyright (c) 2004-2005 The Regents of the University of California. # All rights reserved. -# Copyright (c) 2013 Intel Inc. All rights reserved. # $COPYRIGHT$ # # Additional copyrights may follow @@ -21,40 +20,19 @@ use File::Find; use File::Basename; use File::Compare; -use Text::Diff; use Getopt::Long; +use Text::Diff; -if (scalar(@ARGV) != 2) { - print "Usage: search_compare.pl src_dir target_dir\n"; - exit 1; -} - -my $src_dir = @ARGV[0]; -my $target_dir = @ARGV[1]; -my $len_src_dir = length($src_dir); -my $len_tgt_dir = length($target_dir); +my $src_arg; +my $tgt_arg; +my $src_dir; +my $target_dir; my @src_tree = (); my @tgt_tree = (); my $flag; - -my $ok = Getopt::Long::GetOptions("diff" => \$diff_arg, - "debug|d" => \$debug_arg, - "help|h" => \$help_arg, - "ignore=s" => \$exclude_arg, - ); - -if (!$ok || $help_arg) { - print "Invalid command line argument.\n\n" - if (!$ok); - print "Options: - --diff | -diff Output a diff of files that were modified - turns - off the output of files added/deleted - --debug | -d Output lots of debug information - --help | -h This help list - --ignore | -ignore Name of file containing typical ignore list - e.g., - .hgignore or .gitignore\n"; - my_exit($ok ? 0 : 1); -} +my $help_arg = 0; +my $diff_file = ""; +my $diff_arg; sub construct { # don't process directories or links, and dont' recurse down @@ -88,6 +66,41 @@ sub construct { } } +# Command line parameters + +my $ok = Getopt::Long::GetOptions("help|h" => \$help_arg, + "src=s" => \$src_arg, + "tgt=s" => \$tgt_arg, + "diff=s" => \$diff_arg, + ); + +if (!$ok || $help_arg) { + print "Invalid command line argument.\n\n" + if (!$ok); + print "Options: + --diff | -diff Output diff of changed files to specified file + --src | -src Head of source directory + --tgt | -tgt Head of target directory\n"; + exit($ok ? 0 : 1); +} + +if (!$src_arg || !$tgt_arg) { + print "Missing src or tgt directory\n"; + exit(1); +} + +$src_dir = $src_arg; +$target_dir = $tgt_arg; + +if ($diff_arg) { + $diff_file = File::Spec->rel2abs($diff_arg); + unlink ($diff_file); + open(MYFILE, ">$diff_file"); +} + +my $len_src_dir = length($src_dir); +my $len_tgt_dir = length($target_dir); + # construct a tree of all files in the source directory tree $flag = 0; find(\&construct, $src_dir); @@ -106,7 +119,6 @@ my $tgt_file; my @modified = (); my @src_pared = (); my $i; -my $d; foreach $src (@src_tree) { # strip the leading elements of the path that was given to us $src_file = substr($src, $len_src_dir); @@ -120,46 +132,50 @@ foreach $src (@src_tree) { # file has been found - ignore it $found = 1; if (compare($src, $tgt) != 0) { - $d = diff $src, $tgt; - print "Index: $tgt\n"; - print "===================================================================\n"; - print "$d\n"; -# push(@modified, $src); + push(@modified, $src); + if ($diff_arg) { + my $diff = diff $src, $tgt, { STYLE => "Unified" }; + print MYFILE $diff . "\n"; + } } # remove this file from the target tree as it has been found # splice @tgt_tree, $i, 1; break; } } -# if ($found == 0) { -# print "Add: " . $src . "\n"; -## } else { -# push(@src_pared, $src); -# } + if ($found == 0) { + print "Add: " . $src . "\n"; + } else { + push(@src_pared, $src); + } } print "\n"; # print a list of files in the target tree that need to be deleted -#foreach $tgt (@tgt_tree) { -# $found = 0; -# $tgt_file = substr($tgt, $len_tgt_dir); -# foreach $src (@src_pared) { -# $src_file = substr($src, $len_src_dir); -# if ($src_file eq $tgt_file) { -# # file has been found - ignore it -# $found = 1; -# break; -# } -# } -# if ($found == 0) { -# print "Delete: " . $tgt . "\n"; -# } -#} +foreach $tgt (@tgt_tree) { + $found = 0; + $tgt_file = substr($tgt, $len_tgt_dir); + foreach $src (@src_pared) { + $src_file = substr($src, $len_src_dir); + if ($src_file eq $tgt_file) { + # file has been found - ignore it + $found = 1; + break; + } + } + if ($found == 0) { + print "Delete: " . $tgt . "\n"; + } +} -#print "\n"; +print "\n"; # print a list of files that have been modified -#foreach $tgt (@modified) { -# print "Modified: " . $tgt . "\n"; -#} +foreach $tgt (@modified) { + print "Modified: " . $tgt . "\n"; +} + +if ($diff_arg) { + close(MYFILE); +}