Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Ignore missing trailing EOL" option to Compare settings #2573

Merged
merged 25 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Docs/Manual/Manual.cfg text eol=lf
Docs/Manual/**/*.xml text eol=lf
Translations/**/*.po text eol=lf
Translations/**/*.pot text eol=lf
Testing/Data/Compare/**/ignore_eof_*.txt -text
6 changes: 5 additions & 1 deletion Src/CompareEngines/ByteComparator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@
}
else // don't skip blank lines, but still ignore eol difference
{
const char* ptr0b = ptr0;
const char* ptr1b = ptr1;
HandleSide0Eol((char **) &ptr0, end0, eof0);
HandleSide1Eol((char **) &ptr1, end1, eof1);

Expand All @@ -353,6 +355,8 @@
if ((!m_eol0 || !m_eol1) && (orig0 == end0 || orig1 == end1))
{
// one side had an end-of-line, but the other didn't
ptr0 = ptr0b;

Check warning

Code scanning / CodeQL

Local variable address stored in non-local memory Warning

A stack address which arrived via a
parameter
may be assigned to a non-local variable.
A stack address which arrived via a
parameter
may be assigned to a non-local variable.
A stack address which arrived via a
parameter
may be assigned to a non-local variable.
A stack address which arrived via a
parameter
may be assigned to a non-local variable.
A stack address which arrived via a
parameter
may be assigned to a non-local variable.
A stack address which arrived via a
parameter
may be assigned to a non-local variable.
A stack address which arrived via a
parameter
may be assigned to a non-local variable.
A stack address which arrived via a
parameter
may be assigned to a non-local variable.
ptr1 = ptr1b;

Check warning

Code scanning / CodeQL

Local variable address stored in non-local memory Warning

A stack address which arrived via a
parameter
may be assigned to a non-local variable.
A stack address which arrived via a
parameter
may be assigned to a non-local variable.
A stack address which arrived via a
parameter
may be assigned to a non-local variable.
A stack address which arrived via a
parameter
may be assigned to a non-local variable.
A stack address which arrived via a
parameter
may be assigned to a non-local variable.
A stack address which arrived via a
parameter
may be assigned to a non-local variable.
A stack address which arrived via a
parameter
may be assigned to a non-local variable.
A stack address which arrived via a
parameter
may be assigned to a non-local variable.
result = RESULT_DIFF;
goto exit;
}
Expand Down Expand Up @@ -385,7 +389,7 @@
goto need_more;
else
{
result = RESULT_SAME;
result = (m_eol0 == m_eol1) ? RESULT_SAME : RESULT_DIFF;
goto exit;
}
}
Expand Down
29 changes: 28 additions & 1 deletion Src/CompareEngines/ByteCompare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
// because transform code converted any UCS-2 files to UTF-8
// We could compare directly in UCS-2LE here, as an optimization, in that case
char buff[2][WMCMPBUFF]; // buffered access to files
std::string lasteol[2];
int i;
unsigned diffcode = 0;

