When traversing SES_DELETE in uniHunks, beforeIdx suddenly decreases #19

Open
opened 2024-04-21 21:33:01 -05:00 by qaqcatz · 1 comment
qaqcatz commented 2024-04-21 21:33:01 -05:00 (Migrated from github.com)

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

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`: ```shell ... -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: ```cpp #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](https://github.com/cubicdaiya/dtl/files/15056237/new.txt) [old.txt](https://github.com/cubicdaiya/dtl/files/15056238/old.txt)
qaqcatz commented 2024-04-23 01:45:18 -05:00 (Migrated from github.com)

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

By the way, the result in `getSes().getSequence()` is correct, It seems that there is some problem within `composeUnifiedHunks`.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-cubicdaiya/dtl#19
No description provided.