cubicdaiya / dtl

diff template library written by C++
Other
283 stars 51 forks source link

There is a bug #3

Closed tripolskypetr closed 5 years ago

tripolskypetr commented 5 years ago

Steps to reproduce:

#include "3rdparty/dtl/dtl.hpp"
#include <iostream>
#include <vector>

int main(int argc, char *argv[]) {
    std::vector<char> a = {'a','b','c','d'};
    std::vector<char> b = {'a','b','c','d','e','f'};

    std::cout << "a: " << "abcd" << "\n";
    std::cout << "b: " << "abcdef" << "\n";

    dtl::Diff<char,std::vector<char>> d(b,a);
    d.compose();
    d.onHuge();
    d.composeUnifiedHunks();
    d.printUnifiedFormat();

    return 0;
}

Output:

a: abcd
b: abcdef
@@ -2,5 +2,3 @@
 b
 c
 d
-e
-f

Does anyone know why the first element 'a' is not defined as common to sequences? Is there any way around this mistake without losing performance?

cubicdaiya commented 5 years ago

It's not a bug but expected behavior.

A diff with unified format is represented as a set of chunk and each chunk has common sequences up to N(>=0). N in dtl is 3. It's fixed.

cubicdaiya commented 5 years ago

FYI, GNU diffutils has the feature to change this number.

$ diff --help | grep "\-U"
  -u  -U NUM  --unified[=NUM]  Output NUM (default 3) lines of unified context.
wingunder commented 5 years ago

@cubicdaiya wrote:

A diff with unified format is represented as a set of chunk and each chunk has common sequences up to N(>=0). N in dtl is 3. It's fixed.

My PR #5, now enables the user to specify N, say 5, instead of the default 3: d.composeUnifiedHunks(5);