distributed version control systems.

DVC Intro
*********

       Copyright (C) 2007 - 2011 Stephen Leake
       Permission is granted to copy, distribute and/or modify this document
       under the terms of the GNU Free Documentation License, Version 1.2
       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''.

Overview
********

DVC is a common interface to several extremely powerful and flexible version control systems, such as Gnu arch, monotone, bzr, and others (known as 'backends' to DVC).

DVC provides the same (or at least similar) user interface for each backend, making it easier to use multiple backends in related projects. It also automates some tasks, and provides guidance to the user as to what needs to be done.

DVC is not included with the standard Gnu emacs distribution. It is provided in source form via a bzr repository (see Installing).

If you are not already familiar with version control systems, please read Basic DVC.

One of the most important features of the DVC user interface is that it identifies what files in a project need attention of some sort; you have changed them in your working directory, or someone else has changed them in the repository, or they've been deleted or are new, etc. DVC presents a list of all such files, and makes it easy to see what needs to be done for each file.

When committing files, ediff is used to allow reviewing the changes, so an appropriate change comment can be written.

DVC replaces the command-line interface to the backends for the most common operations, but it is still necessary to use the command line at times. Creating a repository, starting a project in a repository, and managing branches require command line operations.

This manual describes the DVC user interface, and gives examples of some required command line operations, using the monotone backend.

It also describes some DVC extensions that are specific to the monotone backend.

Basic DVC
=========

Here we give a brief introduction to general concepts of distributed version control systems, focusing on the concepts that are needed to use DVC, and providing common terminology.

Each backend will have its own documentation, and terminology that differs from this. The terms here are taken mostly from the monotone backend.

Let's start with some definitions:

workspace
     Each user has a workspace, containing a copy of the files she is working on. This is typically a directory tree. In the root directory of the tree there is typically a directory containing backend control files, used only by the backend.

database
     The database stores copies of all files in the workspace (and typically more than one workspace), together with all of the change history and other meta-information. The database is never edited directly; only the backends modify it.

local database
     A database on the user's machine. This database is used to control all workspaces on the user's machine.

remote database
     A database on a remote machine. This may be another user's local database, or a central database set up specifically for sharing files. The user interacts with the remote database in order to retrieve other user's files, or deliver files to them.

revision
     The state of the entire workspace, usually including the set of changes to the workspace that transform it from the previous revision. Most operations on the database involve revisions, and all changes to files are part of a revision.

branch
     A label for distinct trees of revisions. There are two main uses for branches; parallel development on a single project, and completely separate projects. Branches of a single project are typically merged back together (this is called ``propagating''), while completely separate projects are not.

     A database can store any number of branches.

heads
     The revisions that are the leaves of the history tree on a single branch. In monotone, there can be any number of heads on a branch (see Merging).

merge
     The process of combining multiple heads of a branch into one head. This can encounter conflicts that require user resolution; see Merging.

propagate
     One branch can be ``propagated'' to another. This is a form of merging; it merges all the changes from one branch into another, starting from their common ancestor (which is usually the previous propagate between the two branches).

     This is how changes in a development branch are promoted to the main branch.

     Since propagating is a form of merging, it can encounter all of the same conflicts that merging can.

*dvc-status* buffer
     A main user interface buffer. It shows all files in the workspace that need attention. Single keystrokes invoke various operations. See Status Display, for more details.

     The name of the buffer is not literally *dvc-status*; instead, dvc is replaced by the backend name; xmtn for monotone, bzr for bzr, etc. But in this document, we will use the name *dvc-status*.

*dvc-diff* buffer
     Another main user interface buffer. It shows the files changed in a particular revision, together with the diffs of the changes. Single keystrokes invoke various operations.

Users edit files in their workspace, then use DVC to synchronize the workspace with the local database. Later, they use the command line to synchronize their local database with a remote database. This allows each user to make changes locally but still under change control, without affecting other users until they each choose to synchronize.

Compare to CVS
==============

Since many people are familiar with the CVS version control system, we compare that with DVC, and monotone in particular.

In CVS, each file is committed separately; in DVC, all files in a workspace are committed together. This makes sure that all changes that are related are committed together.

This means the commit log message mentions all files that have changes; it is a much longer message, but there are fewer of them, and the message can more easily describe changes that affect more than one file.

In CVS, you must always have access to the remote server. In DVC, you work with a local database, then separately sync that database with a remote server. Thus DVC is useful when not on a network; monotone can even sync via USB disk rather than a network connection.

This means there are two steps to syncing a workspace with the central server, which can be annoying. On the other hand, the sync process syncs all projects in the database at once; with monotone, it lets you know what projects have changes.

Otherwise the primary Emacs interface to CVS and DVC are very similar, although DVC has many secondary interfaces that CVS does not have.

Installing
**********

Install bzr; see http://bazaar.canonical.com/en/.

Retrieve the DCV source; see https://gna.org/projects/dvc#options for general information.

In a bash shell:

     cd ~
     bzr get http://bzr.xsteve.at/dvc/
     cd ~/dvc
     autoconf
     ./configure
     make

In your .emacs, add (load-file (expand-file-name "~/dvc/dvc-load.el"))

Invoking
********

Before invoking DVC, you may want to ensure that the local database is synchronized with the central database, via a backend-specific command line.

You typically invoke DVC with the Emacs command dvc-status or dvc-diff. This prompts for a workspace; it should be the top level directory in your working directory tree.

You can also create shortcuts in text files to invoke dvc:

     (dvc-status (expand-file-name "~/dvc"))
     (dvc-diff nil (expand-file-name "~/dvc"))

These can be executed with C-x C-e, and are a handy way of keeping track of several workspaces.

dvc-status or dvc-diff run the corresponding backend command, comparing the workspace against the local database, and presenting the information in the *dvc-status* or *dvc-diff* buffer.

For monotone, there are higher-level starting points:

xmtn-status-one
     Summarizes the status of one workspace.

xmtn-status-multiple
     Similar to xmtn-status-one, but shows all workspaces immediately under a root directory.

xmtn-propagate-one
     Supervises propagating one workspace.

xmtn-propagate-multiple
     Supervises propagating several workspaces.

     <<<<<<< TREE =======

xmtn-sync-sync
     Syncs the local database with a remote database, then runs xmtn-sync-review.

xmtn-sync-review
     Reviews saved output of a command-line mtn automate sync, displays branches that have been transferred. This is useful for syncs <<<<<<< TREE that take a long time, because external commands display the tickers much better than DVC does.

     The external sync should redirect stdout to ~/.dvc/sync.basic_io.

     >>>>>>> MERGE-SOURCE ======= that take a long time, because the command-line displays progress tickers. >>>>>>> MERGE-SOURCE

xmtn-status-one
===============

Summarizes the status of one workspace, in a xmtn-multi-status buffer. The branch name is shown, followed by possible appropriate actions. As each action is performed, it is replaced by the next action, until there are none left.

Similarly, xmtn-status-multiple shows the status of all workspaces immediately under a root directory.

Actions are invoked with M-d.

The possible actions are:

need-refresh
     Shown while the backend is computing, or the user is performing operations in an associated *xmtn-multi-status* buffer.

commit
     Open an *xmtn-status* buffer to commit changes.

resolve conflicts
     Open an *xmtn-conflicts* buffer to resolve conflicts; see Merging.

show heads
     Open an *xmtn-revlist* buffer to show the current head revisions.

merge
     Perform the merge, using the conflict resolutions.

update
     Update the workspace to the current head revision (must be merged).

update preview
     Open an *xmtn-revlist* buffer to review the revisions that will be included in the next update.

update review
     Open an *xmtn-revlist* buffer to review the revisions that were included in the most recent update.

ignore local changes
     Don't show commit.

refresh
     Recompute the *xmtn-multi-status* display.

clean/delete
     Delete conflicts and conflict resolution files, and delete the workspace from the display.

xmtn-propagate-one
==================

xmtn-propagate-one supervises the process of propagating from one workspace to another, in an xmtn-propagate buffer.

The display shows one source and destination branch pair, and possible appropriate actions. As each action is performed, it is replaced by the next action, until there are none left.

Similarly, xmtn-propagate-multiple supervises the propagation of all workspaces immediately under two root directories. This is useful when several related projects branch together.

In the list of actions, ``from'' stands for the name of the source branch, ``to'' the name of the destination branch.

Actions are invoked with M-d.

The possible actions are:

status ``from''
status ``to''
     Start an xmtn-multi-status buffer for the specified workspace, to allow commit, update preview, or merge with conflict resolution.

update ``to''
     Update the specified workspace to the current head revision (must be merged). This bypasses the xmtn-multi-status buffer, and therefore does not provide for update preview. It does allow for update review.

ignore local changes ``from''

ignore local changes ``to''
     Don't show need commit; assume the workspace is committed. Useful when you know that any local changes won't interfere with the propagate.

resolve conflicts
     Open an *xmtn-conflicts* buffer in the destination workspace to resolve propagate conflicts; see Merging.

propagate
     Propagate the branch pair, using the conflict resolutions.

refresh
     Recompute the display. If prefixed with C-u, force examining workspaces for local changes.

clean/delete
     Delete conflicts and conflict resolution files, and delete the workspace from the display.

<<<<<<< TREE =======

xmtn-sync-review
================

xmtn-sync-review supervises the process of updating local workspaces after a command line operation that synchronizes the local and remote databases.

The command line operation should redirect stdout to ~/.dvc/sync.basic_io. Most users will want to define shell functions to invoke common syncs. For example:

         mtn --db ~/monotone-dbs/gds.db automate sync --ticker=count "ssh:user@host/gds.db?*" >> ~/.dvc/sync.basic_io

The xmtn-sync-review display shows each branch that was transferred, with a count of how many revisions were sent and received.

The user may set the variable xmtn-sync-sort to a function that indicates how to order the branches in the display.

Actions on branches are invoked with M-d.

The possible branch actions are:

status
     Start an xmtn-multi-status buffer for the workspace assoicated with the specified branch, to allow commit, update preview, update followed by update review, or merge with conflict resolution.

     The user may set the variable xmtn-sync-guess-workspace to a function that returns a workspace given a branch. Otherwise, the user is prompted for the workspace location; the location is cached for future use.

update
     Start an xmtn-multi-status buffer for the workspace assoicated with the specified branch, then perform update (if appropriate). This is often convenient when you know the workspace has no local changes.

brief
     Show the first line of the changelog for each revision received.

full
     Show the complete changelog for each revision received.

clean
     Delete the branch from the display.

     Branches that are not cleaned are cached; they will reappear the next time xmtn-sync-review is run.

In addition, there are global actions:

next
     Move to the next branch

prev
     Move to the previous branch

save-quit
     Save the displayed branches, quit.

save
     Save the displayed branches.

>>>>>>> MERGE-SOURCE

Status Display
**************

After invoking dvc-status, you are presented with the *dvc-status* buffer.

The detailed format differs depending on the backend. This presentation is close to the bzr and mtn formats.

The buffer contains a header, such as:

     Status for c:/Projects/GDS/common/main/:
       base revision : e946839c833b15e6bf12bd1536764e1106c41924
       branch        : common.main
       branch is merged
       base revision is a head revision

The last two lines are important; either may have ``not'' in it.

If the branch is not merged, it must be merged before an update can be done; see Merging. However, commits can be done when the branch is not merged; this allows saving work before attempting the merge.

If the base revision is not a head revision, there are updates that need to be applied to the workspace. The updates may be reviewed first using M m; they may be applied using M u.

In the main body of the buffer, there is one line for each file in the workspace that needs attention. For example:

      * modified      hardware/gds-hardware-pmrd_wrapper.adb
        unknown       build/ip1k110_quartus/serv_req_info.txt
      E modified      hardware/test/test_hardware-one_harness.adb

Each line has three fields:

Mark
     Either blank (not marked), '*' (marked), or 'E' (excluded). Most commands can apply to a group of marked files, but some cannot (they warn if a group is marked).

     Excluded files are under configuration management, but are excluded from commits. This is used for files that each user modifies, such as development test drivers.

Status
     A phrase indicating the status of the file; see the table below.

File name
     Gives the file name of the working file, with a path relative to the root directory.

In addition, some files will have extra status information that appears on the next line, indented.

The following table defines each status phrase, and gives the set of actions that can be taken for each. The action shown is from the DVC menu; the equivalent key is also given.

Other actions (such as commit) apply to all files; they are discussed later.

Added
     Working file has been added, but not committed.

     r Delete
          Remove the file from the workspace, do not commit it. Do this if you've changed your mind.

Conflict
     A conflict was detected while merging. The same lines have been edited differently by different people.

     This status does not appear with the monotone back-end.

     <enter> Edit the file.
          Either resolve the conflict manually, or use M-x smerge-ediff. Execute M-x dvc-resolve when finished to inform the back-end that the conflict is resolved.

     U Revert
          Delete the working copy, replace it with the database copy. Do this if you decide the changes are not correct.

