diff --git a/Src/CompareEngines/Wrap_DiffUtils.cpp b/Src/CompareEngines/Wrap_DiffUtils.cpp index 4ab3b1a5b8b..88b7d636ef4 100644 --- a/Src/CompareEngines/Wrap_DiffUtils.cpp +++ b/Src/CompareEngines/Wrap_DiffUtils.cpp @@ -113,6 +113,7 @@ int DiffUtils::CompareFiles(DiffFileData* diffData) if (script != nullptr) { const bool usefilters = m_pDiffWrapper->GetOptions().m_filterCommentsLines || + m_pDiffWrapper->GetOptions().m_bIgnoreEofNewlinePresence || (m_pDiffWrapper->GetFilterList() && m_pDiffWrapper->GetFilterList()->HasRegExps()) || (m_pDiffWrapper->GetSubstitutionList() && m_pDiffWrapper->GetSubstitutionList()->HasRegExps()); diff --git a/Src/CompareOptions.cpp b/Src/CompareOptions.cpp index a218c442acb..5e06b9e39b6 100644 --- a/Src/CompareOptions.cpp +++ b/Src/CompareOptions.cpp @@ -49,6 +49,7 @@ void CompareOptions::SetFromDiffOptions(const DIFFOPTIONS &options) m_bIgnoreCase = options.bIgnoreCase; m_bIgnoreEOLDifference = options.bIgnoreEol; m_bIgnoreNumbers = options.bIgnoreNumbers; + m_bIgnoreEofNewlinePresence = options.bIgnoreEofNewlinePresence; } /** @@ -96,7 +97,6 @@ void DiffutilsOptions::SetFromDiffOptions(const DIFFOPTIONS & options) CompareOptions::SetFromDiffOptions(options); m_bCompletelyBlankOutIgnoredDiffereneces = options.bCompletelyBlankOutIgnoredChanges; m_filterCommentsLines = options.bFilterCommentsLines; - m_bIgnoreEofNewlinePresence = options.bIgnoreEofNewlinePresence; m_bIndentHeuristic = options.bIndentHeuristic; switch (options.nDiffAlgorithm) { @@ -189,6 +189,7 @@ void DiffutilsOptions::GetAsDiffOptions(DIFFOPTIONS &options) const options.bIgnoreEol = m_bIgnoreEOLDifference; options.bIgnoreNumbers = m_bIgnoreNumbers; options.nDiffAlgorithm = m_diffAlgorithm; + options.bIgnoreEofNewlinePresence = m_bIgnoreEofNewlinePresence; switch (m_ignoreWhitespace) { diff --git a/Src/DiffWrapper.cpp b/Src/DiffWrapper.cpp index 91e46e2afd1..ad590d4c6e3 100644 --- a/Src/DiffWrapper.cpp +++ b/Src/DiffWrapper.cpp @@ -339,6 +339,18 @@ static void ReplaceChars(std::string & str, const char* chars, const char *rep) } } +static void RemoveEOL(std::string& str) +{ + if (str.empty()) + return; + if (str.size() >= 2 && str[str.size() - 2] == '\r' && str[str.size() - 1] == '\n') + str.erase(str.size() - 2, 2); + else if (str.back() == '\n') + str.pop_back(); + else if (str.back() == '\r') + str.pop_back(); +} + /** * @brief The main entry for post filtering. Performs post-filtering, by setting comment blocks to trivial * @param [in, out] thisob Current change @@ -447,6 +459,11 @@ int CDiffWrapper::PostFilter(PostFilterContext& ctxt, change* thisob, const file Replace(lineDataRight, "\r\n", "\n"); Replace(lineDataRight, "\r", "\n"); } + if (thisob->link == nullptr && m_options.m_bIgnoreEofNewlinePresence && (file_data_ary[0].missing_newline || file_data_ary[1].missing_newline)) + { + RemoveEOL(lineDataLeft); + RemoveEOL(lineDataRight); + } // If both match after filtering, mark this diff hunk as trivial and return. if (lineDataLeft == lineDataRight)