% Give some user-focused documentation on the formats introduced by Darcs 2


\chapter{Repository formats}

\section{Introduction}

Darcs 2 introduces a couple of new repository formats and this chapter
is intended to serve as brief introduction to them and as an overview of
inter-operation between them.

\section{Darcs 1 format}

Darcs 1 format is the only format supported by 1.0.x versions of darcs.
Darcs 2 is capable of entirely interacting with darcs 1 format and still
defaults to darcs 1 format, but to take full advantage of new
capabilities of darcs 2 it be will necessary to upgrade to the newer
formats.

\verb'old-fashioned-inventory' is now deprecated and should be avoided if at
all possible.

\section{Hashed format}

Hashed repository format is an intermediate format that interoperates
well with darcs 1 repositories.  Darcs 2 can push/pull between darcs 1
format and hashed format repositories and can easily convert from one to
the other.  Among its benefits, one of the most user obvious changes is
that the hashed format provides a more robust pristine format, that is
less susceptible to corruption from IDEs and automated tools. It also
enables the use of a global patch cache (see the Best Practices section
for more).

Hashed format is recommend for all repositories used with darcs 2 that
need to interoperate with darcs 1 branches or darcs 1 developers.  

To convert an existing darcs 1 repository to hashed format simply
\verb|get| a new copy with the hashed flag:

\begin{verbatim}
$ darcs get --hashed old-repo new-repo
\end{verbatim}

\verb'hashed' Offers several features while still being compatible with old-fashioned repositories. The specific features are:

\begin{itemize}  

\item The hashed format allows for greater atomicity of operations. This makes for greater safety and simultaneously greater efficiency. These benefits, however, have not been fully realized in this release. For instance, with a hashed repository, there is no need for darcs push to require a repository lock, so you could record patches while waiting for a push to finish (for instance, if it's waiting on the test suite).

\item The \verb!_darcs/pristine! directory no longer holds the pristine
cache. This disallows certain hackish short-cuts, but also dramatically
reduces the danger of third-party programs (e.g. DreamWeaver) recursing
into the pristine cache and corrupting darcs repositories.

\item Darcs get can optionally operate in a much faster ``lazy''
fashion, meaning that patches are downloaded only when they are
needed. This gives us much of the benefits of --partial repositories,
without most of their disadvantages. This approach, however, does have
several new dangers. First, some operations may unexpectedly require the
download of large numbers of patches, which could be slow (but you could
always interrupt with \verb!^C!). Secondly, if the source repository disappears,
or you lose network connectivity, some operations may fail.

\item Darcs now supports caching of patches and file contents to reduce bandwidth and save disk space. It greatly speeds up a number of operations, and is essentially transparent.

\end{itemize}

\section{Darcs 2 format}

Darcs 2 format is the successor to darcs 1 format.  It makes use of the
various improvements of the hashed repository format, with additional
benefits including an increased efficiency and robustness when dealing
with conflicting patches.

Darcs 2 format is recommended for projects that do not need to
interoperate with darcs 1 repositories or developers with versions of
darcs less than 2.0.0 installed.  

Initialize a new repository in darcs 2 format:

\begin{verbatim}
$ darcs init --darcs-2
\end{verbatim}

Projects in darcs 1 format ready to move all development to darcs 2 can
convert an existing repository to darcs 2 format.  This should be done
only once per family tree of related repositories, as converting each
branch separately may result in inter-repository corruption that can
lead to subtle and hard to diagnose problems when attempting to exchange
patches between seperately converted repositories.  The recommendation
is to convert the branch of a project with the largest superset of
patches in the project and then recreate the branches from this superset
repository via \verb|darcs get|, particularly with the usage of its
selection flags such as \verb|--context|, \verb|--tag| and
\verb|--to-match|, and \verb|darcs obliterate|, which can be used to
interactively remove patches that are not intended in the recreated
branch.

The command for conversion:

\begin{verbatim}
$ darcs convert d1repo d2repo
\end{verbatim}

\verb'darcs-2' Is the default.  It enables all available features, and
requiring that all repos for a project use the same format. In addition to the
features of the \verb'hashed' format described above, the \verb'darcs-2' format
also enables the following:

\begin{itemize}

\item It should no longer be possible to confuse darcs or freeze it indefinitely by merging conflicting changes. 

\item Identical primitive changes no longer conflict. This is a long-requested feature, and has far-reaching implications. 

\end{itemize}