Expand Down Expand Up @@ -126,11 +127,23 @@
if (rtn < space)
eof[i] = true;
bfend[i] += rtn;
if (m_pOptions->m_bIgnoreMissingTrailingEol)
{
for (int64_t j = (std::max)(bfstart[i], bfend[i] - 4); j < bfend[i]; ++j)
{
const char c = buff[i][j];
if (c == '\r' || c == '\n')
lasteol[i].push_back(c);
else
lasteol[i].clear();
}
}
if (diffData->m_inf[0].desc == diffData->m_inf[1].desc)
{
bfstart[1] = bfstart[0];
bfend[1] = bfend[0];
eof[1] = eof[0];
lasteol[1] = lasteol[0];
diffData->m_FileLocation[1] = diffData->m_FileLocation[0];
memcpy(&buff[1][bfend[1] - rtn], &buff[0][bfend[0] - rtn], rtn);
break;
Expand Down Expand Up @@ -165,7 +178,21 @@
}
else
{
diffcode |= DIFFCODE::DIFF;
if (m_pOptions->m_bIgnoreMissingTrailingEol)
{
if ((eof[0] || eof[1]) &&
((end0 - ptr0 <= 1 && (lasteol[0] == "\r" || lasteol[0] == "\n" || lasteol[0] == "\r\n") && (end1 == ptr1))) ||
((end0 - ptr0 == 2 && (lasteol[0] == "\r\n") && (end1 == ptr1))) ||
((end1 - ptr1 <= 1 && (lasteol[1] == "\r" || lasteol[1] == "\n" || lasteol[1] == "\r\n") && (end0 == ptr0))) ||
((end1 - ptr1 == 2 && (lasteol[1] == "\r\n") && (end0 == ptr0))))
Comment on lines +183 to +187

Check notice

Code scanning / CodeQL

Complex condition Note

Complex condition: too many logical operations in this expression.
;
else
diffcode |= DIFFCODE::DIFF;
}
else
{
diffcode |= DIFFCODE::DIFF;
}
ptr0 = end0;
ptr1 = end1;
// move our current pointers over what we just compared
Expand Down
1 change: 1 addition & 0 deletions Src/CompareEngines/Wrap_DiffUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ int DiffUtils::CompareFiles(DiffFileData* diffData)
if (script != nullptr)
{
const bool usefilters = m_pDiffWrapper->GetOptions().m_filterCommentsLines ||
m_pDiffWrapper->GetOptions().m_bIgnoreMissingTrailingEol ||
(m_pDiffWrapper->GetFilterList() && m_pDiffWrapper->GetFilterList()->HasRegExps()) ||
(m_pDiffWrapper->GetSubstitutionList() && m_pDiffWrapper->GetSubstitutionList()->HasRegExps());

Expand Down
3 changes: 3 additions & 0 deletions Src/CompareOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ CompareOptions::CompareOptions()
, m_bIgnoreCase(false)
, m_bIgnoreEOLDifference(false)
, m_bIgnoreNumbers(false)
, m_bIgnoreMissingTrailingEol(false)
{
}

Expand Down Expand Up @@ -48,6 +49,7 @@ void CompareOptions::SetFromDiffOptions(const DIFFOPTIONS &options)
m_bIgnoreCase = options.bIgnoreCase;
m_bIgnoreEOLDifference = options.bIgnoreEol;
m_bIgnoreNumbers = options.bIgnoreNumbers;
m_bIgnoreMissingTrailingEol = options.bIgnoreMissingTrailingEol;
}

/**
Expand Down Expand Up @@ -187,6 +189,7 @@ void DiffutilsOptions::GetAsDiffOptions(DIFFOPTIONS &options) const
options.bIgnoreEol = m_bIgnoreEOLDifference;
options.bIgnoreNumbers = m_bIgnoreNumbers;
options.nDiffAlgorithm = m_diffAlgorithm;
options.bIgnoreMissingTrailingEol = m_bIgnoreMissingTrailingEol;

switch (m_ignoreWhitespace)
{
Expand Down
2 changes: 2 additions & 0 deletions Src/CompareOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ struct DIFFOPTIONS
bool bFilterCommentsLines; /**< Ignore Multiline comments differences -option. */
bool bIndentHeuristic; /**< Ident heuristic -option */
bool bCompletelyBlankOutIgnoredChanges;
bool bIgnoreMissingTrailingEol; /**< Ignore missing trailing EOL -option. */
};

/**
Expand All @@ -105,6 +106,7 @@ class CompareOptions
bool m_bIgnoreCase; /**< Ignore case differences? */
bool m_bIgnoreNumbers; /**< Ignore number differences? */
bool m_bIgnoreEOLDifference; /**< Ignore EOL style differences? */
bool m_bIgnoreMissingTrailingEol; /**< Ignore missing trailing EOL */
};

/**
Expand Down
Loading
Loading