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

Allow Diff algorithms (patience, histogram) other than default to be … #2015

Merged
merged 8 commits into from
Sep 7, 2023
13 changes: 12 additions & 1 deletion Src/CompareEngines/Wrap_DiffUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "coretools.h"
#include "DiffList.h"
#include "DiffWrapper.h"
#include "xdiff_gnudiff_compat.h"
#include "unicoder.h"

namespace CompareEngines
Expand Down Expand Up @@ -267,7 +268,17 @@ bool DiffUtils::Diff2Files(struct change ** diffs, int depth,
SE_Handler seh;
try
{
*diffs = diff_2_files(m_inf, depth, bin_status, bMovedBlocks, bin_file);
if (m_pOptions->m_diffAlgorithm != DIFF_ALGORITHM_DEFAULT)
{
const unsigned xdl_flags = make_xdl_flags(*m_pOptions);
*diffs = diff_2_files_xdiff(m_inf, bin_status, 0, xdl_flags);
files[0] = m_inf[0];
files[1] = m_inf[1];
}
else
{
*diffs = diff_2_files(m_inf, depth, bin_status, bMovedBlocks, bin_file);
}
}
catch (SE_Exception&)
{
Expand Down
4 changes: 2 additions & 2 deletions Src/DiffWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,8 +891,8 @@ bool CDiffWrapper::Diff2Files(struct change ** diffs, DiffFileData *diffData,
{
if (m_options.m_diffAlgorithm != DIFF_ALGORITHM_DEFAULT)
{
unsigned xdl_flags = make_xdl_flags(m_options);
*diffs = diff_2_files_xdiff(diffData->m_inf, (m_pMovedLines[0] != nullptr), xdl_flags);
const unsigned xdl_flags = make_xdl_flags(m_options);
*diffs = diff_2_files_xdiff(diffData->m_inf, bin_status, (m_pMovedLines[0] != nullptr), xdl_flags);
files[0] = diffData->m_inf[0];
files[1] = diffData->m_inf[1];
}
Expand Down
18 changes: 15 additions & 3 deletions Src/xdiff_gnudiff_compat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
return 1;
}

struct change * diff_2_files_xdiff (struct file_data filevec[], int bMoved_blocks_flag, unsigned xdl_flags)
struct change * diff_2_files_xdiff (struct file_data filevec[], int* bin_status, int bMoved_blocks_flag, unsigned xdl_flags)
{
mmfile_t mmfile1 = { 0 }, mmfile2 = { 0 };
change *script = nullptr;
Expand All @@ -130,54 +130,66 @@
xpparam_t xpp = { 0 };
xdemitconf_t xecfg = { 0 };
xdemitcb_t ecb = { 0 };
int bin_flag = 0;

read_files(filevec, no_details_flag & ~ignore_some_changes, &bin_flag);

mmfile1.ptr = const_cast<char*>(filevec[0].prefix_end);
mmfile1.size = static_cast<long>(filevec[0].suffix_begin - filevec[0].prefix_end) - filevec[0].missing_newline;
mmfile2.ptr = const_cast<char*>(filevec[1].prefix_end);
mmfile2.size = static_cast<long>(filevec[1].suffix_begin - filevec[1].prefix_end) - filevec[1].missing_newline;

/*
if (!read_mmfile(filevec[0].desc, mmfile1))
goto abort;
if (!read_mmfile(filevec[1].desc, mmfile2))
goto abort;
*/

xpp.flags = xdl_flags;
xecfg.hunk_func = hunk_func;
if (xdl_diff_modified(&mmfile1, &mmfile2, &xpp, &xecfg, &ecb, &xe, &xscr) == 0)
{
/*
filevec[0].buffer = mmfile1.ptr;
filevec[1].buffer = mmfile2.ptr;
filevec[0].bufsize = mmfile1.size;
filevec[1].bufsize = mmfile2.size;
filevec[0].buffered_chars = mmfile1.size;
filevec[1].buffered_chars = mmfile2.size;
filevec[0].linbuf_base = 0;
filevec[1].linbuf_base = 0;
filevec[0].valid_lines = xe.xdf1.nrec;
filevec[1].valid_lines = xe.xdf2.nrec;
filevec[0].linbuf = static_cast<const char **>(malloc(sizeof(char *) * (xe.xdf1.nrec + 1)));
if (!filevec[0].linbuf)
goto abort;
filevec[1].linbuf = static_cast<const char **>(malloc(sizeof(char *) * (xe.xdf2.nrec + 1)));
if (!filevec[1].linbuf)
goto abort;
filevec[0].equivs = static_cast<int *>(malloc(sizeof(int) * xe.xdf1.nrec));
if (!filevec[0].equivs)
goto abort;
filevec[1].equivs = static_cast<int *>(malloc(sizeof(int) * xe.xdf2.nrec));
if (!filevec[1].equivs)
goto abort;
for (int i = 0; i < xe.xdf1.nrec; ++i)
{
filevec[0].linbuf[i] = xe.xdf1.recs[i]->ptr;
filevec[0].equivs[i] = -1;
}
if (xe.xdf1.nrec > 0)
filevec[0].linbuf[xe.xdf1.nrec] = xe.xdf1.recs[xe.xdf1.nrec - 1]->ptr + xe.xdf1.recs[xe.xdf1.nrec - 1]->size;
for (int i = 0; i < xe.xdf2.nrec; ++i)
{
filevec[1].linbuf[i] = xe.xdf2.recs[i]->ptr;
filevec[1].equivs[i] = -1;
}
if (xe.xdf2.nrec > 0)
filevec[1].linbuf[xe.xdf2.nrec] = xe.xdf2.recs[xe.xdf2.nrec - 1]->ptr + xe.xdf2.recs[xe.xdf2.nrec - 1]->size;
filevec[0].missing_newline = is_missing_newline(mmfile1);
filevec[1].missing_newline = is_missing_newline(mmfile2);
*/
Fixed Show fixed Hide fixed

change *prev = nullptr;
for (xdchange_t* xcur = xscr; xcur; xcur = xcur->next)
Expand Down Expand Up @@ -216,7 +228,7 @@
return script;

abort:
free(mmfile1.ptr);
free(mmfile2.ptr);
//free(mmfile1.ptr);
//free(mmfile2.ptr);
Fixed Show fixed Hide fixed
return nullptr;
}
2 changes: 1 addition & 1 deletion Src/xdiff_gnudiff_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

class DiffutilsOptions;
unsigned long make_xdl_flags(const DiffutilsOptions& options);
struct change * diff_2_files_xdiff(struct file_data filevec[], int bMoved_blocks_flag, unsigned xdl_flags);
struct change * diff_2_files_xdiff(struct file_data filevec[], int* bin_status, int bMoved_blocks_flag, unsigned xdl_flags);
Loading