\documentclass[t,compress,red]{beamer}

\usepackage[utf8]{inputenc}

\usepackage{xspace}

\usepackage{graphics}

\title{Distributed versioning for everyone}

\author{Nicolas Pouillard}

\institute{{\tt Nicolas.Pouillard@inria.fr} }

\usetheme{JuanLesPins}

\usefonttheme{serif}

\setbeamercolor*{titlelike}{parent=structure}

\AtBeginSection[]
{
\begin{frame}

\frametitle{Outline}

\tableofcontents[sectionstyle=show/shaded,subsectionstyle=show/shaded/hide]
\end{frame}
}

\AtBeginSubsection[]
{
\begin{frame}

\frametitle{Outline}

\tableofcontents[sectionstyle=show/shaded,subsectionstyle=show/shaded/hide]
\end{frame}
}

        \defbeamertemplate*{footline}{infolines theme without institution}
        {
          \leavevmode%
          \hbox{%
            \begin{beamercolorbox}[wd=.50\paperwidth,ht=2.25ex,dp=1.125ex,center]{author in head/foot}%
              \usebeamerfont{author in head/foot}
              \insertshortauthor
            \end{beamercolorbox}%
            \begin{beamercolorbox}[wd=.0\paperwidth,ht=2.25ex,dp=1.125ex,center]{title in head/foot}%
              \usebeamerfont{title in head/foot}
              \insertshorttitle
            \end{beamercolorbox}%
            \begin{beamercolorbox}[wd=.50\paperwidth,ht=2.25ex,dp=1.125ex,right]{date in head/foot}%
              \usebeamerfont{date in head/foot}
              \insertshortdate{}\hspace*{2em}
              \insertframenumber{} / \inserttotalframenumber\hspace*{2ex}
            \end{beamercolorbox}}%
          \vskip0pt%
        }
\begin{document}

\maketitle

\section{Introduction}

\begin{frame}

\frametitle{SCM$:$ “Source Code Manager”}

\begin{itemize}
\item Keeps track of changes to source code so you can track down bugs and work collaboratively.

\item Most famous example$:$ CVS

\item Numerous acronyms$:$ RCS, SCM, VCS

\item DSCM$:$ Distributed Source Code Manager
\end{itemize}
\end{frame}

\begin{frame}

\frametitle{Purpose}