Deleted
     Working file has been marked for deletion, but not committed.

     a Add
          Undo the removal.

Ignored
     Working file is ignored by the back-end. Files with this status are not typically shown - ignored files are ignored by DVC as well. They can be enabled by setting dvc-status-display-ignored to nil.

     # e
          Edit the back-end ignore file.

Known
     Working file is known to the back-end, and unchanged. Files with this status are not typically shown. They can be enabled by setting dvc-status-display-known to nil. There are no appropriate actions.

Missing
     A previously known file has been deleted from the workspace, but not marked for deletion.

          U Revert Restore the file to the workspace from the database.

     r Delete
          Mark the file for deletion.

Modified
     A changed file in the workspace.

     e ediff
          Review differences and collect a change comment.

     U Revert
          Delete the working copy, replace it with the database copy. Do this if you decide your changes are not correct.

Rename-source
     Working file has been marked as renamed but not committed. No appropriate actions.

Rename-target
     Working file has been marked as renamed but not committed. No appropriate actions.

Unknown
     Working file is unknown.

     a Add
          The file is a new source file; add it to the current revision. This will change the status to 'Added'.

     i Ignore
          The file is an output file of some sort (ie object file, test output). Ignore it in all future DVC sessions.

     I Ignore extension in dir
          Ignore all files with this extension in this directory.

     M-I Ignore extension
          Ignore all files with this extension in all directories.

     r Delete
          The file is a scratch file, or was created by mistake. Remove it from the workspace.

Changes are committed all at once; the set of changes to the entire workspace is called a ``revision''. c opens the *dvc-log-edit* buffer, where you can write a change comment. Then C-c C-c commits all changes.

The key M-d invokes a function called ``Do the Right Thing''. If there is only a single choice (or an extremely common choice) in the table above, it does that action. Otherwise, it presents a short list of the actions, in the message buffer, reminding the user of the appropriate options. Note that M-d means meta-d (alt-d on most PC keyboards))

Key bindings
************

Here is a summary of the most useful key bindings in the various buffers associated with DVC.

status buffer keys
==================

In a *dvc-status* buffer:

M-d
     Do the right thing for the current file.

c
     Open a *dvc-log-edit* buffer to accumulate comments for a commit.

M m
     Show missing revisions; changes that will be applied by update.

M M
     Merge current heads; see Merging.

M u
     Update to the current head.

R
     Rename a missing to an unknown file. The two files must be marked first, and they must be the only files marked.

t
     Create an entry in the *dvc-log-edit* for the current diff.

Ediff keys
==========

In an Ediff control buffer (the small window with Ediff in the title bar):

a
     Copy from buffer A to buffer B.

b
     Copy from buffer B to buffer A.

n
     Move to next diff.

p
     Move to previous diff.

q
     Quit Ediff.

t
     Create an entry in the *dvc-log-edit* for the current diff.

$$
     Focus on conflicts in a merge.

?
     Show the help summary for Ediff. ? hides it again.

log edit keys
=============

In the *dvc-log-edit* buffer:

C-c C-c
     Commit. Note that this is the only way to actually commit.

DVC log keys
============

In a *xmtn-log* buffer:

n
     move to the next revision

p
     move to the previous revision

=
     show a diff of the changes in a single revision

C-=
     show a diff between the revision and the workspace

DVC diff keys
=============

In a *dvc-diff* buffer:

e
     show ediff for current file

j
     jump between file list and diff hunks

n
     move to the next diff hunk

p
     move to the previous diff hunk

mtn conflicts keys
==================

In a *xmtn-conflicts* buffer:

C
     Delete conflicts file and any resolution files.

c
     Clear the current resolution, so you can specify a different one.

n
     Move to the next conflict.

N
     Move to the next unresolved conflict.

p
     Move to the previous conflict.

P
     Move to the previous unresolved conflict.

q
     Quit the *xmtn-conflicts* buffer. The conflicts file and associated resolution files are saved.

r
     Specify a resolution for the current conflict. This prompts with a choice of resolutions appropriate for the current conflict; select the appropriate resolution by number. See Merging, for information on the possible resolutions.

M-d
     Same as r

Previewing updates
******************

To preview updates before applying them to your workspace, use the dvc-missing command; it's on the status buffer menu at DVC | Merge/Update | show missing.

dvc-missing can also be invoked via the Emacs command line (M-x); that prompts for a local tree.

