MCPcopy Create free account
hub / github.com/WinMerge/winmerge / AdjustDiffBlocks

Method AdjustDiffBlocks

Src/MergeDocDiffSync.cpp:333–441  ·  view source on GitHub ↗

* @brief Divide diff blocks to align similar lines in diff blocks. */

Source from the content-addressed store, hash-verified

331 * @brief Divide diff blocks to align similar lines in diff blocks.
332 */
333void CMergeDoc::AdjustDiffBlocks()
334{
335 int nDiff;
336 int nDiffCount = m_diffList.GetSize();
337
338 // Go through and do our best to line up lines within each diff block
339 // between left side and right side
340 DiffList newDiffList;
341 newDiffList.Clear();
342 for (nDiff = 0; nDiff < nDiffCount; nDiff++)
343 {
344 const DIFFRANGE & diffrange = *m_diffList.DiffRangeAt(nDiff);
345 // size map correctly (it will hold one entry for each left-side line
346 int nlines0 = diffrange.end[0] - diffrange.begin[0] + 1;
347 int nlines1 = diffrange.end[1] - diffrange.begin[1] + 1;
348 if (nlines0>0 && nlines1>0)
349 {
350 // Call worker to do all lines in block
351 int lo0 = 0, hi0 = nlines0-1;
352 int lo1 = 0, hi1 = nlines1-1;
353 const std::vector<WordDiff> worddiffs = GetWordDiffArrayInRange(diffrange.begin, diffrange.end);
354#ifdef _DEBUG
355 PrintWordDiffList(2, worddiffs);
356#endif
357 DiffMap diffmap;
358 diffmap.InitDiffMap(nlines0);
359 AdjustDiffBlock(diffmap, diffrange, worddiffs, 0, 1, lo0, hi0, lo1, hi1);
360 ValidateDiffMap(diffmap);
361 std::vector<std::array<int, 2>> vlines = CreateVirtualLineToRealLineMap(diffmap, nlines0, nlines1);
362
363 // divide diff blocks
364 int line0 = 0, line1 = 0;
365 for (size_t i = 0; i < vlines.size();)
366 {
367 DIFFRANGE dr;
368 size_t ib = i;
369 if ((vlines[i][0] != DiffMap::GHOST_MAP_ENTRY) &&
370 (vlines[i][1] != DiffMap::GHOST_MAP_ENTRY))
371 {
372 while (i < vlines.size() &&
373 (vlines[i][0] != DiffMap::GHOST_MAP_ENTRY) &&
374 (vlines[i][1] != DiffMap::GHOST_MAP_ENTRY))
375 {
376 line0++;
377 line1++;
378 i++;
379 }
380 dr.begin[0] = diffrange.begin[0] + vlines[ib][0];
381 dr.begin[1] = diffrange.begin[1] + vlines[ib][1];
382 dr.end[0] = diffrange.begin[0] + vlines[i - 1][0];
383 dr.end[1] = diffrange.begin[1] + vlines[i - 1][1];
384 dr.blank[0] = dr.blank[1] = -1;
385 dr.op = diffrange.op;
386 newDiffList.AddDiff(dr);
387 }
388 else if ((vlines[i][0] == DiffMap::GHOST_MAP_ENTRY) &&
389 (vlines[i][1] != DiffMap::GHOST_MAP_ENTRY))
390 {

Callers

nothing calls this directly

Calls 10

PrintWordDiffListFunction · 0.85
ValidateDiffMapFunction · 0.85
assertClass · 0.85
DiffRangeAtMethod · 0.80
InitDiffMapMethod · 0.80
AddDiffMethod · 0.80
GetSizeMethod · 0.45
ClearMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected