# xxdiff documentation

Author: | Martin Blais
Contact: | blais@furius.ca
Date: | 2003-12-25
Copyright: | Copyright (C) 1999-2004, Martin Blais. All Rights Reserved.

Abstract

User's manual for xxdiff. The official location of xxdiff on the internet is http://xxdiff.sourceforge.net. If you're reading this page from the web, note that you can also access this document from the Help menu of xxdiff.

Table of Contents

# 1 Introduction

xxdiff is a graphical file and directories comparison and merge tool. This program is an essential software development tool that can be used to

- visualize the differences between files or directories;
- merge files with differences, resolving conflicts and saving output to a new file or patch;
- assist file changes reviewing and comment production (e.g. approving source code changes before they get merged into a source tree).

xxdiff doesn't itself compute the differences between files, it just displays them graphically (the rationale behind this is that you can use different tools to compute the actual diffs (for example using Rational ClearCase's cleardiff, which gives more sensible results than GNU diff in certain cases), there is a relatively standard format for difference output (POSIX diff), so it is easy and efficient to parse diff output from different programs, under the UNIX dataflow paradigm, it is common for graphical tools to be built on top of text tools. There are already many good tools to perform diffs, so there's no need to rewrite them.

# 2 Version

This documentation was generated for version:

<version/>

# 3 Invocation

Usage:

    xxdiff [OPTIONS] <file1> <file2> [<file3>]

You can specify either two files (two-way diff), three files (three-way diff), or two directories (directory diff).

You can also specify a mix of regular files and directories. If at least one of the paths specified on the cmdline is a regular file, all other paths that are directories will have the basename of the regular filename appended to them. For example, if you specify:

    xxdiff dir1/bn1 dir2/bn2 dir3

xxdiff will be run on `dir1/bn1`, `dir2/bn2`, and `dir3/bn1`.

xxdiff can accept one of its inputs from stdin. You must replace the relevant filename by '`-`' (a dash) to instruct xxdiff to use stdin for that file, e.g.:

    cat file2 | sort | xxdiff file1 - file3

If all the file paths are directories, a directory diff is invoked. Note that xxdiff doesn't do three-way directory diffs.

If the "unmerge" option is given, then xxdiff can only be invoked with a single file containing the conflicts.

## 3.1 Return Value

xxdiff returns the same values that diff(1) or diff3(1) return. See the respective man pages of those utilities for details.

## 3.2 Command-line Options

<invocation/>

Note that the last few options are provided compatible with common GNU diff options that the user might want to use, as a mere convenience. Note also that xxdiff options are a superset of the original xdiff options, so that xxdiff is compatible with old SGI scripts that use xdiff. xxdiff options follow the GNU conventions for command-line options.

## 3.3 Using xxdiff as a short-lived application

xxdiff has not been designed with the intent of being used over multiple sets of files over the course of one execution---that is, it has been built around the idea that you would execute it once over a single set of inputs, use it, then exit, rather than to open new files again using the 'file' menu features without exiting. The 'file' menu features are provided as a convenience, to allow one to occasionally replace one of the files during an execution. That is the reason why you can't open xxdiff with just one file. It is just not useful that way.

# 4 General operation

This section describes general features and operation of xxdiff.

## 4.1 The text area

xxdiff shows up with two or three text regions that display the text of the files to compare, with color-coded blocks that indicate regions of text (lines) that have changes (specific sections contain a list and descriptions on what types of change can appear). Each of these regions of text is called a "hunk" in diff terminology (for more about this, see the GNU diff manual). The text area can be scrolled vertically and horizontally, when necessary.

Corresponding regions of text are aligned between the files. Since changed regions do not necessarily contains the same number of lines, empty alignment lines are appended to the shorter regions in order to keep the corresponding lines aligned (this is a simple way of solving the alignment problem; an alternate solution would have been to implement a smart type of scrolling with lines indicating correspondance of regions between them).

All the colors can be individually configured using the display options dialog or resources. The display dialog contains a legend of all the colors. Note that the default colors for different regions are often set to be the same to other types of lines when it is not necessary to dissociate them, to avoid visual clutter. You could however, customize every region to be of a different color, for example, perhaps you would want to have the dummy lines drawn of a special color to indicate that they are not really part of the text.

In the text area, there is a cursor that in indicates the current line of text being worked on. This cursor can be optionally hidden.

### 4.1.1 Horizontal diffs

Each of the diff hunks is normally displayed in one color, but if horizontal diffs is enabled, for each line, xxdiff find the smallest differing part of the line that differs and displays that in a different, highlighted color. This allows the user to more quickly visualize exactly what has changed between the two lines of text. No need to mention, this is highly addictive and is now enabled by default. This is the "single horizontal diffs" mode.

When there are no more than two pieces of text on a single line, if the differing parts of the lines are not too long (e.g. less than 100 chars), the horizontal diffs can isolate the differences within the line. This is the "multiple horizontal diffs" mode. In this mode, we require that between horizontal changes, inserts or deletes, there be a minimal number of common context characters, so that the eye can make out what has change between the lines. This value is configurable (see resources section).

When computing horizontal diffs, changes in whitespace can be optionally ignored. However, if whitespace has been added in the middle of a word, it will still be highlighted.

### 4.1.2 Per-hunk ignore whitespace

Diff Hunks with text on all sides but with just whitespace or line break differences will be detected by xxdiff and marked with a special flag. If the feature is enabled, those hunks will be drawn of a different color, thus enabling the reviewer to quickly ignore those hunks. See the merge review features section for more details.

### 4.1.3 Navigation

xxdiff supports a subset of the emacs bindings, as well as support for most of the standard keys found on AT keyboards (PgUp, PgDown, arrow keys, Home, End).

Default bindings include:

- Ctrl-V, Alt-V: scroll up/down;
- Ctrl-N, Ctrl-P: move cursor one line up/down;
- Home, End: move cursor to beginning/end of files;
- N, P: move to next/previous diff hunk;
- B, O: mov the next/previous unselected diff hunk.

Explore the menus to find out about the other default bindings. You can customize all the key bindings using the resources.

### 4.1.4 Pop-up menu

Using the third mouse button in the text area brings a popup menu that contains cursor-sensitive commands, as well as the common commands to navigate between hunks.

### 4.1.5 Searching

You can search the text by bringing up the search dialog. Type your search query and press enter, which will apply the search and display diamond shaped match locations in the overview area. You can then navigate the search results using Ctrl-F and Ctrl-B. Searching will occur in all files simultaneously. You have to reapply the search to search for something else.

You can also move the cursor and display to a particular line from the search dialog.

### 4.1.6 Other options

Carriage returns (CR) characters in DOS files can be hidden in the text area.

Tabs by default are rendered aligned at each 8 characters, but can be set to any value by changing the tab width option.

### 4.1.7 Display options

The display options can be fully customized by bringing up the options dialog with the "Display -> Display Options..." menu item. From that dialog you can also customize the colors and fonts.

## 4.2 Redoing the diffs

If a file has changed while xxdiff is up, and there is need to recompute the diffs, invoke the "redo diff" command from the edit menu. The arguments used with the surrogate diff command can be changed by using the dialog provided by the "diff arguments" command. One can also replace a loaded file with a different one by using the "open" commands from the "file" menu.

## 4.3 Other UI elements

The following other UI elements can be optionally hidden or displayed from the Windows menu or Display menu (use the resource file to display or hide them on startup):

- Overview area. On the right side, an area that shows a color-coded pictorial rendering of the diff hunks for the whole files, with correspondances. This area also shows the as a rectangle the currently visible portion of text for each of the files. This rectangle can also be used as a scrollbar. In addition, a marker indicates the location of the line cursor.
- Remaining Unselected Hunks. Just above the overview area is a label that indicates the number of remaining unselected diff hunks between the files. In addition, if that number is zero, and if the files are identical byte-for-byte, it display a "(=)" string next to the number, so that you can figure out quickly if the files have any ignored whitespace changes or not (this can be important during merge review).
- Toolbar. A toolbar that gives access to the common motion and selection commands.
- Filenames. For each file, a region at the top that displays the filename. You can customize what shows up in this region from the command-line. Clicking on the filename puts it in the clipboard for cut-n-paste. (This label will intelligently display the end part of the filename if it is too long to fit.) This region also display the text line that the line cursor is in, for each file. You can customize what gets displayed in this labeled by using a command-line option.
- Line numbers. For each file, a thin window that display the number of each line (dummy alignment lines don't have any number).
- Vertical line. A vertical line can be drawn in the text area, at a specified column. This can be used for alignment purposes or for verifying that a line doesn't extend beyond a specified number of characters (many people like to limit their source code to fit in e.g. 80 characters).
- Merged view. A view of the file resulting from the currently selected regions (see section on Merged view below).

# 5 Comparing two files

When invoking xxdiff with two files, we normally think of an old and a new file, where:

    xxdiff old new

The default colors used here are symmetrical, so invoking the files in a different order will result in regions being assigned the same colors.

## 5.1 Types of hunks

The following hunk types can appear when comparing two files:

- Same: no change in that region;
- Insert: text has been added to the new file;
- Delete: text has been deleted from the new file;
- Diff: text has changed between the files.

Note that each Diff or Insert hunk is always separated by a Same hunk (if it was not the case, then two different contiguous hunks would necessarily get merged into a single Diff hunk).

## 5.2 Options

You can ignore trailing blanks, whitespace, or case for two-way diffs. See GNU diff(1) manual for information these features. xxdiff provides menu items to access these diff options. Those items simply add or remove switches to the diff program command-line and call the diff program again to regenerate the diffs.

Switches for GNU diff algorithm quality are also provided in the UI as a convenience.

# 6 Comparing three files

When invoking xxdiff with three files, we think of an ancestor file, a "mine" file, which the current user has been working on, and a "yours" file which someone else has merged in the main tree. They are normally specified in the following order:

    xxdiff mine older yours

The default colors used here are symmetrical, so invoking the files in a different order will result in regions being assigned the same colors.

## 6.1 Types of hunks

The following hunk types can appear when comparing two files:

- Same: no change in that region;
- Insert: text has been added one of the files;
- Delete: text has been deleted from one of the files;
- DiffOne: text is different in one of the three files but the two other files are the same.
- DiffAll: text is different in all of the three files.
- DiffDel: text is different in two files and is absent in the third.

## 6.2 Ignoring one file

In three-way mode, it can be useful to temporarily ignore one of the three files to concentrate on the differences between the other two. This feature is available from the Display menu and is performed by simply remapping colors at display time and doesn't require xxdiff to recompute the differences. The ignored file will be displayed as grayed out.

# 7 Comparing two directories

When invoking xxdiff with two directories, we normally think of an old and a new directory, where:

    xxdiff olddir newdir

The default colors used here are symmetrical, so invoking the files in a different order will result in regions being assigned the same colors.

Note

If you want to compare the files within directories all at once, use the `--recursive` option and you will get a single xxdiff with all the file differences. xxdiff accomplishes that by passing on the option to the subordinate diff program (e.g., GNU diff).

## 7.1 Types of hunks

The following hunk types can appear when comparing two directories:

- Same: files are present in both directories and have no differences;
- Insert: file has been added to directory;
- Delete: file has been removed from directory;
- Diff: files are present in both directories and have differences;
- Directories: directories are present in both directories but we don't know if they differ;

## 7.2 Options

The directories can be compared recursively, in which case no directories will be shown. You can activate this from the command-line or from the ui.

You can also instruct xxdiff not to display the files that haved changed, just the insertions and deletions.

## 7.3 File operations

In directory diffs mode, you can invoke an xxdiff on the pair of files or directories under the line cursor. This allows you to start xxdiff on a pair of directories, and then to examine the pairs of files that have changed, all from that directory diff. That functionality is available from the popup menu in the text area (right-click).

You can also copy and remove files from that menu, see Merging files and resolving conflicts section for details.

# 8 Merging files and resolving conflicts

Merging files is the process of manually resolving conflicts when two files cannot be merged automatically. This is a common problem when doing parallel software development where multiple developers could be working on the same files.

Most of the merging can be handled automatically, because if the changes were applied to fairly independent parts of the files, most of the changes will be insertions or deletions. However, when overlapping changes occur, no automatic decision can be taken.

xxdiff can be used to resolve conflicts by letting the user "select" which side of a diff hunk should be killed and what side should be kept. The user can take this decision on a line-by-line basis, and can decide to keep both sides as well, in any order. xxdiff then allows the user to save the resulting file.

## 8.1 Selecting regions

Selecting a diff hunk can be carried out by clicking on it. The colors update to display which side is selected for output. You can select individual lines with the second button. There are three types of selection that you can carry out:

- select clicked file;
- select no file (take the decision that nothing will be output);
- leave the line/hunk unselected.

If you want to select more than one side, you have to invoke the split-swap-join command (default is on 'S' key), which will split the current diff hunk if it's a Diff hunk so you can select the pieces you want from both sides. Further invocations of this command will cause swapping the regions, looping through all the different ordering possibilities, and finally joining the regions again (preserving selections where it is possible).

If you want to select individual lines, use the second button of the mouse on the lines that you want to select.

## 8.2 Saving the resulting file

The resulting file can be saved under one of the input filenames, under a computed "merged" filename, or under a new filename (from the File menu). The intended "merged" filename can be built from the input filenames and it's format can be specified through the resources file or the command line.

If some regions are left unselected, the save dialog will have some widgets that allows you to decide how you want to save the unselected hunks:

- Save as merge conflicts: save all sides, separating them with merge conflict markers similar to those inserted by CVS;
- Save with conditionals: save all sides, separating them with C pre-processor directives, so that you could then use a #define directive to have one set of changes or another be active if compiling.

The markers and pre-processor directives can be customized through the resources file.

There is a customization flag that lets you specify that xxdiff should warn you when trying to save with some regions unselected. It will bring the cursor to the first remaining unselected region and ask for confirmation. This can be used to insure that the user has made all the required decisions before saving and that no text will be forgotten.

You could also decide to save only the selected regions, from the File menu. This can be useful for making comments when reviewing merges.

### 8.2.1 Forcing Output of a Merged File and Better Script Integration

xxdiff is often used for merging conflicts, replacing some of the tools that are provided with popular configuration management systems. Sometime it is "required" that the conflict resolution tool output the merged file. To that extent, xxdiff has a special mode triggered with the option `--decision` to address specifically that need. When specified, the exit functionality is replaced with three functions:

- exit with ACCEPT: the string "ACCEPT" is printed on stdout. The left file is automatically saved into the merged file;
- exit with REJECT: the string "REJECT" is printed on stdout. The right file is automatically saved into the merged file;
- exit with MERGED: the string "MERGED" is printed on stdout. If there are remaining conflictual hunks when exiting, a popup will ask how to deal with them, you are forced to make a selection on all the hunks.

We want to allow for a fast process where the user is presented with a series of xxdiffs and has to make decisions on each. The calling script can then do whatever is required to integrate the resulting file into its workflow.

If the window is killed, the merge file is not saved and NODECISION is output (the script that calls xxdiff must be prepared to deal with that somehow). Also, note that you are responsible for deleting the merged file. Also in this mode, if the merged file already exists, it gets overwritten without warning.

## 8.3 Rapid, sequential merge conflict resolution

Some people like to merge files within a guided process, where the visual diff program asks for a merge decision for each conflictual hunk one-by-one and then asks for a filename to use for saving the merged output. For example, that is how ClearCase's xcleardiff works when querying the user to resolve conflicts.

There are a set of commands under the Region menu that allows one to rapidly take decisions on merge conflicts. These commands perform a selection and then automatically move the cursor to the next unselected region. If there are no more unselected regions, the save dialog is brought up automatically.

## 8.4 Automatic merge

By default, xxdiff doesn't perform any selections. You can instruct xxdiff to perform the initial selection of the non-conflictual regions automatically. This can be specified from the command-line or from the Global menu.

Just like xxdiff can be instructed not to show up if there aren't any differences between the files, xxdiff can also be instructed not to show up if after the automatic merge there remains no conflictual regions. You can use the return value to find out.

(Note that we do not want to add a feature to xxdiff to allow it to output to the merged file if there are no conflics, because that would amount to make xxdiff a non-graphical tool, while its mandate is to use such tools underneath and display their output. Besides, that would be the single case where xxdiff writes to a file without a file dialog. You can very easily implement this from within a script using the return value of either diff or xxdiff.)

### 8.4.1 Requiring an output file

Sometimes we want to force the user into producing a merged output file (when calling xxdiff from an update script, for example). Thus there is a feature to put xxdiff in this mode (see resources or invocation section). In this mode, the user must save before exiting xxdiff (exiting will prompt for save filename).

## 8.5 Merging directories

Selecting is disable in directory diffs mode, where the concept of "saving" a directory does not really make sense. However, you can apply changes to a directory from xxdiff, such as copying and removing files under the line cursor. This can be invoked from the popup menu in the text area.

## 8.6 Merged view

During selection or before saving the selected regions into the result file, you might want to visualize what it would look like with the current selections. You can display the "merged view" for this purpose, an dedicated window showing the merge output, that updates interactively as you make selections.

This view will scroll to match the main display. Unselected regions are shown in this view with oblique lines ("in construction" style), and merge decisions are slightly highlighted as well. This output allows you to review the merge decisions before commiting the file to output.

# 9 Merge review features

One of the most important uses of xxdiff is to assist the merge review process, where one developer visualizes the file changes of another and approves or rejects those changes, making comments along the way.

For this purpose, xxdiff puts selected text (i.e. when you click on a diff hunk) in the clipboard text buffer when you select it. Thus, the merge cop can select a region, and paste the results in a neighboring editor window.

These snippets of code will typically be interspersed with comments. xxdiff can be format the line contents before they are copied to the clipboard, to make them distinct from the merge comments. This can be enabled using the "format clipboard text" option. The clipboard line format is a string that contains format specifiers similar to printf for each line to be formatted prior to being put on the clipboard. The following specifiers are allowed:

`%N`
  file line (0 is leftmost file)
`%L`
  line number
`%F`
  filename
`%s`
  line contents

There is also a "clipboard header format" resource for adding the filename at the top of the copied text. This is useful for quickly pasting into a merge comments file.

Also note that clicking on the filename labels will put the filenames in the clipboard for similar cut-n-paste action. This can be useful when reviewing ClearCase revision files, which often have very long p-names.

## 9.1 Variable text selection

You can press ALT and Button1 to select an arbitrary number of lines. The selected lines will be marked with a special border to show what gets put in the clipboard. This is very useful when you don't want to quote an entire diff hunk, or a section of text that straddles hunks.

## 9.2 Per-hunk ignore whitespace

Many source code changes often just reindent or reorganize blocks of code, and result in many isolated hunks with no relevant changes to look at (for languages that don't use whitespace semantics anyway). For merge police duties, this can lead to more work to review changes, and typically, programmers (and groups, sometimes) will explicitly choose not to allow code beautification because of that very reason (...and the directed anger of merge cops themselves). xxdiff now has a new feature that alleviates this problem greatly: it will scan each diff hunk for non-whitespace changes, and if the only changes are of whitespace, it will mark the hunk with a special flag. The "ignore per-hunk whitespace" feature will draw these hunks with a different color, by default, a color very similar to the "same" hunks. The hunks are not ignored, however, as skipping from hunk to hunk will still stop at these hunks, but they can be very quickly ignored by the merge police. So go on ahead now, and reindent that code without fear.

# 10 Unmerging merge conflicts

Unmerging merge conflicts is a special input mode of xxdiff where a single file containing the result of an automatic merge of two files is split into two files and displayed as such.

This may sound like a "trava lengua", but unmerging merge conflicts can be a very useful feature, if you like to let your source code management system automatically perform merges and save the output without user intervention, such as the way CVS is normally used. Typical use of the CVS update command will merge the main branch changes into your local copy files. When there are conflicts, your files are modified to contain both your changes and the main branch changes in the regions that conflict. CVS inserts text markers such as the following to indicate the conflictual regions:

    Some merged text.
    >>>>>>>> MYFILE
    I added this.
    ========
    This line added in main branch.
    <<<<<<<< 1.1
    Some finetext.

Then, the user is notified of the conflictual files, and has to go inspect the conflicts and resolve them by editing the file accordingly. The problem is that it is often quite difficult (and unpleasant) to figure out exactly what happened during the automated merge process, without the original files (note that CVS does make a backup copy of your file before writing it over with the merged output, see CVS manual for details).

To help in figuring out what happened during merge and in performing the user-directed selections, xxdiff can be invoked in "unmerge mode" with the file containing the merge conflicts. It parses the file and generates two files from it, displaying them with differences. You can then perform selections as usual to produce the final merged file.

Note that we think that this is not the best way of resolving conflicts, rather just a useful feature for people who like to work this way. A better way to merge would be to use your source code management system to fetch the common ancestor revision, the latest/head of the main branch and to invoke xxdiff with your file, the ancestor and the latest/head. You can also tell xxdiff to initially perform all non-conflictual selections automatically.

## 10.1 Unmerging merge conflicts with three files

diff3 can be used to produce a merged file in which all the three files' regions are shown if there is a conflict. xxdiff can also parse these files and display them as a three-way diff. You then have to invoke xxdiff with the 'unmerge3' command-line argument to let it know you want the file split in three.

# 11 Editing files

There has been a conscious decision NOT to develop xxdiff into a fully-featured editing program. Sometimes it could be handy to be able to edit a few lines of a difficult conflict. However, that is a task best left to your own favorite editing program. Saving with merge conflicts will allow you to resolve those few remaining conflicts by hand.

However, a few commands have been provided under the File menu to spawn an editor on the input files. You can then redo the diff after your input file has changed.

# 12 Customization using resource file

Much of the state of xxdiff can be customized through a resource file (actually, some of the features can only be changed through resource customization). By default, xxdiff looks for the file `.xxdiffrc` located in the user's home directory (this file location can be overriden by setting the environment variable XXDIFFRC), and reads that file for resource definition.

The format of the resource file is a fairly simple list of colon-separated resource name/value pairs, one per line:

    resourceName: "value"

Any text after "#" on a line is considered a comment and ignored.

Some resources may require string delimiters (double-quotes) around their value specification, but not all (see below).

You can also specify additional resources on the command-line, which take precendence over the resources specified in the resource file. To get a complete list of the available resources, use the `--list-resources` command-line option (see Options section).

Trick: you can use different resources files by invoking xxdiff like this in most shells:

    XXDIFFRC=myrcfile xxdiff file1 file2

## 12.1 Automatic generation of the resource file

You can generate a resource file containing only the differences from the defaults from the "File -> Save Option..." menu command. This can be used to "save" the current customizable options into `~/.xxdiffrc`.

# 13 Resource reference

This section contains a reference of the all the currently supported customizable resources in this version of xxdiff.

<resourceref/>

# 14 Frequently Asked Questions (FAQ)

## 14.1 Can I diff files with CRLF DOS characters in them?

If you want to diff files with CRLF characters in them, you can use the 'ignore whitespace option to GNU diff, which will work, even if only one of the files has the DOS characters in it.

## 14.2 How do I make xxdiff display the revision number of a file?

By default, the filenames window display the filename. From the command-line, however, you can set it to display an arbitrary string, which could include your current revision number.

# 15 Author

This program has been written from scratch and is being actively maintained by Martin Blais (blais@furius.ca).

# 16 Reporting bugs

All bug reports and feature requests should be submitted throught the SourceForge bug tracking system at the following URL http://sourceforge.net/bugs/?group_id=2198. Please avoid sending the author email about xxdiff bugs. Please use this bug tracking system, it is extremely fast and simple to use.

# 17 Project history

This program has been written and inspired after gdiff, mgdiff, and Rudy Wortel's xdiff under SGI. xxdiff aims to provide a lasting open-source replacement to these programs. Writing this tool from scratch was originally motivated by the need to have horizontal diffs, which turned out to be an essential feature of this program.

This program is being extensively tested by several software development engineers at discreet, that use it daily in their merge reviewing activities. It has reached a stable state.

## 17.1 Licensing

This program is distributed under the GNU General Public License. See the GNU project website for full details.

## 17.2 Dependencies

This program depends on the availability of a textual diff program (such as GNU diff) and the Qt UI toolkit (available at http://trolltech.com).

## 17.3 Acknowledgements

Thanks go to discreet, for letting me deploy my program there, and for not bothering me with the occasional bug fix that I did on the job. Many more thanks to all the many engineers who tested it there and reported problems with it, as well as providing invaluable suggestions.

SourceForge is hosting my web site and I'm using many of its features. Tomas Pospisek (tpo at sourcepole.ch) has provided a Debian package. Dan Weeks has packaged it for one of the BSD variants (danimal at danimal.org). Not sure, but I think that Christian Savard (savardc at pobox.com) provided the original Gentoo port (xxdiff is now supported in Gentoo).