diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index 5151095..865259f 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -12,9 +12,9 @@ jobs: run: | sudo apt-get install -y scons sudo apt-get install -y cmake scons - wget https://github.com/google/googletest/archive/release-1.8.0.zip - unzip -q release-1.8.0.zip - cd googletest-release-1.8.0 + wget https://github.com/google/googletest/archive/release-1.11.0.zip + unzip -q release-1.11.0.zip + cd googletest-release-1.11.0 cmake . make sudo make install diff --git a/ChangeLog b/ChangeLog index e2f22db..de19a6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2022-04-11 Tatsuhiko Kubo + + * bugfix: fixed invalid offset in unified format difference when difference is too large. + + * 1.20 released + 2015-05-03 Tatsuhiko Kubo * added some minor changes. diff --git a/dtl/Diff.hpp b/dtl/Diff.hpp index cff05fe..8c9c774 100644 --- a/dtl/Diff.hpp +++ b/dtl/Diff.hpp @@ -67,6 +67,8 @@ namespace dtl { bool editDistanceOnly; uniHunkVec uniHunks; comparator cmp; + long long ox; + long long oy; public : Diff () {} @@ -260,7 +262,8 @@ namespace dtl { if (isHuge()) { pathCordinates.reserve(MAX_CORDINATES_SIZE); } - + ox = 0; + oy = 0; long long p = -1; fp = new long long[M + N + 3]; fill(&fp[0], &fp[M + N + 3], -1); @@ -595,18 +598,18 @@ namespace dtl { while(px_idx < v[i].x || py_idx < v[i].y) { if (v[i].y - v[i].x > py_idx - px_idx) { if (!wasSwapped()) { - ses.addSequence(*y, 0, y_idx, SES_ADD); + ses.addSequence(*y, 0, y_idx + oy, SES_ADD); } else { - ses.addSequence(*y, y_idx, 0, SES_DELETE); + ses.addSequence(*y, y_idx + oy, 0, SES_DELETE); } ++y; ++y_idx; ++py_idx; } else if (v[i].y - v[i].x < py_idx - px_idx) { if (!wasSwapped()) { - ses.addSequence(*x, x_idx, 0, SES_DELETE); + ses.addSequence(*x, x_idx + ox, 0, SES_DELETE); } else { - ses.addSequence(*x, 0, x_idx, SES_ADD); + ses.addSequence(*x, 0, x_idx + ox, SES_ADD); } ++x; ++x_idx; @@ -614,10 +617,10 @@ namespace dtl { } else { if (!wasSwapped()) { lcs.addSequence(*x); - ses.addSequence(*x, x_idx, y_idx, SES_COMMON); + ses.addSequence(*x, x_idx + ox, y_idx + oy, SES_COMMON); } else { lcs.addSequence(*y); - ses.addSequence(*y, y_idx, x_idx, SES_COMMON); + ses.addSequence(*y, y_idx + oy, x_idx + ox, SES_COMMON); } ++x; ++y; @@ -658,6 +661,8 @@ namespace dtl { fp = new long long[M + N + 3]; fill(&fp[0], &fp[M + N + 3], -1); fill(path.begin(), path.end(), -1); + ox = x_idx - 1; + oy = y_idx - 1; return false; } return true; diff --git a/dtl/variables.hpp b/dtl/variables.hpp index cbf5a54..6720ec8 100644 --- a/dtl/variables.hpp +++ b/dtl/variables.hpp @@ -63,7 +63,7 @@ namespace dtl { /** * version string */ - const string version = "1.19"; + const string version = "1.20"; /** * type of edit for SES diff --git a/test/Patchtest.cpp b/test/Patchtest.cpp index 44c10f5..2e87cf3 100644 --- a/test/Patchtest.cpp +++ b/test/Patchtest.cpp @@ -35,6 +35,7 @@ protected : cases.push_back(createCase("abcdefq3wefarhgorequgho4euhfteowauhfwehogfewrquhoi23hroewhoahfotrhguoiewahrgqqabcdef", "3abcdef4976fd86ouofita67t85r876e5e746578tgliuhopoqqabcdef")); // 8 cases.push_back(createCase("abcqqqeqqqccc", "abdqqqeqqqddd")); // 9 + cases.push_back(createCase("aaaaaaaaaaaaa>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>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&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&saaabcaaaaaaccc")); // 10 } void TearDown () {} @@ -96,3 +97,8 @@ TEST_F (Patchtest, patch_test9) { ASSERT_EQ(cases[9].B, cases[9].diff.patch(cases[9].A)); ASSERT_EQ(cases[9].B, cases[9].diff.uniPatch(cases[9].A)); } + +TEST_F (Patchtest, patch_test10) { + ASSERT_EQ(cases[10].B, cases[10].diff.patch(cases[10].A)); + ASSERT_EQ(cases[10].B, cases[10].diff.uniPatch(cases[10].A)); +} diff --git a/test/SConstruct b/test/SConstruct index c124166..37873dd 100644 --- a/test/SConstruct +++ b/test/SConstruct @@ -11,6 +11,7 @@ def path_chomp(path): env = Environment( CPPFLAGS=['-Wall', '-O2'], CPPPATH=['..'], + CXXFLAGS="-std=c++11", ) conf = Configure(env);