-
Notifications
You must be signed in to change notification settings - Fork 55
Open
Description
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:
Metadata
Metadata
Assignees
Labels
No labels