Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Dec 18, 2024
1 parent 97d0d9c commit 087f8a9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
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_bIgnoreEofNewlinePresence ||
(m_pDiffWrapper->GetFilterList() && m_pDiffWrapper->GetFilterList()->HasRegExps()) ||
(m_pDiffWrapper->GetSubstitutionList() && m_pDiffWrapper->GetSubstitutionList()->HasRegExps());

Expand Down
3 changes: 2 additions & 1 deletion Src/CompareOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
17 changes: 17 additions & 0 deletions Src/DiffWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 087f8a9

Please sign in to comment.