Переписан для обычного diff

This commit is contained in:
Alexander Zhirov 2025-09-01 02:02:13 +03:00
parent ef491965f6
commit e7d16e6969
Signed by: alexander
GPG key ID: C8D8BE544A27C511
7 changed files with 212 additions and 15 deletions

View file

@ -1,17 +1,20 @@
import std.stdio;
import libxdiff : MMFile;
import libxdiff;
import std.conv : to;
import std.stdio : writefln, writeln;
import std.file : read;
void main()
{
auto a = MMFile.fromBytes(cast(ubyte[]) "hello world\n");
auto b = MMFile.fromBytes(cast(ubyte[]) "hello world!\n");
auto file1 = new MMFile(cast(const(ubyte)[]) read("/tmp/diff1.d"));
auto file2 = new MMFile(cast(const(ubyte)[]) read("/tmp/diff2.d"));
auto patch = a.computePatch(b);
writeln("patch size: ", patch.size());
auto patch = file1.computePatch(file2);
auto res = a.applyPatch(patch);
writeln("apply success: ", res.success);
writeln(res.patched.asSlice()); // печатаем результат
// печатаем как есть (включая заголовок @@ и строки с '-'/'+' и '\n')
write(cast(string) MMFile.fromBlocksMoved(patch).asSlice());
writeln(patch);
writefln(
"file1: %s\nfile2: %s",
file1.size, file2.size
);
}