An Improved diff3 Format for Changes and Conflicts in Tree Structures

Robin La Fontaine

Nigel Whitaker

Abstract

There are some pieces of software, and some formats, that are de-facto standards and have been around for decades. One of these is the diff3 format for representing changes and conflicts in text documents. Diff3 works well for unstructured text documents that are divided into lines. It works surprisingly well for pretty-printed source code and similar documents. But it has frustrating limitations when used for XML or JSON or similar tree-based data formats.

Can we improve on diff3 without making it too complicated? Can the existing representation of changes and conflicts be extended to handle tree-based data? This paper seeks to answer these questions and to describe how further benefits can be enjoyed by using XML or JSON as the basis for showing conflicts and changes.


Table of Contents

Introduction and Background
How diff3 Delimits the Extent of Changes and Conflicts
Preserving Well-Formed Tree Structure in diff3
Representing XML Element Tag Change in diff3
Representing XML Attribute Change in diff3
Representing JSON Structure Change in diff3
Representing JSON Separator Change in diff3
diff3 Format as XML or JSON
Nested Changes
Conclusions
References