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

When traversing SES_DELETE in uniHunks, beforeIdx suddenly decreases #19

Open
qaqcatz opened this issue Apr 22, 2024 · 1 comment
Open

Comments

@qaqcatz
Copy link

qaqcatz commented Apr 22, 2024

Hello, I am traversing the uniHunks in dtl and attempting to print out each element (type, beforeIdx, afterIdx).

However, I noticed that when traversing consecutive SES_DELETE elements, the value of beforeIdx was reduced from 15321 to 1452:

...
-1 15321 0
-1 1452 0
...

Additionally, I tested with other diff tools and found that there is no text change in line 1452.

This is my code:

#include <iostream>
#include <string>
#include <vector>
#include <filesystem>
#include <fstream>
#include "dtl/dtl.hpp"

namespace fs = std::filesystem;

void fatal(const std::string &msg) {
    std::cerr << msg << std::endl;
    exit(1);
}

void run(const fs::path &oldPath,
         const fs::path &newPath) {
    std::vector<std::string> oldLines;
    std::vector<std::string> newLines;

    std::ifstream oldFileFs(oldPath);
    if (!oldFileFs.is_open()) {
        fatal("Diff error: can not open oldFile: " +
                             oldPath.string());
    }
    std::string line;
    while (getline(oldFileFs, line)) {
        oldLines.push_back(line);
    }

    std::ifstream newFileFs(newPath);
    if (!newFileFs.is_open()) {
        fatal("Diff error: can not open newFile: " +
                             newPath.string());
    }
    while (getline(newFileFs, line)) {
        newLines.push_back(line);
    }

    dtl::Diff<std::string, std::vector<std::string>> diff(oldLines, newLines);
    diff.onHuge();
    diff.compose();
    diff.composeUnifiedHunks();
    auto uniHunks = diff.getUniHunks();

    for (const auto &hunk: uniHunks) {
        for (auto &diffLine: hunk.change) {
            auto &diffLineInfo = diffLine.second;

            std::cerr << diffLineInfo.type << " " <<
            diffLineInfo.beforeIdx << " " << diffLineInfo.afterIdx << std::endl;
        }
    }

}

int main() {
    run("../old.txt", "../new.txt");
}

This is my test files:

new.txt
old.txt

@qaqcatz
Copy link
Author

qaqcatz commented Apr 23, 2024

By the way, the result in getSes().getSequence() is correct, It seems that there is some problem within composeUnifiedHunks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant