GNU TeXmacsUser manualReferenceAboutEnglish
Versioning and document comparison

1.Introduction

TeXmacs has three different notions of “versions”, which should not be confused:

  1. The undo/redo history of a buffer, maintained in C++ by the archiver class (

    Data/History/archiver.hpp

    ). It lives in memory only and is described together with patches in Live documents and shared editing.

  2. Versions of files managed by an external or remote system: the version control systems Subversion and Git for local files, and the server side version lists for remote files (see the remote file system). TeXmacs gives a uniform interface to browse histories, open old revisions and commit.

  3. The structural comparison of two documents, which produces a document with special markup for the differences, and the commands for navigating through the differences and retaining one of the versions.

This page covers the last two points. All code lives in

progs/version/

.

2.The generic versioning interface

2.1.Dispatch

version/version-tmfs.scm

defines a set of generic functions which are overloaded, using tm-define with a :require clause, by each back-end:

(version-tool name)
(versioning tool of a file)

Returns "svn" if a .svn directory exists in one of the ancestor directories of name, "git" if a .git directory exists, "wrap" if the URL wraps a versioned URL (url-wrap), and #f otherwise. The result is cached per file in version-tool-table, and the corresponding back-end module (version-svn or version-git) is loaded the first time it is needed. (versioned? name) tests whether there is a tool.

The functions to be provided by a back-end are:

(version-status name)

One of "unknown", "modified" or "unmodified".

(version-history name)

A list of (rev by date msg), or #f.

(version-revision name rev)

The contents of the file at revision rev, as a string.

(version-beautify-revision name rev)

A short form of a revision for display (Git hashes are truncated to seven characters).

version-update, version-register, version-unregister, (version-commit name msg)

Operations of the Subversion style interface; they return a message to be displayed.

version-supports-svn-style?, version-supports-git-style?

Which of the two interfaces the menu should offer.

The buffer level commands update-buffer, register-buffer, commit-buffer and commit-buffer-message call these functions and display the result; version-interactive-update and version-interactive-commit first save the buffer (save-buffer with the options :update and :commit). The menus are in

version/version-menu.scm

(version-menu, version-compare-menu).

2.2.tmfs classes for histories and revisions

tmfs://history/url

A generated page with the history of a file (version-show-history), with a link to each revision.

tmfs://revision/rev/url

A file at a given revision; its load handler returns (version-revision u rev). version-revision?, version-get-revision and version-head decompose such URLs, and version-revision-url builds them.

tmfs://commit/rev/root, tmfs://git/which/root

Pages for a Git commit (message, parents and diff statistics) and for the global status and log of a Git repository.

For remote files,

client/client-tmfs.scm

overloads the generic functions so that the history is the server side version list and revisions are time= URLs.

2.3.The Subversion and Git back-ends

Both back-ends simply run the command line tools with eval-system and parse their output.

2.4.Adding a back-end

To support another system, add a detection predicate to the cond in version-tool together with the name of the module to load, and write a module which overloads the generic functions above with (:require (== (version-tool name) "tool")). The history, revision and comparison facilities then work unchanged.

3.Comparing documents

3.1.Version markup

The result of a comparison is an ordinary document in which each difference is represented by one of the tags of the group version-tag (

version/version-drd.scm

):

version-both

Two arguments, the old and the new content, shown one after the other (using version-both-small for inline content and version-both-big when the old content is a document).

version-old, version-new

The same two arguments, but only the old resp. new content is shown; the other one appears in a balloon when the cursor enters the tag.

version-suppressed

A placeholder for an absent content (inserted or deleted material), rendered as a cross.

The macros are defined in

packages/standard/std-fold.ts

, and the colors are given by the environment variables old-version-color and new-version-color. Since the three tags form a variant group, the user can cycle between them.

3.2.The comparison algorithm

(compare-versions t1 t2) in

version/version-compare.scm

takes two Scheme trees and returns a merged tree. It works recursively:

The comparison is a heuristic tuned for text documents; it is not an optimal edit distance and it does not detect moved blocks.

3.3.Commands

(compare-with-older old), (compare-with-newer new)
(compare the current buffer with another file)

Load the other version with tree-load-inclusion, compare, replace the current buffer by the merged document, and move to the first difference. compare-with-newer* compares with an already open buffer. For versioned files and revisions, the submenu Compare with (version-compare-menu) lists the revisions of the history and chooses between the two functions with version-newer?.

(version-first-difference), (version-next-difference), …
(navigation)

Move to the first, previous, next or last tag of the group version-tag.

(version-show tag), (version-show-all tag)
(change the display of differences)

Replace the innermost difference, the differences in the selection, in the current paragraph (version-show-paragraph) or in the whole buffer by version-old, version-new or version-both.

(version-retain which), (version-retain-all which)
(resolve differences)

Replace differences by one of their versions: 0 for the old one, 1 for the new one, or 'current for the one which is displayed (the new one for version-both). Suppressed content is removed, and the surrounding concat and document are normalized. This is the only form of “merging”: there is no automatic three-way merge.

reactualize-differences recomputes the comparison inside the current difference or selection, for instance after the user edited one of the versions or changed the grain. The keyboard shortcuts are defined in

version/version-kbd.scm

.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".