Project Home

The Almost Secret Features of xxdiff

Author: Martin Blais <blais@furius.ca>
Date: 2004-01-21

Abstract

A short exposť of some of the least-known or non-obvious features of xxdiff.

Table of Contents

Introduction

xxdiff has grown a number of little cool features that are not necessarily obvious from its user interface. This documents aims at presenting some of them together outside of the general documentation. (All these features are also documented in the user's manual.)

Horizontal Diffs

When there are small changes between lines, it can be laborious to quickly figure out exactly what has changed between them. An extremely addictive feature of xxdiff is that it can compute the diffs between pairs of matching lines, i.e. horizontal diffs. The differing parts are highlighted with a brighter color.

horiz.png

Checking for Strict Equality

When comparing a large number of files for merge review, we want to minimize the amount of time we spend on useless changes, and you will most likely enable the "ignore whitespace" features. Sometimes some automated scripts that will launch xxdiff will be lauching it on two files which have no non-whitespace differences. It is then impossible to "see" if the files are exactly the same or not (I mean, byte-for-byte the same or not).

equals.png

Sometimes it is important to know that, for example, before committing changes to a revision control system. For this purpose, you can check out the label over the overview area which will contain an equal sign (=) if there are no differences at all, not even whitespace differences. If you can see no visible differences and this marker is not present, this indicates that the files do differ, probably just in whitespace.

Number of Remaining Hunks

That little number of the overview area is the number of diff hunks that are unselected. You can save a merged result when all the hunks are selected, so this indicates the number of remaining hunks to resolve before you can save.

Selecting Text

In the context of merge reviewing, it is often useful to make comments on the code that is visible from xxdiff. You can use the Control key and mouse button 1 to select an arbitrary set of lines in either file, and that text is put into the clipboard. You can then cut-n-paste it in a text editor where you make your comments.

A red line appears to display the selection of text stored in the clipboard.

select.png

How the line is formatted can be configured with the resources to include the line numbers and some other things.

Per-Hunk Ignore Whitespace

Often in a context of looking at many changes, code reviewers get really annoyed with having to review formatting changes intermixed with code changes. Fortunately, some of these changes can be ignored by diff by ignoring the whitespace characters (and this is also supported by xxdiff) but this does not help for the cases when reformatting involves breaking lines.

In practice, if you're just re-formatting some code, it is often the case that only whitespace differences are appearing in a diff hunk. For this purpose, xxdiff has a special feature that de-emphasizes diff hunks that only differ in whitespace.

perhunk.png

The algorithm we use is really simple: given a diff hunk with text on both sides (i.e. a change hunk), we compare all the non-whitespace characters. If the entire hunks do not differ in that way, we de-emphasize the hunk to make it look like both regions are the same (using a gray color similar to the color for non-differing hunks). Those hunks are otherwise still selectable for merging.


(FIXME finish documenting the other features here)