Skip to content

Commit

Permalink
deflookup: look by line content without spaces if available
Browse files Browse the repository at this point in the history
Related: csutils#98
Closes: csutils#168
  • Loading branch information
kdudka committed Apr 19, 2024
1 parent 135f255 commit 0308d93
Show file tree
Hide file tree
Showing 15 changed files with 20,696 additions and 117 deletions.
26 changes: 24 additions & 2 deletions src/lib/deflookup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "deflookup.hh"

#include "finger-print.hh"
#include "msg-filter.hh"
#include "parser.hh"

Expand Down Expand Up @@ -79,8 +80,29 @@ void DefLookup::hashDefect(const Defect &def)
defList.push_back(def);
}

static bool defLookupCore(TDefList &defList)
static bool defLookupCore(TDefList &defList, const Defect &lookFor)
{
// look by line content without spaces if available
const std::string lineCont = FingerPrinter(lookFor).getLineContent();
if (!lineCont.empty()) {
bool fullLineContCoverage = true;

for (auto it = defList.begin(); it != defList.end(); ++it) {
const std::string lineContNow = FingerPrinter(*it).getLineContent();
if (lineContNow.empty())
fullLineContCoverage = false;
else if (lineCont == lineContNow) {
// matched by line content without spaces
defList.erase(it);
return true;
}
}

if (fullLineContCoverage)
// we had line content for all lines but none of them matched
return false;
}

// just remove an arbitrary one
// TODO: add some other criteria in order to make the match more precise
defList.resize(defList.size() - 1U);
Expand Down Expand Up @@ -132,7 +154,7 @@ bool DefLookup::lookup(const Defect &def)
// process the resulting list of defects sequentially
TDefList &defList = itByMsg->second;
assert(!defList.empty());
if (!defLookupCore(defList))
if (!defLookupCore(defList, def))
return false;

// remove empty maps to speed up subsequent lookups
Expand Down
5 changes: 5 additions & 0 deletions src/lib/finger-print.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,8 @@ std::string FingerPrinter::getHash(const EFingerPrintVer fpv) const
// return SHA1 hash from basicData AND lineContent
return computeHexSHA1(d->basicData + sep + d->lineContent);
}

std::string FingerPrinter::getLineContent() const
{
return d->lineContent;
}
3 changes: 3 additions & 0 deletions src/lib/finger-print.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class FingerPrinter {
/// return fingerprint of the selected kind
std::string getHash(EFingerPrintVer) const;

/// return line content without spaces (empty string if not available)
std::string getLineContent() const;

private:
struct Private;
std::unique_ptr<Private> d;
Expand Down
1 change: 1 addition & 0 deletions tests/csdiff/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ test_csdiff(diff-misc 16-cov-parser-key-event)
test_csdiff(diff-misc 17-cov-parser-key-event)
test_csdiff(diff-misc 18-cov-parser-key-event)
test_csdiff(diff-misc 19-cov-parser-key-event)
test_csdiff(diff-misc 20-shellcheck-line-content)
test_csdiff(diff-misc 21-kernel-shell-code)
test_csdiff(diff-misc 22-kernel-zstream-path)
test_csdiff(diff-misc 23-cov-parser-key-event)
Expand Down
7 changes: 7 additions & 0 deletions tests/csdiff/diff-misc/20-shellcheck-line-content-add-z.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Error: SHELLCHECK_WARNING (CWE-475):
/usr/lib/dracut/modules.d/01fips/fips.sh:81:5: warning[SC2039]: In POSIX sh, 'local' is undefined.
# 79| fips_load_crypto() {
# 80| local _k
# 81|-> local _v
# 82| local _module
# 83| local _found
7 changes: 7 additions & 0 deletions tests/csdiff/diff-misc/20-shellcheck-line-content-add.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Error: SHELLCHECK_WARNING (CWE-475):
/usr/lib/dracut/modules.d/01fips/fips.sh:81:5: warning[SC2039]: In POSIX sh, 'local' is undefined.
# 79| fips_load_crypto() {
# 80| local _k
# 81|-> local _v
# 82| local _module
# 83| local _found
Empty file.
Empty file.
Loading

0 comments on commit 0308d93

Please sign in to comment.