Invoking dvc-missing brings up an *dvc-log* window, showing revisions that are in your local database but not yet applied to the workspace.

The revisions are listed oldest first.

You can view the changes made in a single revision, or from that revision to the current workspace.

See Log edit keys, for key bindings.

= and C-= bring up a *dvc-diff* buffer for the revision selected. The diffs are shown in Gnu diff format; all files in one *dvc-diff* buffer. There is a list of the files at the top of the buffer. See DVC diff keys, for key bindings.

Note that you can also review updates after they have been applied. This is often more useful, because you can edit the workspace file to fix problems caused by the update, or just to see the final state after all revisions have been applied.

Merging
*******

Monotone allows multiple people to each commit to their local database. Then when the databases are synced, there are multiple heads for the branch; one head for each developer that commited since the last sync.

These multiple heads must be merged before a local workspace can be updated to the head of the branch; there must be only one head to update to. The monotone command line allows updating to one head of an unmerged branch, but DVC does not support this.

When the changes in the different heads are to different files, or to different parts of the same file, monotone can perform the merge itself. However, when there are changes to the same parts of one file, it needs help; this is called a content conflict.

An *xmtn-conflicts* buffer shows all conflicts in a merge or propagate. You can work thru the list one a time, using M-d to specify conflict resolutions. The list is saved in a file, so you can come back to it later.

The conflicts that monotone knows how to resolve internally have resolutions of resolved-internal; the others have no resolutions.

The conflicts file and associated resolution files are stored in the monotone bookkeeping area. They must be deleted when you are done with them; use C C for that.

M-d prompts with a list of appropriate resolutions for the current conflict; select the appropriate resolution by number. The possible resolutions are:

right: drop
left: drop
     Resolve one side of a duplicate name conflict by dropping it.

drop
     Resolve an orphaned node conflict by dropping it.

right: rename
left: rename
     Resolve one side of a duplicate name conflict by specifying a new name.

rename
     Resolve an orphaned node conflict by specifying a new name.

right: right file
right: left file
left: right file
left: left file
     Resolve one side of a duplicate name conflict by specifying a file.

     The other side must be dropped or renamed.

left file
     Resolve a content conflict by specifying a file. The file defaults to the current workspace file.

right: keep
left: keep
     Resolve one side of a duplicate name conflict by keeping it as is.

     The other side must be dropped or renamed.

right: ediff
left: ediff
     Resolve one side of a duplicate name conflict by ediff. This brings up an ediff merge of the two files, and saves the result in the resolution file area.

     The other side must be dropped or renamed.

ediff
     Resolve a content conflict via ediff. This brings up an ediff merge of the two files, and saves the result in the resolution file area.

See mtn conflicts keys, for a summary of key bindings.

mtn command line
****************

Sometimes, especially over NFS, the Emacs DVC interface can be painfully slow, and it is appropriate to use the mtn command line instead.

Other times, the mtn command line is just simpler.

So we list the most useful mtn commands here. See the monotone command line help or manual for more information.

status
     mtn status

commit
     mtn commit --message="<message>"

     mtn commit --message-file=_MTN/log

rename
     mtn rename <file> <new-file>

update
     mtn update --move-conflicting-paths

Common Errors and Solutions
***************************

Attach blocked by unversioned path
==================================

Problem: When attempting to update a directory, this warning appears:

     $ mtn update
      ...
     mtn: warning: attach node 2147486644 blocked by unversioned path '<file path>'
     mtn: misuse: 1 workspace conflict

Explanation: "Unversioned path" means the indicated file is not in the current revision, however the file already exists on the disk. The revision you are updating to contains the file, but it can't be updated because it would overwrite the unknown file on the disk

Solution: Delete the indicated files from the disk and retry the update, or specify the --move-conflicting-paths option.

Revision id does not match conflict file
========================================

Problem: When attempting to propagate from one branch to another, this message appears:

     $ mtn: propagating common.main -> common.work_user
       mtn: [left]  48b675060af47a02bc6f773bd63647726f96cbd5
       mtn: [right] 94ffd0b529dfb44c3ab122fe6c514b5f2e857104
       mtn: misuse: left revision id does not match conflict file

Explanation: It means you have some conflict files left over from a previous propagation or merge.

Solution: In a buffer showing the ``from'' workspace, run: M-x xmtn-conflicts-clean.  Repeat in the ``to'' workspace, then propagate again.

GNU Free Documentation License
******************************

     [file fdl.texinfo not included]