From: Lars Kurth Date: Tue, 25 Sep 2018 17:58:37 +0000 (+0100) Subject: Handle heuristic for fuzzy commit matches better X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=437bf146b252f97da57bada8e30db9557b6fbba6;p=people%2Flarsk%2Fxen-release-scripts.git Handle heuristic for fuzzy commit matches better --- diff --git a/match-xsa b/match-xsa index a88a1d0..a07628f 100755 --- a/match-xsa +++ b/match-xsa @@ -36,6 +36,11 @@ my $qemuu_git = $opt{'QEMUU_GIT'}; my $qemut_git = $opt{'QEMUT_GIT'}; my $xsa = $XSADIR; +# Make print output redirected to HTML files more easily readable +my $NL = "\n"; +if ($HTML) { + $NL = "
\n"; +} # Always get/update logs my $rl .= "./xen-release-logs --logroot $LOGROOT --version $VERSION --major $MAJOR"; @@ -110,9 +115,9 @@ getlogs("$LOGDIR/qemuu_$SHORT", \@LOGQEMUU, \@LOGQEMUU_hash); getlogs("$LOGDIR/qemut_$SHORT", \@LOGQEMUT, \@LOGQEMUT_hash); # Do the actual matching -print "CHECKING '$XSALISTFILE' against 'xen_$SHORT.log', 'qemuu_$SHORT.log' ". - "and 'qemut_$SHORT.log'.\n"; -print "\n"; +print "CHECKING '$XSALISTFILE' against 'xen_$SHORT.log', + 'qemuu_$SHORT.log' "."and 'qemut_$SHORT.log'.$NL"; +print $NL; for ($i=0; $i <= $XSAs; $i++) { my $j=0; my $i_correct = $i+1; @@ -561,6 +566,7 @@ sub matchsmart { # If there is a match, compare the actual patch my $index = 0; + my @matches = (); for my $log_id (@$log_ref) { my $ret = matchcommitmsg ($XSA_ID[$i], $log_id); if ($ret) { @@ -568,27 +574,44 @@ sub matchsmart { } if ($DEBUG != 0) { $debugstring .= $index.": ".$log_id."\n"; - if ($namefound != 0) { - if ($ret == 1) { - $debugstring .= ">>> FILENAME MATCHED\n"; - } elsif ($ret == 2) { - $debugstring .= ">>> FILENAME MATCHED (truncated)\n"; + } + if ($namefound != 0) { + if ($ret == 1) { + if ($DEBUG != 0) { + $debugstring .= ">>> FILENAME MATCHED\n"; + } + # Ignore any almost matches found before + @matches = ($index); + $namefound = 1; + last; + } elsif ($ret == 2) { + if ($DEBUG != 0) { + $debugstring .= ">>> FILENAME MATCHED (truncated)"; + $debugstring .= "... keep searching\n"; } + push @matches, $index; + # Keep tracking this for a while + print "WARNING XSA=".$XSA[$i]."(".$i."); Possible Issue: ". + "truncated file match: '".$XSA_ID[$i]."' with '". + $log_id."'".$NL; } - } - - if ($namefound != 0) { + } + $index++; + } + + if ($namefound != 0) { + for my $index (@matches) { chdir($git_dir); #my $git_command="git show ".@$loghash_ref[$index].' --format=""'; my $git_command="git show ".@$loghash_ref[$index]; my $diff_git = `$git_command`; - + if ($XSAFETCH) { my $path=""; # Check whether $XSA_PATCH[$i] contains a path - my $index = rindex($XSA_PATCH[$i], "/"); - if ($index != -1) { - $path = "/".substr($XSA_PATCH[$i], 0, $index); + my $rindex = rindex($XSA_PATCH[$i], "/"); + if ($rindex != -1) { + $path = "/".substr($XSA_PATCH[$i], 0, $rindex); } if (! -d "$xsa_dir$path") { system("mkdir $xsa_dir$path"); @@ -596,35 +619,35 @@ sub matchsmart { system("wget --quiet --no-check-certificate -P $xsa_dir$path ". "$XSAFETCH/$XSA_PATCH[$i]"); } - + my $patch = read_file("$xsa_dir/$XSA_PATCH[$i]"); - + my $diff_git_n = normalize_diff($diff_git); my $patch_n = normalize_diff($patch); - - if ($DEBUG != 0) { + + if ($DEBUG != 0) { my $gitfile_n = $debugbase."-git-n.txt"; - my $gitfile = $debugbase."-git.txt"; + my $gitfile = $debugbase."-git.txt"; my $patchfile_n = $debugbase."-patch-n.txt"; - my $patchfile = $debugbase."-patch.txt"; + my $patchfile = $debugbase."-patch.txt"; my $compfile_n = $debugbase."-diff-n.txt"; - my $compfile = $debugbase."-diff.txt"; - - write_file($gitfile_n, $diff_git_n); + my $compfile = $debugbase."-diff.txt"; + + write_file($gitfile_n, $diff_git_n); write_file($gitfile, $diff_git); - write_file($patchfile_n, $patch_n); - write_file($patchfile, $patch); + write_file($patchfile_n, $patch_n); + write_file($patchfile, $patch); system ("diff $gitfile_n $patchfile_n > $compfile_n"); system ("diff $gitfile $patchfile > $compfile"); } - + # Check whether the normalized patch and diff are the same - if ($diff_git_n eq $patch_n) { + if ($diff_git_n eq $patch_n) { $found++; if ($DEBUG) { my $debuglog = $debugbase."--content-match.txt"; write_file($debuglog, "matches: ".$found); - $debugstring .= ">>> CONTENT MATCHED\n"; + $debugstring .= ">>> CONTENT MATCHED\n"; $XSA_HASH[$i] = @$loghash_ref[$index]; if ($type eq "xen") { $XSA_REPO[$i] = "xen.git"; @@ -632,14 +655,11 @@ sub matchsmart { $XSA_REPO[$i] = "qemu-xen.git"; } elsif ($type eq "qemut") { $XSA_REPO[$i] = "qemu-xen-traditional.git"; - } + } } } - last; - } - - $index++; + } } if ($namefound == 0) {