Is there a way to diff files from C++?

谁说我不能喝 提交于 2019-11-28 04:31:44
Matt Fichman

I think I've found a good solution, finally:

The DTL - Diff Template Library --- Tutorial

It supports patch. I had to type "diff.cpp" into Google to find it. Hopefully it works!

It seems like the Google Diff, Match and Patch libraries are what you need.

This is an implementation of a "solution to SES/LCS with the Hirschberg linear space refinement as described in the following publication":

E. Myers, ``An O(ND) Difference Algorithm and Its Variations,'' Algorithmica 1, 2 (1986), 251-266. http://www.cs.arizona.edu/people/gene/PAPERS/diff.ps

Found it on the Wikipedia page on diff.

That's only for finding a diff though, not applying it as a patch. I think that application of a patch is actually a harder problem; due to the risk of conflicts. It would need some form of user-controlling feedback mechanism, to resolve conflicts.

There is one that is part of Mercurial. It exists as some C code that's designed as a Python extension, but it could probably be extracted pretty easily. I believe it can also do binary diffs.

The relevant .c files are mercurial/bdiff.c, mercurial/mpatch.c and possibly mercurial/diffhelpers.c.

Subversion includes a library libsvn_diff.

Also pretty much unfindable in Google, it turns out that Gnulib has a diff module. This one seems sufficient for what I wanted a diff library for. It doesn't seem to have a patch module, though.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!