Releases: lassevk/DiffLib
2025.0.0 - Breaking change, .NET 8 and 9 support
This release signifies a breaking change.
Several types have been made into records and/or structs, as well as some namespace changes.
Additionally! All MERGE-functionality has been ripped out as it has serious bugs and needs a complete rewrite. I cannot guarantee it will make it back into the library, depending on whether I can figure out how to implement it correctly!
The major reason I am releasing this is that the older version comes with dependencies that are flagged as security risks. The new version only targets .NET 8 and 9.
One additional feature has been implemented, the DiffOptions record now contains a ContextSize
property. The default value is 1, which makes the library behave as it always have, but if you increase this value, diffs need to have more elements in sequence that compare equal before a new synchronization point is found.
This is most useful when dealing with raw text, as there will be fewer single-character replacements when you have replaced a whole word. A good value for text comparisons is 3 if you want a more "real" diff for raw text.
For older versions of .NET, the older package is still available on Nuget, but will receive no new changes.
Version 2017.7.26.1241
Added new target platform monikers for the following platforms:
- .NET 3.5
- .NET 4.5
- .NET 4.6
- .NET 4.7
This in addition to .NET Standard 1.0 that was already there.
This release now creates .NET Platform versions of the assembly to avoid polluting project references with a ton of .NET Standard shim assemblies when the project is targetting .NET Framework and not .NET Standard/Core.
Version 2017.5.21.1535
Following is new in this release:
- Added missing "TakeRightThenLeft" merge conflict handlers
- Fixed missing suffix "MergeConflictResolver" on a couple of the merge conflict resolvers
- Fixed bug in LongestCommonSubsequence implementation which did not use the provided EqualityComparer for hash code calculation
- DiffElement now provides the index of the two elements (thanks hali15845)
Version 2017.5.1.1345-beta
This beta-release simply adds an extension method based on the diff operations that can be used to mutate lists.
A typical scenario is that you have a list that you want to mutate such that it has the same items as another collection. However, since something is observing changes to the list you want to mutate, you don't simply want to clear it and re-add all the elements it is supposed to have. Instead you would like to insert new elements in the right places and remove elements that should no longer be there.
The new extension method does just that:
It is called by:
(List<T> variable).MutateToBeLike(otherCollection, optionalComparer, optionalElementAligner);
In its simplest form:
(List<T> variable).MutateToBeLike(otherCollection);
It will take elements from otherCollection
and insert into your list in the right places, and also remove items from your list if they should no longer be there.
Version 2015.7.24.1614
Complete rewrite from v2014.2.
No longer two different methods and sets of classes for dealing with unaligned and aligned diffs. Unaligned diffs are now called "sections" and aligned diff produces "elements".
There's also some performance improvements, due to simplifying some of the code.
Also made it possible to plug in new alignment strategies via an interface and let the main diff system do the rest of the heavy lifting. Basic alignment strategies are provided as well as one that uses similarity matching to produce the alignment that has the highest similarity rating.
Note that this release is not backwards-compatible with the old one in terms of API and syntax. If you upgrade from v2014.2 to this, you will need to change your code to accommodate the new classes and the new API.
The library is available for download/installation via Nuget, just do a search for difflib
. Here's a direct link to Difflib on Nuget.
Version 2017.4.24.2347
This release adds 3-way merge functionality to DiffLib.
It is based on common base, left, right type of merges, similar to what you would encounter in most version control systems that support any kind of branches and/or merging.
Let's see how to use it.
You have to supply the following parameters to Merge.Perform
:
- The common base, this is considered to be the content of the collection before either side changed it
- The left side, this simply one of the set of changes (compared to the common base) that you want to merge
- The right side, again compared to the common base this provides a set of changes you want to merge
- A diff element aligner (
IDiffElementAligner<T>
implementation) - A conflict resolver (
IMergeConflictResolver<T>
implementation), this is new so described below - Optionally a
IEqualityComparer<T>
comparer as usual
Here's what will happen:
- Common base will be compared with left
- Common base will be compared with right
- The two sets of diffs will be compared, using the common base items as synchronization points
This now gives us matching changed elements from both left and right simultaneously. We now analyze what happened to them in each respective diff and decide how to handle the change.
In the scenarios where conflicting edits have been made, such as left side deleted an item and right side modified it, the conflict resolve will be asked what the end result should be.
The conflict resolver will be given items from the common base, left side, and right side, and have to produce the final set of items this conflict should end up with.
For instance, to simulate the git merge -s ours
strategy, and left
means ours
, you would simply return the left items. If you want to simulate something like take left then right
you would concatenate the two and return them.
There are a couple of basic implementations built into DiffLib:
TakeLeftMergeConflictResolver<T>
, always takes left side and discards rightTakeLeftThenRightMergeConflictResolver<T>
, always take both sides, left firstTakeLeftThenRightIfRightDiffersFromLeft<T>
, take both sides if they differ, otherwise take left (and I notice here that I have gotten the name of the type wrong, will be fixed in an upcoming release)TakeRightMergeConflictResolver<T>
, similar to the left version, just always takes right and discards left
v2017.4.9.2148
New in this release:
- Now supports .NET Standard 1.0 and upwards instead of an odd mix of portable formats
- Minor tidying up of internal files and refresh of project after it had lapsed for a long time
Version is now available on nuget.