\begin{block}{What's the purpose of this presentation}
\begin{itemize}
\item Show the importance of the distributed feature

\item Enrich your toolbox with a DSCM

\item Exorcize rumors about darcs

\item Show how DSCM are adapted for personal use
\end{itemize}
\end{block}

\begin{block}{What's {\bf not} the purpose of it}
\begin{itemize}
\item A flame against other DSCMs

\item A precise darcs tutorial

\item A real explanation of the Theory of patches
\end{itemize}
\end{block}
\end{frame}

\section{Principles of Distributed Versioning}

\begin{frame}

\frametitle{Distributed rather than centralized}

\begin{columns}[c]
\begin{column}{5.5cm}
\begin{block}{Centralized}
\begin{figure}
\includegraphics[height=3.8cm]{figures/centralized}
\end{figure}

Examples$:$ CVS, Subversion, Perforce
\end{block}
\end{column}

\begin{column}{5.5cm}
\begin{block}{Distributed}
\begin{figure}
\includegraphics[height=3.8cm]{figures/distributed}
\end{figure}

Examples$:$ darcs, Git, Bitkeeper, monotone, arch
\end{block}
\end{column}
\end{columns}
\end{frame}

\begin{frame}

\frametitle{Principles}

\begin{block}{Unify Repositories and Working copies}
\begin{itemize}
\item Working copies with full history

\item Repositories with local changes
\end{itemize}
\end{block}

\begin{block}{Users record/commit in a local branch}
\begin{itemize}
\item Local branches can be then merged with remote ones

\item Branching/Merging is then {\bf forced} to work
\end{itemize}
\end{block}
\end{frame}

\begin{frame}

\frametitle{Local branches}

\begin{block}{Branching in a centralized system is morally flawed}
\begin{itemize}
\item People use branches only when they must

\item Branches are public (not discreet)

\item That's considered as an advanced usage
\end{itemize}
\end{block}

\begin{block}{Distributed systems make them easy}
\begin{itemize}
\item Offline commit (no need to be connected)

\item Try out an idea (cheap and discreet)

\item Polish your work / amend a patch

\item Publish with a delay (e.g. end of the work-day)
\end{itemize}
\end{block}
\end{frame}

\begin{frame}

\frametitle{DSCM are often lighter}

\begin{itemize}
\item No server to setup

\item Make a repository is as easy as "darcs initialize"

\item There is no need to "wait for" a center

\item No commit rights management needed
\end{itemize}
\end{frame}

\begin{frame}

\frametitle{DSCM for open source projects}

\begin{block}{Collaborating to an open source project}
\begin{itemize}
\item Local branches is a "must have"

\item Help to publish only clean and working changes

\item Send your patches under {\bf your} name
\end{itemize}
\end{block}

\begin{block}{Work with user contributions}
\begin{itemize}
\item Maintain an auto-gratification principle

\item No need for commit rights (was really a pain)

\item Commutation is essential

\item Delaying user contributions if needed
\end{itemize}
\end{block}
\end{frame}

\section{Darcs is one of them}

\subsection{Darcs overview}

\begin{frame}

\frametitle{Why focusing on one of them}

\begin{itemize}
\item Treat each system in details is too long

\item Abstract over DSCM would be too obscure

\item Darcs is conceptually simple

\item Darcs is certainly the smarter of them
\end{itemize}
\end{frame}

\begin{frame}

\frametitle{Ideas behind darcs}

\begin{block}{Distributed}
\begin{itemize}
\item A simple “egalitarian” distributed model

\item “Cherry picking” of changes

\item Avoidance of “merge points” (no merge history)
\end{itemize}
\end{block}

\begin{block}{Interactive}
\begin{itemize}
\item Efficient and easy to learn

\item Improved work flow (e.g. partial records, code review, ...)
\end{itemize}
\end{block}

\begin{block}{Smart}
\begin{itemize}
\item Based on a unique algebra of patches

\item Spontaneous branches

\item Commutation of changes
\end{itemize}
\end{block}
\end{frame}

\begin{frame}

\frametitle{Change-based rather than version-based}

\begin{columns}
\begin{column}{5.5cm}
\begin{block}{Version-based}
\begin{figure}
\includegraphics[height=3.8cm]{figures/version_based}
\end{figure}

Examples$:$ Git, Bitkeeper, Monotone, CVS, Subversion
\end{block}
\end{column}

\begin{column}{5.5cm}
\begin{block}{Change-based}
\begin{figure}
\includegraphics[width=4cm]{figures/change_based}
\end{figure}

Examples$:$ darcs
\end{block}
\end{column}
\end{columns}
\end{frame}

\begin{frame}

\frametitle{Darcs terminology}

\begin{block}{}
\begin{itemize}
\item A change is a logical entity

\item A patch is a description of a change

\item The state of a repository is defined by its set of changes

\item A set of changes is stored as a sequence of patches
\end{itemize}
\end{block}

\begin{block}{Notation}
\begin{itemize}
\item A change is represented as a capital letter$:$ \( A \)

\item A patch is represented by a capital letter with possibly primes and/or a subscript$:$ \( A \), \( A' \), \( A_{1} \)

\item Sometimes the state (or context) before and after a patch is represented by lowercase superscripts$:$ \( ^{o}A^{a} \)
\end{itemize}
\end{block}
\end{frame}

\begin{frame}

\begin{center}
{\vfill}\begin{vcenter}
{\huge The state of a repository is defined by a {\bf set} of {\bf changes}. }
\end{vcenter}{\vfill}
\end{center}
\end{frame}

\begin{frame}

\begin{center}
{\vfill}\begin{vcenter}
{\huge The repository is represented by a {\bf sequence} of {\bf patches}. }
\end{vcenter}{\vfill}
\end{center}
\end{frame}

\subsection{Darcs Theory of patches}

\begin{frame}

\frametitle{Some primitive patches}

\begin{block}{}
\begin{itemize}
\item {\tt addfile} \( f \)$:$ Create the empty file \( f \)

\item {\tt rmdir} \( d \)$:$ Remove the empty directory \( d \)

\item {\tt move} \( x \) \( y \)$:$ Move/rename the file/directory \( x \) into \( y \)

\item {\tt hunk}$:$ Change the contents of a file {\tt ~\newline{}
hunk{\hspace{0.5em}}"foo.txt"{\hspace{0.5em}}42\newline{}-{\hspace{0.5em}}the{\hspace{0.5em}}old{\hspace{0.5em}}lines{\hspace{0.5em}}has{\hspace{0.5em}}been\newline{}-{\hspace{0.5em}}removed.\newline{}+{\hspace{0.5em}}and{\hspace{0.5em}}replaced{\hspace{0.5em}}by{\hspace{0.5em}}this{\hspace{0.5em}}one\newline{}}
\end{itemize}
\end{block}

\begin{block}{}
However the theory is independent of its primitives
\end{block}
\end{frame}

\begin{frame}

\frametitle{Each patch is invertible}

\begin{block}{Definition}
\begin{center}
{\tt invert} \( ^{o}A^{a} \) = \( ^{a}A^{-1o} \)
\end{center}
\end{block}

\begin{block}{Property}
\begin{center}
$\forall$ \( x \) . {\tt invert} ({\tt invert} \( x \)) = \( x \)
\end{center}
\end{block}

\begin{block}{Examples}
\begin{itemize}
\item {\tt invert} ({\tt addfile} \( f \)) = {\tt rmfile} \( f \)

\item {\tt invert} ({\tt move} \( x \) \( y \)) = {\tt move} \( y \) \( x \)

\item {\tt invert} ({\tt hunk} \( f \) {\it line} {\it old} {\it new}) = {\tt hunk} \( f \) {\it line} {\it new} {\it old}

\item {\tt invert} (\( A \) $:$\textgreater{} \( B \)) = ({\tt invert} \( B \)) $:$\textgreater{} ({\tt invert} \( A \))
\end{itemize}
\end{block}

\begin{block}{}
Consequence$:$ While {\tt move} is easy, {\tt copy} hardly make sense
\end{block}
\end{frame}

\begin{frame}

\frametitle{Independent changes $\Rightarrow$ commuting patches}

\begin{block}{}
\begin{center}
\( ^{o}A^{a}B^{b} \) $\leftrightarrow$ \( ^{o}B_{1}^{c}A_{1}^{b} \)
\end{center}
\end{block}

\begin{block}{Examples}
\begin{itemize}
\item Hunks on different files trivially commute

\item Hunks commute with moves

\item Hunks on different parts of a file commute (output patches have different line numbers)
\end{itemize}
\end{block}
\end{frame}

\begin{frame}

\begin{center}
{\vfill}\begin{vcenter}
{\huge Illustrated naive merging... }
\end{vcenter}{\vfill}
\end{center}
\end{frame}

\begin{frame}

\includegraphics[height=8cm]{figures/merge}
\end{frame}

\subsection{Darcs for working alone}

\begin{frame}

\frametitle{Darcs for small projects}

\begin{itemize}
\item A research paper

\item A prototype implementation

\item A small module/library

\item Configuration files

\item Personal web page

\item More to imagine...
\end{itemize}
\end{frame}

\begin{frame}

\frametitle{The bare minimum}

\begin{block}{}
\begin{tabular}{ll}
{\tt initialize} & Initialize a new source tree as a darcs repository \\
{\tt add} & Add one or more new files or directories \\
{\tt record} & Save local changes as a patch \\
{\tt mv} & Move/rename one or more files or directories \\
{\tt whatsnew} & Display local/unrecorded changes
\end{tabular}
\end{block}
\end{frame}

\begin{frame}

\frametitle{Handy operations}

\begin{block}{}
\begin{tabular}{ll}
{\tt revert} & Revert to the recorded version (not always doable) \\
{\tt unrevert} & Undo last revert (unless if changes after the revert) \\
{\tt rollback} & Record a new patch reversing some changes
\end{tabular}
\end{block}

\only<5->{\begin{block}{}
{\tt revert{\hspace{0.5em}};{\hspace{0.5em}}unrevert{\hspace{0.5em}}$\approx${\hspace{0.5em}}id}
\end{block}}
\end{frame}

\begin{frame}

\frametitle{Overriding unpublished changes}

\begin{block}{}
\begin{tabular}{ll}
{\tt amend-record} & Replace a patch with a better version \\
{\tt unrecord} & Remove patches wo/ changing the working copy \\
{\tt obliterate} & Delete selected patches from the repository
\end{tabular}
\end{block}

\only<5->{\begin{block}{}
\begin{itemize}
\item {\tt amend-record{\hspace{0.5em}}$\approx${\hspace{0.5em}}unrecord{\hspace{0.5em}};{\hspace{0.5em}}record}

\item {\tt obliterate{\hspace{0.5em}}$\approx${\hspace{0.5em}}unrecord{\hspace{0.5em}};{\hspace{0.5em}}revert}
\end{itemize}
\end{block}}
\end{frame}

\begin{frame}

\frametitle{Towards advanced patch types}

\begin{block}{}
\begin{tabular}{ll}
{\tt replace} & Replace a token with a new value for that token
\end{tabular}
\end{block}
\end{frame}

\begin{frame}

\frametitle{Looking in the past}

\begin{block}{}
\begin{tabular}{ll}
{\tt changes} & Give a summary of the repository history \\
{\tt annotate} & Display which patch last modified something \\
{\tt diff} & Create a diff between versions of the repository \\
{\tt dist} & Create a distribution tarball \\
{\tt trackdown} & Locate the most recent version lacking an error \\
{\tt show} & Show information which is stored by darcs
\end{tabular}
\end{block}
\end{frame}

\subsection{Darcs branching, merging, tagging}

\begin{frame}

\frametitle{Moving patches around}

\begin{block}{}
\begin{tabular}{ll}
{\tt pull} & Apply patches from another repository to this one \\
{\tt push} & Apply patches from this repository to another one \\
{\tt get} & Create a local copy of another repository \\
{\tt put} & Make a copy of the repository \\
{\tt send} & Send (by email) a bundle of one or more patches \\
{\tt apply} & Apply patches (from an email) to the repository
\end{tabular}
\end{block}

\only<8->{\begin{block}{}
\begin{itemize}
\item {\tt get{\hspace{0.5em}}{\it src}{\hspace{0.5em}}{\it dst}{\hspace{0.5em}}$\approx${\hspace{0.5em}}initialize{\hspace{0.5em}}{\it src}{\hspace{0.5em}};{\hspace{0.5em}}cd{\hspace{0.5em}}{\it src}{\hspace{0.5em}}\&\&{\hspace{0.5em}}pull{\hspace{0.5em}}{\it dst}}

\item {\tt put{\hspace{0.5em}}{\it dst}{\hspace{0.5em}}$\approx${\hspace{0.5em}}initialize{\hspace{0.5em}}{\it dst}{\hspace{0.5em}};{\hspace{0.5em}}push{\hspace{0.5em}}{\it dst}}

\item {\tt push{\hspace{0.5em}}{\it dst}{\hspace{0.5em}}$\approx${\hspace{0.5em}}send{\hspace{0.5em}}{\it dst}{\hspace{0.5em}};{\hspace{0.5em}}cd{\hspace{0.5em}}{\it dst}{\hspace{0.5em}}\&\&{\hspace{0.5em}}apply}
\end{itemize}
\end{block}}
\end{frame}

\begin{frame}

\frametitle{Branching and merging}

\begin{block}{Branching is as easy as copying all patches}
\${\hspace{0.5em}}darcs{\hspace{0.5em}}get{\hspace{0.5em}}foo-stable{\hspace{0.5em}}foo-with-feature-A
\end{block}

\begin{block}{Merging is as easy as \{pull,push\}ing things}
\${\hspace{0.5em}}cd{\hspace{0.5em}}foo-with-feature-A

\\
\${\hspace{0.5em}}darcs{\hspace{0.5em}}pull{\hspace{0.5em}}../foo-stable
\end{block}
\end{frame}

\begin{frame}

\frametitle{Tagging your repository (darcs tag)}

\begin{block}{A "tag" patch is$:$}
\begin{itemize}
\item A change with no effect

\item Transitively depends on all patches

\item Really depends only on non tagged patches
\end{itemize}
\end{block}

\begin{block}{Tagging quite often is a good practice}
\begin{itemize}
\item Tag (some/only) versions that pass all tests

\item Tag pre-releases and releases
\end{itemize}
\end{block}

\begin{block}{Drawback of tagging}
Freeze commutations (patches under a tag cannot cross the tag)
\end{block}
\end{frame}

\begin{frame}

\frametitle{darcs + tagging like crazy $\approx$ git}

\begin{block}{}
\${\hspace{0.5em}}git{\hspace{0.5em}}commit{\hspace{0.5em}}={\hspace{0.5em}}darcs{\hspace{0.5em}}record{\hspace{0.5em}};{\hspace{0.5em}}darcs{\hspace{0.5em}}tag{\hspace{0.5em}}-m{\hspace{0.5em}}\textless{}SHA1\textgreater{}
\end{block}

\begin{block}{}
\begin{itemize}
\item Enforce the history

\item Enforce the order of patches

\item Loose commutativity (manually hacked with git rebase)
\end{itemize}
\end{block}
\end{frame}

\begin{frame}

\frametitle{Fancy features}

\begin{itemize}
\item Take the union$:$ pull another repository

\item Extract a sub part$:$ pull interactively only what's needed
\end{itemize}
\end{frame}

\subsection{Darcs for working with others}

\begin{frame}

\frametitle{Working with others}

\begin{itemize}
\item Just replace pathnames by URLs (http, ssh)

\item Use send/apply for email based contributions
\end{itemize}
\end{frame}

\subsection{Conflicts and concerns}

\begin{frame}

\frametitle{When conflicts happen}

\begin{block}{Two patches conflicts}
\begin{itemize}
\item they are parallel patches (\( A \) $\vee$ \( B \))

\item they don't commute (\( A \) \( B^{-1} \) $\nleftrightarrow$ \( B' \) \( A'^{-1} \))
\end{itemize}
\end{block}

\begin{block}{Conflict example}
{\tt ~\newline{}
hunk{\hspace{0.5em}}"foo.txt"{\hspace{0.5em}}42\newline{}-{\hspace{0.5em}}\#{\hspace{0.5em}}TODO\newline{}+{\hspace{0.5em}}\#{\hspace{0.5em}}FIXED\newline{}\newline{}hunk{\hspace{0.5em}}"foo.txt"{\hspace{0.5em}}42\newline{}-{\hspace{0.5em}}\#{\hspace{0.5em}}TODO\newline{}+{\hspace{0.5em}}\#{\hspace{0.5em}}DONE\newline{}}
\end{block}
\end{frame}

\begin{frame}

\frametitle{Resolving conflicts}

\begin{itemize}
\item When two patches conflicts one add a third one

\item By depending on the conflicting patches it tells what to do

\item Resolutions patches should be shared as much as possible
\end{itemize}
\end{frame}

\begin{frame}

\frametitle{Avoiding conflicts}

\begin{columns}[c]
\begin{column}{5.5cm}
\begin{block}{Typical DVCS usage}
\begin{figure}
\includegraphics[width=5cm]{figures/locallydistributed}
\end{figure}
\end{block}
\end{column}

\begin{column}{5.5cm}
\begin{block}{Recipe}
\begin{itemize}
\item Pull often

\item Amend local patches to resolve conflicts

\item Push/send clean patches
\end{itemize}
\end{block}
\end{column}
\end{columns}
\end{frame}

\begin{frame}

\frametitle{Is darcs slow?}

\begin{itemize}
\item Performances are due to its algorithms not its implementation

\item Darcs algorithms provide more power/flexibility

\item Completely usable for day to day commands

\item Can be really slow on hard requests

\item Darcs2 has made great progress

\item Darcs2 reports progress to the user

\item Darcs2 handles the conflict resolution problem
\end{itemize}
\end{frame}

\begin{frame}

\frametitle{Are DSCM slow or greedy?}

\begin{itemize}
\item Full history means bigger/slower copies/gets

\item Hard links in the repository

\item More network friendly than CVS/SVN

\item Darcs2 partial repositories could help
\end{itemize}
\end{frame}

\section{Conclusion}

\begin{frame}

\frametitle{Conclusion and questions}

\begin{center}
{\vfill}\begin{vcenter}
{\huge {\bf So, convinced?}}
\end{vcenter}{\vfill}
\end{center}
\end{frame}

\begin{frame}

\frametitle{Resources}

\begin{itemize}
\item "The Monad Reader", issue 9 by Jason Dagit

\item "Implementing the darcs patch formalism ...and verifying it" by David Roundy

\item The darcs website {\tt http$:$//darcs.net}

\item The darcs help
\end{itemize}
\end{frame}
\end{document}
