Follow upstream changes -- Bytestring updates
[git-darcs-import.git] / src / darcs.lhs
blob057a867dac0f61afd77cf6f8d105904880778457
1 % Copyright (C) 2002-2003 David Roundy
3 % This program is free software; you can redistribute it and/or modify
4 % it under the terms of the GNU General Public License as published by
5 % the Free Software Foundation; either version 2, or (at your option)
6 % any later version.
8 % This program is distributed in the hope that it will be useful,
9 % but WITHOUT ANY WARRANTY; without even the implied warranty of
10 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 % GNU General Public License for more details.
13 % You should have received a copy of the GNU General Public License
14 % along with this program; see the file COPYING. If not, write to
15 % the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 % Boston, MA 02110-1301, USA.
18 \documentclass{book}
19 %\usepackage{color}
21 \usepackage{verbatim}
22 \usepackage{html}
23 \usepackage{fancyvrb}
24 \newenvironment{code}{\comment}{\endcomment}
25 % \newenvironment{code}{\color{blue}\verbatim}{\endverbatim}
27 \begin{document}
29 \begin{code}
30 {-# OPTIONS_GHC -cpp #-}
31 {-# LANGUAGE CPP #-}
33 module Main (main) where
35 import System.IO ( hSetBinaryMode)
36 import System.IO ( stdin, stdout )
37 import System.Exit ( exitWith, ExitCode(..) )
38 import System.Environment ( getArgs )
39 import Control.Monad ( when )
40 import Control.Exception ( Exception( AssertionFailed ), handleJust, catchDyn )
42 import Darcs.RunCommand ( run_the_command )
43 import Darcs.Flags ( DarcsFlag(Verbose) )
44 import Darcs.Commands.Help ( help_cmd, list_available_commands, print_version )
45 import Autoconf( darcs_version )
46 import Darcs.SignalHandler ( withSignalsHandled )
47 import Context ( context )
48 import Darcs.Global ( with_atexit )
49 import Exec ( ExecException(..) )
50 #include "impossible.h"
51 \end{code}
53 % Definition of title page:
54 \title{
55 Darcs \haskell{darcs_version}\\
56 {\Large\itshape Darcs}
58 \author{
59 David Roundy
62 \maketitle
64 \tableofcontents
66 \chapter{Introduction}
68 Darcs is a revision control system, along the lines of CVS or arch. That
69 means that it keeps track of various revisions and branches of your
70 project, allows for changes to propagate from one branch to another. Darcs
71 is intended to be an ``advanced'' revision control system. Darcs has two
72 particularly distinctive features which differ from other revision control
73 systems: 1) each copy of the source is a fully functional branch, and 2)
74 underlying darcs is a consistent and powerful theory of patches.
76 \paragraph{Every source tree a branch}
77 The primary simplifying notion of darcs is that \emph{every} copy of your
78 source code is a full repository. This is dramatically different from CVS,
79 in which the normal usage is for there to be one central repository from
80 which source code will be checked out. It is closer to the notion of arch,
81 since the `normal' use of arch is for each developer to create his own
82 repository. However, darcs makes it even easier, since simply checking out
83 the code is all it takes to create a new repository. This has several
84 advantages, since you can harness the full power of darcs in any scratch
85 copy of your code, without committing your possibly destabilizing changes to
86 a central repository.
88 \paragraph{Theory of patches}
89 The development of a simplified theory of patches is what originally
90 motivated me to create darcs. This patch formalism means that darcs patches
91 have a set of properties, which make possible manipulations that couldn't be
92 done in other revision control systems. First, every patch is invertible.
93 Secondly, sequential patches (i.e.\ patches that are created in sequence, one
94 after the other) can be reordered, although this reordering can fail, which
95 means the second patch is dependent on the first. Thirdly, patches which are
96 in parallel (i.e.\ both patches were created by modifying identical trees)
97 can be merged, and the result of a set of merges is independent of the order
98 in which the merges are performed. This last property is critical to darcs'
99 philosophy, as it means that a particular version of a source tree is fully
100 defined by the list of patches that are in it, i.e.\ there is no issue
101 regarding the order in which merges are performed. For a more thorough
102 discussion of darcs' theory of patches, see Appendix~\ref{Patch}.
104 \paragraph{A simple advanced tool}
105 Besides being ``advanced'' as discussed above, darcs is actually also quite
106 simple. Versioning tools can be seen as three layers. At the foundation is
107 the ability to manipulate changes. On top of that must be placed some kind
108 of database system to keep track of the changes. Finally, at the very top is
109 some sort of distribution system for getting changes from one place to
110 another.
112 Really, only the first of these three layers is of particular interest to
113 me, so the other two are done as simply as possible. At the database
114 layer, darcs just has an ordered list of patches along with the patches
115 themselves, each stored as an individual file. Darcs' distribution system
116 is strongly inspired by that of arch. Like arch, darcs uses a dumb server,
117 typically apache or just a local or network file system when pulling
118 patches. darcs has built-in support for using \verb!ssh! to write to a remote file
119 system. A darcs executable is called on the remote system to apply the patches.
120 Arbitrary other transport protocols are supported, through an environment
121 variable describing a command that will run darcs on the remote system.
122 See the documentation for DARCS\_APPLY\_FOO in Chapter~\ref{configuring}
123 for details.
125 The recommended method is to send patches through gpg-signed email
126 messages, which has the advantage of being mostly asynchronous.
128 \paragraph{Keeping track of changes rather than versions}
130 In the last paragraph, I explained revision control systems in terms of
131 three layers. One can also look at them as having two distinct uses. One
132 is to provide a history of previous versions. The other is to keep track
133 of changes that are made to the repository, and to allow these changes to
134 be merged and moved from one repository to another. These two uses are
135 distinct, and almost orthogonal, in the sense that a tool can support one
136 of the two uses optimally while providing no support for the other. Darcs
137 is not intended to maintain a history of versions, although it is possible
138 to kludge together such a revision history, either by making each new patch
139 depend on all previous patches, or by tagging regularly. In a sense, this
140 is what the tag feature is for, but the intention is that tagging will be
141 used only to mark particularly notable versions (e.g.\ released versions, or
142 perhaps versions that pass a time consuming test suite).
144 Other revision control systems are centered upon the job of keeping track
145 of a history of versions, with the ability to merge changes being added as
146 it was seen that this would be desirable. But the fundamental object
147 remained the versions themselves.
149 In such a system, a patch (I am using patch here to mean an encapsulated
150 set of changes) is uniquely determined by two trees. Merging changes that
151 are in two trees consists of finding a common parent tree, computing the
152 diffs of each tree with their parent, and then cleverly combining those two
153 diffs and applying the combined diff to the parent tree, possibly at some
154 point in the process allowing human intervention, to allow for fixing up
155 problems in the merge such as conflicts.
157 In the world of darcs, the source tree is \emph{not} the fundamental
158 object, but rather the patch is the fundamental object. Rather than a
159 patch being defined in terms of the difference between two trees, a tree is
160 defined as the result of applying a given set of patches to an empty tree.
161 Moreover, these patches may be reordered (unless there are dependencies
162 between the patches involved) without changing the tree. As a result,
163 there is no need to find a common parent when performing a merge. Or, if
164 you like, their common parent is defined by the set of common patches, and
165 may not correspond to any version in the version history.
167 One useful consequence of darcs' patch-oriented philosophy is that since a
168 patch need not be uniquely defined by a pair of trees (old and new), we can
169 have several ways of representing the same change, which differ only in how
170 they commute and what the result of merging them is. Of course, creating
171 such a patch will require some sort of user input. This is a Good Thing,
172 since the user \emph{creating} the patch should be the one forced to think
173 about what he really wants to change, rather than the users merging the
174 patch. An example of this is the token replace patch (See
175 Section~\ref{token_replace}). This feature makes it possible to create a
176 patch, for example, which changes every instance of the variable
177 ``stupidly\_named\_var'' to ``better\_var\_name'', while leaving
178 ``other\_stupidly\_named\_var'' untouched. When this patch is merged with
179 any other patch involving the ``stupidly\_named\_var'', that instance will
180 also be modified to ``better\_var\_name''. This is in contrast to a more
181 conventional merging method which would not only fail to change new
182 instances of the variable, but would also involve conflicts when merging
183 with any patch that modifies lines containing the variable. By more using
184 additional information about the programmer's intent, darcs is thus able to
185 make the process of changing a variable name the trivial task that it
186 really is, which is really just a trivial search and replace, modulo
187 tokenizing the code appropriately.
189 The patch formalism discussed in Appendix~\ref{Patch} is what makes darcs'
190 approach possible. In order for a tree to consist of a set of patches,
191 there must be a deterministic merge of any set of patches, regardless of the
192 order in which they must be merged. This requires that one be able to
193 reorder patches. While I don't know that the patches are required to be
194 invertible as well, my implementation certainly requires invertibility. In
195 particular, invertibility is required to make use of
196 Theorem~\ref{merge_thm}, which is used extensively in the manipulation of
197 merges.
199 \input{features.tex}
201 \input{switching.tex}
203 \input{building_darcs.tex}
205 \chapter{Getting started}
207 This chapter will lead you through an example use of darcs, which hopefully
208 will allow you to get started using darcs with your project.
210 \section{Creating your repository}
212 Creating your repository in the first place just involves telling darcs to
213 create the special directory (called {\tt \_darcs}) in your project tree,
214 which will hold the revision information. This is done by simply calling
215 from the root directory of your project:
216 \begin{verbatim}
217 % cd my_project/
218 % darcs initialize
219 \end{verbatim}
220 This creates the \verb|_darcs| directory and populates it with whatever
221 files and directories are needed to describe an empty project. You now
222 need to tell darcs what files and directories in your project should be
223 under revision control. You do this using the command \verb|darcs add|%
224 \footnote{Note that darcs does not do wildcard expansion, instead relying
225 on the command shell. The Windows port of darcs has a limited form of
226 expansion provided by the C runtime}:
227 \begin{verbatim}
228 % darcs add *.c Makefile.am configure.ac
229 \end{verbatim}
230 When you have added all your files (or at least, think you have), you will
231 want to record your changes. ``Recording'' always includes adding a note
232 as to why the change was made, or what it does. In this case, we'll just
233 note that this is the initial version.
234 \begin{verbatim}
235 % darcs record --all
236 What is the patch name? Initial revision.
237 \end{verbatim}
238 Note that since we didn't specify a patch name on the command line we were
239 prompted for one. If the environment variable `EMAIL' isn't set, you will
240 also be prompted for your email address. Each patch that is recorded is
241 given a unique identifier consisting of the patch name, its creator's email
242 address, and the date when it was created.
244 \section{Making changes}
246 Now that we have created our repository, make a change to one or more of
247 your files. After making the modification run:
248 \begin{verbatim}
249 % darcs whatsnew
250 \end{verbatim}
251 This should show you the modifications that you just made, in the darcs
252 patch format. If you prefer to see your changes in a different format,
253 read Section~\ref{whatsnew}, which describes the whatsnew command in
254 detail.
256 Let's say you have now made a change to your project. The next thing to do
257 is to record a patch. Recording a patch consists of grouping together a
258 set of related changes, and giving them a name. It also tags the patch
259 with the date it was recorded and your email address.
261 To record a patch simply type:
262 \begin{verbatim}
263 % darcs record
264 \end{verbatim}
265 darcs will then prompt you with all the changes that you have made that
266 have not yet been recorded, asking you which ones you want to include in
267 the new patch. Finally, darcs will ask you for a name for the patch.
269 You can now rerun whatsnew, and see that indeed the changes you have
270 recorded are no longer marked as new.
272 \section{Making your repository visible to others}
273 How do you let the world know about these wonderful changes? Obviously,
274 they must be able to see your repository. Currently the easiest way to do
275 this is typically by http using any web server. The recommended way to do
276 this (using apache in a UNIX environment) is to create a directory called
277 {\tt /var/www/repos}, and then put a symlink to your repository there:
278 \begin{verbatim}
279 % cd /var/www/repos
280 % ln -s /home/username/myproject .
281 \end{verbatim}
283 As long as you're running a web server and making your repository available to
284 the world, you may as well make it easy for people to see what changes
285 you've made. You can do this by running \verb!make installserver!, which
286 installs the program \verb|darcs_cgi| at \verb|/usr/lib/cgi-bin/darcs|. You
287 also will need to create a cache directory named
288 \verb!/var/cache/darcs_cgi!, and make sure the owner of that directory is
289 the same user that your web server runs its cgi scripts as. For me,
290 this is www-data. Now your friends and enemies should be able to easily
291 browse your repositories by pointing their web browsers at
292 \verb|http://your.server.org/cgi-bin/darcs|.
294 \section{Getting changes made to another repository}
295 Ok, so I can now browse your repository using my web browser\ldots\ so
296 what? How do I get your changes into \emph{my} repository, where they can
297 do some good? It couldn't be easier. I just \verb|cd| into my repository,
298 and there type:
299 \begin{verbatim}
300 % darcs pull http://your.server.org/repos/yourproject
301 \end{verbatim}
302 Darcs will check to see if you have recorded any changes that aren't in my
303 current repository. If so, it'll prompt me for each one, to see which ones
304 I want to add to my repository. Note that you may see a different series
305 of prompts depending on your answers, since sometimes one patch depends on
306 another, so if you answer yes to the first one, you won't be prompted for
307 the second if the first depends on it.
309 Of course, maybe I don't even have a copy of your repository. In that case
310 I'd want to do a
311 \begin{verbatim}
312 % darcs get http://your.server.org/repos/yourproject
313 \end{verbatim}
314 which gets the whole repository.
316 I could instead create an empty repository and fetch all of your patches
317 with pull. Get is just a more efficient way to clone a whole repository.
319 Get, pull and push also work over ssh. Ssh-paths are of the same form
320 accepted by scp, namely \verb|[username@]host:/path/to/repository|.
322 \section{Moving patches from one repository to another}
324 Darcs is flexible as to how you move patches from one repository to another.
325 This section will introduce all the ways you can get patches from one place
326 to another, starting with the simplest and moving to the most complicated.
328 \subsection{All pulls}
330 The simplest method is the ``all-pull'' method. This involves making each
331 repository readable (by http, ftp, nfs-mounted disk, whatever), and you
332 run \verb|darcs pull| in the repository you want to move the patch to. This is nice,
333 as it doesn't require you to give write access to anyone else, and is
334 reasonably simple.
336 \subsection{Send and apply manually}
338 Sometimes you have a machine on which it is not convenient to set up a web
339 server, perhaps because it's behind a firewall or perhaps for security
340 reasons, or because it is often turned off. In this case you can use
341 \verb|darcs send|
342 from that computer to generate a patch bundle destined for another
343 repository. You can either let darcs email the patch for you, or save it
344 as a file and transfer it by hand. Then in the destination repository you
345 (or the owner of that repository) run \verb|darcs apply| to apply the patches contained
346 in the bundle. This is also quite a simple method since, like the all-pull
347 method, it doesn't require that you give anyone write access to your
348 repository. But it's less convenient, since you have to keep track of the
349 patch bundle (in the email, or whatever).
351 If you use the send and apply method with email, you'll probably want to
352 create a \verb!_darcs/prefs/email! file containing your email address.
353 This way anyone who sends to your repository will automatically send the
354 patch bundle to your email address.
356 If you receive many patches by email, you probably will benefit by running
357 darcs apply directly from your mail program. I have in my \verb!.muttrc!
358 the following:
359 \begin{verbatim}
360 auto_view text/x-patch text/x-darcs-patch
361 macro pager A "<pipe-entry>darcs apply --verbose --mark-conflicts \
362 --reply droundy@abridgegame.org --repodir ~/darcs"
363 \end{verbatim}
364 which allows me to view a sent patch, and then apply the patch directly from \verb!mutt!, sending a
365 confirmation email to the person who sent me the patch. The autoview line relies on on the following
366 lines, or something like them, being present in one's \verb!.mailcap!:
367 \begin{verbatim}
368 text/x-patch; cat; copiousoutput
369 text/x-darcs-patch; cat; copiousoutput
370 \end{verbatim}
372 \subsection{Push}
374 If you use ssh (and preferably also ssh-agent, so you won't have to keep
375 retyping your password), you can use the push method to transfer changes
376 (using the scp protocol for communication). This method is again not very
377 complicated, since you presumably already have the ssh permissions set up.
378 Push can also be used when the target repository is local, in which case
379 ssh isn't needed. On the other hand, in this situation you could as easily
380 run a pull, so there isn't much benefit.
382 Note that you can use push to administer a multiple-user repository. You
383 just need to create a user for the repository (or repositories), and give
384 everyone with write access ssh access, perhaps using
385 \verb!.ssh/authorized_keys!. Then they run
386 \begin{verbatim}
387 % darcs push repouser@repo.server:repo/directory
388 \end{verbatim}
390 \subsection{Push ---apply-as}
392 Now we get more subtle. If you like the idea in the previous paragraph
393 about creating a repository user to own a repository which is writable by
394 a number of users, you have one other option.
396 Push \verb!--apply-as! can run on either a local repository or one accessed
397 with ssh, but uses \verb!sudo! to run a darcs apply command (having created
398 a patch bundle as in send) as another user. You can add the following line
399 in your \verb|sudoers| file to allow the users to apply their patches to a
400 centralized repository:
401 {\small
402 \begin{verbatim}
403 ALL ALL = (repo-user) NOPASSWD: /usr/bin/darcs apply --all --repodir /repo/path*
404 \end{verbatim}
406 This method is ideal for a centralized repository when all the users have
407 accounts on the same computer, if you don't want your users to be able to
408 run arbitrary commands as repo-user.
410 \subsection{Sending signed patches by email}
412 Most of the previous methods are a bit clumsy if you don't want to give
413 each person with write access to a repository an account on your server. Darcs
414 send can be configured to send a cryptographically signed patch by email.
415 You can then set up your mail system to have darcs verify that patches were
416 signed by an authorized user and apply them when a patch is received by
417 email. The results of the apply can be returned to the user by email.
418 Unsigned patches (or patches signed by unauthorized users) will be
419 forwarded to the repository owner (or whoever you configure them to be
420 forwarded to\ldots).
422 This method is especially nice when combined with the \verb!--test! option
423 of darcs apply, since it allows you to run the test suite (assuming you
424 have one) and reject patches that fail---and it's all done on the server,
425 so you can happily go on working on your development machine without
426 slowdown while the server runs the tests.
428 Setting up darcs to run automatically in response to email is by far the
429 most complicated way to get patches from one repository to another\ldots\ so it'll
430 take a few sections to explain how to go about it.
432 \paragraph{Security considerations}
434 When you set up darcs to run apply on signed patches, you should assume
435 that a user with write access can write to any file or directory that is
436 writable by the user under which the apply process runs. Unless you
437 specify the \verb!--no-test! flag to darcs apply (and this is \emph{not}
438 the default), you are also allowing anyone with write access to that
439 repository to run arbitrary code on your machine (since they can run a test
440 suite---which they can modify however they like). This is quite a
441 potential security hole.
443 For these reasons, if you don't implicitly trust your users, it is
444 recommended that you create a user for each repository to limit the damage
445 an attacker can do with access to your repository. When considering who to
446 trust, keep in mind that a security breach on any developer's machine could
447 give an attacker access to their private key and passphrase, and thus to
448 your repository.
450 \paragraph{Installing necessary programs}
452 You also must install the following programs: gnupg, a mailer configured to
453 receive mail (e.g.\ exim, sendmail or postfix), and a web server (usually
454 apache). If you want to be able to browse your repository on the web you
455 must also configure your web server to run cgi scripts and make sure the
456 darcs cgi script was properly installed (by either a darcs-server package,
457 or `make install-server').
459 \paragraph{Granting access to a repository}
461 You create your gpg key by running (as your normal user):
462 \begin{verbatim}
463 % gpg --gen-key
464 \end{verbatim}
465 You will be prompted for your name and email address, among other options.
466 %%To add your public key to the allowed keys keyring.
467 Of course, you can
468 skip this step if you already have a gpg key you wish to use.
470 You now need to export the public key so we can tell the patcher about it.
471 You can do this with the following command (again as your normal user):
472 \begin{verbatim}
473 % gpg --export "email@address" > /tmp/exported_key
474 \end{verbatim}
475 And now we can add your key to the \verb!allowed_keys!:
476 \begin{verbatim}
477 (as root)> gpg --keyring /var/lib/darcs/repos/myproject/allowed_keys \
478 --no-default-keyring --import /tmp/exported_key
479 \end{verbatim}
480 You can repeat this process any number of times to authorize multiple users
481 to send patches to the repository.
483 You should now be able to send a patch to the repository by running as your
484 normal user, in a working copy of the repository:
485 \begin{verbatim}
486 % darcs send --sign http://your.computer/repos/myproject
487 \end{verbatim}
488 You may want to add ``send sign'' to the file \verb!_darcs/prefs/defaults!
489 so that you won't need to type \verb!--sign! every time you want to
490 send\ldots
492 If your gpg key is protected by a passphrase, then executing \verb!send!
493 with the \verb!--sign! option might give you the following error:
494 \begin{verbatim}
495 darcs failed: Error running external program 'gpg'
496 \end{verbatim}
497 The most likely cause of this error is that you have a misconfigured
498 gpg that tries to automatically use a non-existent gpg-agent
499 program. GnuPG will still work without gpg-agent when you try to sign
500 or encrypt your data with a passphrase protected key. However, it will
501 exit with an error code 2 (\verb!ENOENT!) causing \verb!darcs! to
502 fail. To fix this, you will need to edit your \verb!~/.gnupg/gpg.conf!
503 file and comment out or remove the line that says:
504 \begin{verbatim}
505 use-agent
506 \end{verbatim}
507 If after commenting out or removing the \verb!use-agent! line in your
508 gpg configuration file you still get the same error, then you probably
509 have a modified GnuPG with use-agent as a hard-coded option. In that
510 case, you should change \verb!use-agent! to \verb!no-use-agent! to
511 disable it explicitly.
513 \paragraph{Setting up a sendable repository using procmail}
514 If you don't have root access on your machine, or perhaps simply don't want
515 to bother creating a separate user, you can set up a darcs repository using
516 procmail to filter your mail. I will assume that you already use procmail
517 to filter your email. If not, you will need to read up on it, or perhaps
518 should use a different method for routing the email to darcs.
520 To begin with, you must configure your repository so that a darcs send to
521 your repository will know where to send the email. Do this by creating a
522 file in \verb!/path/to/your/repo/_darcs/prefs! called \verb!email!
523 containing your email address. As a trick (to be explained below), we will
524 create the email address with ``darcs repo'' as your name, in an email
525 address of the form ``David Roundy $<$droundy@abridgegame.org$>$.''
526 \begin{verbatim}
527 % echo 'my darcs repo <user@host.com>' \
528 > /path/to/your/repo/_darcs/prefs/email
529 \end{verbatim}
531 The next step is to set up a gnupg keyring containing the public keys of
532 people authorized to send to your repository. Here I'll give a second way of
533 going about this (see above for the first). This time I'll assume you
534 want to give me write access to your repository. You can do this by:
535 \begin{verbatim}
536 gpg --no-default-keyring \
537 --keyring /path/to/the/allowed_keys --recv-keys D3D5BCEC
538 \end{verbatim}
539 This works because ``D3D5BCEC'' is the ID of my gpg key, and I have
540 uploaded my key to the gpg keyservers. Actually, this also requires that
541 you have configured gpg to access a valid keyserver. You can, of course,
542 repeat this command for all keys you want to allow access to.
544 Finally, we add a few lines to your \verb!.procmailrc!:
545 \begin{verbatim}
547 * ^TOmy darcs repo
548 |(umask 022; darcs apply --reply user@host.com \
549 --repodir /path/to/your/repo --verify /path/to/the/allowed_keys)
550 \end{verbatim}
551 The purpose for the ``my darcs repo'' trick is partially to make it easier
552 to recognize patches sent to the repository, but is even more crucial to
553 avoid nasty bounce loops by making the \verb!--reply! option have an email
554 address that won't go back to the repository. This means that unsigned
555 patches that are sent to your repository will be forwarded to your ordinary
556 email.
558 Like most mail-processing programs, Procmail by default sets a tight umask.
559 However, this will prevent the repository from remaining world-readable;
560 thus, the ``umask 022'' is required to relax the umask.
561 (Alternatively, you could set Procmail's global \verb!UMASK! variable
562 to a more suitable value.)
564 \paragraph{Checking if your e-mail patch was applied}
566 After sending a patch with \verb!darcs send!, you may not receive any feedback,
567 even if the patch is applied. You can confirm whether or not your patch was applied
568 to the remote repository by pointing \verb!darcs changes! at a remote repository:
569 \begin{verbatim}
570 darcs changes --last=10 --repo=http://darcs.net/
571 \end{verbatim}
573 That shows you the last 10 changes in the remote repository. You can adjust the options given
574 to \verb!changes! if a more advanced query is needed.
576 \section{Reducing disk space usage}
577 \label{disk-usage}
579 A Darcs repository contains the patches that Darcs uses to store
580 history, the working directory, and a \emph{pristine tree} (a copy of
581 the working directory files with no local modifications). For large
582 repositories, this can add up to a fair amount of disk usage.
584 There are two techniques that can be used to reduce the amount of
585 space used by Darcs repositories: linking and using no pristine tree.
586 The former can be used on any repository; the latter is only suitable
587 in special circumstances, as it makes some operations much slower.
589 \subsection{Linking between repositories}
591 A number of filesystems support \emph{linking} files, sharing a
592 single file data between different directories. Under some
593 circumstances, when repositories are very similar (typically because
594 they represent different branches of the same piece of software),
595 Darcs will use linking to avoid storing the same file multiple times.
597 Whenever you invoke \verb|darcs get| to copy a repository from a local
598 filesystem onto the same filesystem, Darcs will link patches whenever
599 possible.
601 In order to save time, \verb|darcs get| does not link pristine trees
602 even when individual files are identical. Additionally, as you pull
603 patches into trees, patches will become unlinked. This will result in
604 a lot of wasted space if two repositories have been living for a long
605 time but are similar. In such a case, you should \emph{relink} files
606 between the two repositories.
608 Relinking is an asymmetric operation: you relink one repository (to
609 which you must have write access) to another repository, called the
610 \emph{sibling}. This is done with \verb|darcs optimize --relink|, with
611 --the \verb|--sibling| flag specifying the sibling.
612 \begin{verbatim}
613 $ cd /var/repos/darcs.net
614 $ darcs optimize --relink --sibling /var/repos/darcs
615 \end{verbatim}
616 The \verb|--sibling| flag can be repeated multiple times, in which
617 case Darcs will try to find a file to link to in all of the siblings.
618 If a default repository is defined, Darcs will try, as a last resort,
619 to link against the default repository.
621 Additional space savings can be achieved by relinking files in the
622 pristine tree (see below) by using the \verb|--relink-pristine| flag.
623 However, doing this prevents Darcs from having precise timestamps on
624 the pristine files, which carries a moderate performance penalty.
626 \subsection{Alternate formats for the pristine tree}
628 By default, every Darcs repository contains a complete copy of the
629 \emph{pristine tree}, the working tree as it would be if there were no
630 local edits. By avoiding the need to consult a possibly large number
631 of patches just to find out if a file is modified, the pristine tree
632 makes a lot of operations much faster than they would otherwise be.
634 Under some circumstances, keeping a whole pristine tree is not
635 desirable. This is the case when preparing a repository to back up,
636 when publishing a repository on a public web server with limited
637 space, or when storing a repository on floppies or small USB keys. In
638 such cases, it is possible to use a repository with no pristine tree.
640 Darcs automatically recognizes a repository with no pristine
641 tree. In order to create such a tree, specify the
642 \verb|--no-pristine-tree| flag to \verb|darcs initialize| or
643 \verb|darcs get|. There is currently no way to switch an existing
644 repository to use no pristine tree.
646 The support for \verb|--no-pristine-tree| repositories is fairly new,
647 and has not been extensively optimized yet. Please let us know if you
648 use this functionality, and which operations you find are too slow.
650 \input{configuring_darcs.tex}
652 \input{best_practices.tex}
654 \input{formats.tex}
656 \chapter{Darcs commands}
658 \input{Darcs/Commands.lhs}
660 \begin{code}
661 assertions :: Control.Exception.Exception -> Maybe String
662 assertions (AssertionFailed s) = Just s
663 assertions _ = Nothing
665 execExceptionHandler :: ExecException -> IO a
666 execExceptionHandler (ExecException cmd args redirects reason) =
667 do putStrLn $ "Failed to execute external command: " ++ unwords (cmd:args) ++ "\n"
668 ++ "Lowlevel error: " ++ reason ++ "\n"
669 ++ "Redirects: " ++ show redirects ++"\n"
670 exitWith $ ExitFailure 3
672 main :: IO ()
673 main = with_atexit $ withSignalsHandled $
674 flip catchDyn execExceptionHandler $
675 handleJust assertions bug $ do
676 argv <- getArgs;
677 when (length argv < 1) $
678 do print_version
679 help_cmd [] []
680 \end{code}
681 \section{Options apart from darcs commands}
682 \begin{options}
683 --help, --overview
684 \end{options}
685 Calling darcs with just \verb|--help| as an argument gives a brief
686 summary of what commands are available.
687 The \verb|--overview| option gives a more technical summary of
688 what the commands actually \emph{do}.
689 \begin{code}
690 when (length argv == 1 && (argv!!0 == "-h" || argv!!0 == "--help")) $
691 help_cmd [] []
692 when (length argv == 1 && (argv!!0 == "--overview")) $
693 help_cmd [Verbose] []
694 \end{code}
695 \begin{options}
696 --version, --exact-version
697 \end{options}
698 Calling darcs with the flag \verb|--version| tells you the version of
699 darcs you are using. Calling darcs with the flag \verb|--exact-version|
700 gives the precise version of darcs, even if that version doesn't correspond
701 to a released version number. This is helpful with bug reports, especially
702 when running with a ``latest'' version of darcs.
703 \begin{code}
704 when (length argv == 1 && (argv!!0 == "-v" || argv!!0 == "--version")) $
705 do putStrLn darcs_version
706 exitWith $ ExitSuccess
707 when (length argv == 1 && (argv!!0 == "--exact-version")) $
708 do putStrLn $ "darcs compiled on "++__DATE__++", at "++__TIME__
709 putStrLn context
710 exitWith $ ExitSuccess
711 \end{code}
712 \begin{options}
713 --commands
714 \end{options}
715 Similarly calling darcs with only \verb|--commands| gives a simple list
716 of available commands. This latter arrangement is primarily intended for
717 the use of command-line autocompletion facilities, as are available in
718 bash.
719 \begin{code}
720 when (length argv == 1 && argv!!0 == "--commands") $
721 do list_available_commands
722 exitWith $ ExitSuccess
723 hSetBinaryMode stdin True
724 hSetBinaryMode stdout True
725 run_the_command (head argv) (tail argv)
726 \end{code}
728 \section{Getting help}
730 \input{Darcs/Commands/Help.lhs}
732 \section{Creating repositories}
734 \input{Darcs/Commands/Init.lhs}
736 \input{Darcs/Commands/Get.lhs}
738 \input{Darcs/Commands/Put.lhs}
740 \section{Modifying the contents of a repository}
742 \input{Darcs/Commands/Add.lhs}
744 \input{Darcs/Commands/Remove.lhs}
746 \input{Darcs/Commands/Mv.lhs}
748 \input{Darcs/Commands/Replace.lhs}
750 \section{Working with changes}
752 \input{Darcs/Commands/Record.lhs}
754 \input{Darcs/Commands/Pull.lhs}
756 \input{Darcs/Commands/Push.lhs}
758 \input{Darcs/Commands/Send.lhs}
760 \input{Darcs/Commands/Apply.lhs}
762 \section{Seeing what you've done}
764 \input{Darcs/Commands/WhatsNew.lhs}
766 \input{Darcs/Commands/Changes.lhs}
768 \input{Darcs/Commands/Show.lhs}
770 \section{More advanced commands}
772 \input{Darcs/Commands/Tag.lhs}
774 \input{Darcs/Commands/SetPref.lhs}
776 \input{Darcs/Commands/Check.lhs}
778 \input{Darcs/Commands/Optimize.lhs}
780 \section{Undoing, redoing and running in circles}
782 \input{Darcs/Commands/AmendRecord.lhs}
784 \input{Darcs/Commands/Rollback.lhs}
786 \input{Darcs/Commands/Unrecord.lhs}
788 \input{Darcs/Commands/Revert.lhs}
790 \input{Darcs/Commands/Unrevert.lhs}
792 \section{Advanced examination of the repository}
794 \input{Darcs/Commands/Diff.lhs}
796 \input{Darcs/Commands/Annotate.lhs}
798 % Includes the show commands.
799 \input{Darcs/Commands/Show.lhs}
801 \section{Rarely needed and obscure commands}
803 \input{Darcs/Commands/Convert.lhs}
805 \input{Darcs/Commands/MarkConflicts.lhs}
807 \input{Darcs/Commands/Dist.lhs}
809 \input{Darcs/Commands/TrackDown.lhs}
811 \input{Darcs/Commands/Repair.lhs}
813 \appendix
815 \input{Darcs/Patch.lhs}
817 \input{Darcs/Repository/DarcsRepo.lhs}
819 \input{gpl.tex}
821 \end{document}