Darcs is a revision control system, along the lines of CVS or arch. That means that it keeps track of various revisions and branches of your project, allows for changes to propagate from one branch to another. Darcs is intended to be an “advanced” revision control system. Darcs has two particularly distinctive features which differ from other revision control systems: 1) each copy of the source is a fully functional branch, and 2) underlying darcs is a consistent and powerful theory of patches.
Every source tree a branch The primary simplifying notion of darcs is that every copy of your source code is a full repository. This is dramatically different from CVS, in which the normal usage is for there to be one central repository from which source code will be checked out. It is closer to the notion of arch, since the ‘normal’ use of arch is for each developer to create his own repository. However, darcs makes it even easier, since simply checking out the code is all it takes to create a new repository. This has several advantages, since you can harness the full power of darcs in any scratch copy of your code, without committing your possibly destabilizing changes to a central repository.
Theory of patches The development of a simplified theory of patches is what originally motivated me to create darcs. This patch formalism means that darcs patches have a set of properties, which make possible manipulations that couldn’t be done in other revision control systems. First, every patch is invertible. Secondly, sequential patches (i.e. patches that are created in sequence, one after the other) can be reordered, although this reordering can fail, which means the second patch is dependent on the first. Thirdly, patches which are in parallel (i.e. both patches were created by modifying identical trees) can be merged, and the result of a set of merges is independent of the order in which the merges are performed. This last property is critical to darcs’ philosophy, as it means that a particular version of a source tree is fully defined by the list of patches that are in it, i.e. there is no issue regarding the order in which merges are performed. For a more thorough discussion of darcs’ theory of patches, see Appendix A.
A simple advanced tool Besides being “advanced” as discussed above, darcs is actually also quite simple. Versioning tools can be seen as three layers. At the foundation is the ability to manipulate changes. On top of that must be placed some kind of database system to keep track of the changes. Finally, at the very top is some sort of distribution system for getting changes from one place to another. Really, only the first of these three layers is of particular interest to me, so the other two are done as simply as possible. At the database layer, darcs just has an ordered list of patches along with the patches themselves, each stored as an individual file. Darcs’ distribution system is strongly inspired by that of arch. Like arch, darcs uses a dumb server, typically apache or just a local or network file system when pulling patches. darcs has built-in support for using ssh to write to a remote file system. A darcs executable is called on the remote system to apply the patches. Arbitrary other transport protocols are supported, through an environment variable describing a command that will run darcs on the remote system. See the documentation for DARCS_APPLY_FOO in Chapter 4 for details.
The recommended method is to send patches through gpg-signed email messages, which has the advantage of being mostly asynchronous.
Keeping track of changes rather than versions In the last paragraph, I explained revision control systems in terms of three layers. One can also look at them as having two distinct uses. One is to provide a history of previous versions. The other is to keep track of changes that are made to the repository, and to allow these changes to be merged and moved from one repository to another. These two uses are distinct, and almost orthogonal, in the sense that a tool can support one of the two uses optimally while providing no support for the other. Darcs is not intended to maintain a history of versions, although it is possible to kludge together such a revision history, either by making each new patch depend on all previous patches, or by tagging regularly. In a sense, this is what the tag feature is for, but the intention is that tagging will be used only to mark particularly notable versions (e.g. released versions, or perhaps versions that pass a time consuming test suite).
Other revision control systems are centered upon the job of keeping track of a history of versions, with the ability to merge changes being added as it was seen that this would be desirable. But the fundamental object remained the versions themselves.
In such a system, a patch (I am using patch here to mean an encapsulated set of changes) is uniquely determined by two trees. Merging changes that are in two trees consists of finding a common parent tree, computing the diffs of each tree with their parent, and then cleverly combining those two diffs and applying the combined diff to the parent tree, possibly at some point in the process allowing human intervention, to allow for fixing up problems in the merge such as conflicts.
In the world of darcs, the source tree is not the fundamental object, but rather the patch is the fundamental object. Rather than a patch being defined in terms of the difference between two trees, a tree is defined as the result of applying a given set of patches to an empty tree. Moreover, these patches may be reordered (unless there are dependencies between the patches involved) without changing the tree. As a result, there is no need to find a common parent when performing a merge. Or, if you like, their common parent is defined by the set of common patches, and may not correspond to any version in the version history.
One useful consequence of darcs’ patch-oriented philosophy is that since a patch need not be uniquely defined by a pair of trees (old and new), we can have several ways of representing the same change, which differ only in how they commute and what the result of merging them is. Of course, creating such a patch will require some sort of user input. This is a Good Thing, since the user creating the patch should be the one forced to think about what he really wants to change, rather than the users merging the patch. An example of this is the token replace patch (See Section A.3.2). This feature makes it possible to create a patch, for example, which changes every instance of the variable “stupidly_named_var” to “better_var_name”, while leaving “other_stupidly_named_var” untouched. When this patch is merged with any other patch involving the “stupidly_named_var”, that instance will also be modified to “better_var_name”. This is in contrast to a more conventional merging method which would not only fail to change new instances of the variable, but would also involve conflicts when merging with any patch that modifies lines containing the variable. By more using additional information about the programmer’s intent, darcs is thus able to make the process of changing a variable name the trivial task that it really is, which is really just a trivial search and replace, modulo tokenizing the code appropriately.
The patch formalism discussed in Appendix A is what makes darcs’ approach possible. In order for a tree to consist of a set of patches, there must be a deterministic merge of any set of patches, regardless of the order in which they must be merged. This requires that one be able to reorder patches. While I don’t know that the patches are required to be invertible as well, my implementation certainly requires invertibility. In particular, invertibility is required to make use of Theorem 2, which is used extensively in the manipulation of merges.
Record changes locally In darcs, the equivalent of a cvs “commit” is called record, because it doesn’t put the change into any remote or centralized repository. Changes are always recorded locally, meaning no net access is required in order to work on your project and record changes as you make them. Moreover, this means that there is no need for a separate “disconnected operation” mode.
Interactive records You can choose to perform an interactive record, in which case darcs will prompt you for each change you have made and ask if you wish to record it. Of course, you can tell darcs to record all the changes in a given file, or to skip all the changes in a given file, or go back to a previous change, or whatever. There is also an experimental graphical interface, which allows you to view and choose changes even more easily, and in whichever order you like.
Unrecord local changes As a corollary to the “local” nature of the record operation, if a change hasn’t yet been published to the world--that is, if the local repository isn’t accessible by others--you can safely unrecord a change (even if it wasn’t the most recently recorded change) and then re-record it differently, for example if you forgot to add a file, introduced a bug or realized that what you recorded as a single change was really two separate changes.
Interactive everything else Most darcs commands support an interactive interface. The “revert” command, for example, which undoes unrecorded changes has the same interface as record, so you can easily revert just a single change. Pull, push, send and apply all allow you to view and interactively select which changes you wish to pull, push, send or apply.
Test suites Darcs has support for integrating a test suite with a repository. If you choose to use this, you can define a test command (e.g. “make check”) and have darcs run that command on a clean copy of the project either prior to recording a change or prior to applying changes--and to reject changes that cause the test to fail.
Any old server Darcs does not require a specialized server in order to make a repository available for read access. You can use http, ftp, or even just a plain old ssh server to access your darcs repository.
You decide write permissions Darcs doesn’t try to manage write access. That’s your business. Supported push methods include direct ssh access (if you’re willing to give direct ssh access away), using sudo to allow users who already have shell access to only apply changes to the repository, or verification of gpg-signed changes sent by email against a list of allowed keys. In addition, there is good support for submission of patches by email that are not automatically applied, but can easily be applied with a shell escape from a mail reader (this is how I deal with contributions to darcs).
Symmetric repositories Every darcs repository is created equal (well, with the exception of a “partial” repository, which doesn’t contain a full history...), and every working directory has an associated repository. As a result, there is a symmetry between “uploading” and “downloading” changes--you can use the same commands (push or pull) for either purpose.
CGI script Darcs has a CGI script that allows browsing of the repositories.
Portable Darcs runs on UNIX (or UNIX-like) systems (which includes Mac OS X) as well as on Microsoft Windows.
File and directory moves Renames or moves of files and directories, of course are handled properly, so when you rename a file or move it to a different directory, its history is unbroken, and merges with repositories that don’t have the file renamed will work as expected.
Token replace You can use the “darcs replace” command to modify all occurrences of a particular token (defined by a configurable set of characters that are allowed in “tokens”) in a file. This has the advantage that merges with changes that introduce new copies of the old token will have the effect of changing it to the new token--which comes in handy when changing a variable or function name that is used throughout a project.
Configurable defaults You can easily configure the default flags passed to any command on either a per-repository or a per-user basis or a combination thereof.
Darcs is refreshingly different from CVS.
CVS keeps version controlled data in a central repository, and requires that users check out a working directory whenever they wish to access the version-controlled sources. In order to modify the central repository, a user needs to have write access to the central repository; if he doesn’t, CVS merely becomes a tool to get the latest sources.
In darcs there is no distinction between working directories and repositories. In order to work on a project, a user makes a local copy of the repository he wants to work in; he may then harness the full power of version control locally. In order to distribute his changes, a user who has write access can push them to the remote repository; one who doesn’t can simply send them by e-mail in a format that makes them easy to apply on the remote system.
Darcs commands for CVS users Because of the different models used by cvs and
darcs, it is difficult to provide a complete equivalence between cvs and darcs. A rough
correspondence for the everyday commands follows:
cvs checkout | darcs get | |
cvs update | darcs pull | |
cvs -n update | darcs pull --dry-run | (summarize remote changes) |
cvs -n update | darcs whatsnew --summary | (summarize local changes) |
cvs -n update | grep '?' | darcs whatsnew -ls | grep ^a | (list potential files to add) |
rm foo.txt; cvs update foo.txt | darcs revert foo.txt | (revert to foo.txt from repo) |
cvs diff | darcs whatsnew | (if checking local changes) |
cvs diff | darcs diff | (if checking recorded changes) |
cvs commit | darcs record | (if committing locally) |
cvs commit | darcs tag | (if marking a version for later use) |
cvs commit | darcs push or darcs send | (if committing remotely) |
cvs diff | mail | darcs send | |
cvs add | darcs add | |
cvs tag -b | darcs get | |
cvs tag | darcs tag |
Migrating CVS repositories to darcs
Tools and instructions for migrating CVS repositories
to darcs are provided on the darcs community website:
http://www.scannedinavian.org/DarcsWiki/ConvertingFromCvs
0http://www.scannedinavian.org/DarcsWiki/ConvertingFromCvs
Although arch, like darcs, is a distributed system, and the two systems have many similarities (both require no special server, for example), their essential organization is very different.
Like CVS, arch keeps data in two types of data structures: repositories (called “archives”) and working directories. In order to modify a repository, one must first check out a corresponding working directory. This requires that users remember a number of different ways of pushing data around -- tla get, update, commit, archive-mirror and so on.
In darcs, on the other hand, there is no distinction between working directories and repositories, and just checking out your sources creates a local copy of a repository. This allows you to harness the full power of version control in any scratch copy of your sources, and also means that there are just two ways to push data around: darcs record, which stores edits into your local repository, and pull, which moves data between repositories. (darcs push is merely the opposite of pull; send and apply are just the two halves of push).
Darcs commands for arch users
Because of the different models used by arch and darcs, it is difficult to provide a
complete equivalence between arch and darcs. A rough correspondence for the
everyday commands follows:
tla init-tree | darcs initialize | |
tla get | darcs get | |
tla update | darcs pull | |
tla file-diffs f | patch -R | darcs revert | |
tla changes --diffs | darcs whatsnew | |
tla logs | darcs changes | |
tla file-diffs | darcs diff -u | |
tla add | darcs add | |
tla mv | darcs mv | (not tla move) |
tla commit | darcs record | (if committing locally) |
tla commit | darcs tag | (if marking a version for later use) |
tla commit | darcs push or darcs send | (if committing remotely) |
tla archive-mirror | darcs pull or darcs push | |
tla tag | darcs get | (if creating a branch) |
tla tag | darcs tag | (if creating a tag). |
Migrating arch repositories to darcs
Tools and instructions for migrating arch repositories
to darcs are provided on the darcs community website:
http://www.scannedinavian.org/DarcsWiki/ConvertingFromArch
0http://www.scannedinavian.org/DarcsWiki/ConvertingFromArch
This chapter should walk you through the steps necessary to build darcs for yourself. There are in general two ways to build darcs. One is for building released versions from tarballs, and the other is to build the latest and greatest darcs, from the darcs repo itself.
Please let me know if you have any problems building darcs, or don’t have problems described in this chapter and think there’s something obsolete here, so I can keep this page up-to-date.
To build darcs you will need to have ghc, the Glorious Glasgow Haskell Compiler. You should have at the very minimum version 6.2.
It is a good idea (but not required) to have a recent version of libcurl installed. If not, you will at least need to have either wget or curl installed if you want to be able to grab repos remotely over normal network protocols (ftp or http). You also might want to have scp available if you want to grab your repos over ssh...
To send patches, you will also need to have a working /usr/sbin/sendmail or /usr/lib/sendmail, which is provided by most mail transport agents, and is generally available on linux and BSD systems. It’s also there on Mac OS X. However, if you don’t have this, it won’t stop you from building darcs.
To use the diff command of darcs, a diff program supporting options -r (recursive diff) and -N (show new files as differences against an empty file) is required. The configure script will look for gdiff, gnudiff and diff in this order. You can force the use of another program by setting the DIFF environment variable before running configure.
To rebuild the documentation (which should not be necessary since it is included in html form with the tarballs), you will need to have latex installed, as well as latex2html if you want to build it in html form.
To build on Mac OS X, you will need the Apple Developer Tools and the ghc 6.2 package installed. There seems to be a problem with ghc and Apple’s gcc 3.3, so you may need to run
% sudo gcc_select 3.1
|
Another recently discovered problem is that on MacOS, the curl-config from libcurl versions prior to 7.11.0 gives incorrect link flags, so you probably will want to make sure you have version 7.11.0 installed. I suspect one could also simply edit the curl-config of an older install to remove the offending “-arch i386”, but haven’t tried this.
To build on Microsoft Windows, you will need:
Copy the zlib and curl libraries and headers to both GHC and MinGW. GHC stores C headers in <ghc-dir>/gcc-lib/include and libraries in <ghc-dir>/gcc-lib. MinGW stores headers in <mingw-dir>/include and libraries in <mingw-dir>/lib.
Set PATH to include the <msys-dir>/bin, <mingw-dir>/bin, <curl-dir>, and a directory containing a pre-built darcs.exe if you want the build’s patch context stored for ‘darcs --exact-version’.
C:\darcs> cd <darcs-source-dir>
C:\darcs> sh $ export GHC=/c/<ghc-dir>/bin/ghc.exe $ autoconf $ ./configure --disable-mmap --target=mingw $ make |
If you get darcs from a tarball, the procedure (after unpacking the tarball itself) is as follows:
% ./configure
% make % make install |
There are options to configure that you may want to check out with
% ./configure --help
|
To build the latest darcs from its repository, you will first need a working copy of darcs. You can get darcs using:
% darcs get -v http://abridgegame.org/repos/darcs
|
% darcs pull
|
The repository doesn’t hold automatically generated files, which include the configure script and the HTML documentation, so you need to run autoconf first.
You’ll need autoconf 2.50 or higher. Some systems have more than one version of autoconf installed. For example, autoconf may point to version 2.13, while autoconf259 runs version 2.59.
Also note that make is really ”GNU make”. On some systems, such as the *BSDs, you may need to substitute gmake for this to work.
This also means you’ll need to have latex installed if you want the documentation.
% autoconf
% ./configure % make % make install |
If you want to tweak the configure options, you’ll need to run ./configure yourself after the make, and then run make again.
I know, this doesn’t really belong in this chapter, but if you’re using the repository version of darcs it’s really easy to submit patches to me using darcs. In fact, even if you don’t know any haskell, you could submit fixes or additions to this document (by editing building_darcs.tex) based on your experience building darcs...
To do so, just record your changes (which you made in the darcs repository)
% darcs record --no-test
|
% darcs send -u
|
This chapter will lead you through an example use of darcs, which hopefully will allow you to get started using darcs with your project.
Creating your repository in the first place just involves telling darcs to create the special directory (called _darcs) in your project tree, which will hold the revision information. This is done by simply calling from the root directory of your project:
% cd my_project/
% darcs initialize |
% darcs add *.c Makefile.am configure.ac
|
% darcs record --all
What is the patch name? Initial revision. |
Now that we have created our repository, make a change to one or more of your files. After making the modification run:
% darcs whatsnew
|
Let’s say you have now made a change to your project. The next thing to do is to record a patch. Recording a patch consists of grouping together a set of related changes, and giving them a name. It also tags the patch with the date it was recorded and your email address.
To record a patch simply type:
% darcs record
|
You can now rerun whatsnew, and see that indeed the changes you have recorded are no longer marked as new.
How do you let the world know about these wonderful changes? Obviously, they must be able to see your repository. Currently the easiest way to do this is typically by http using any web server. The recommended way to do this (using apache in a UNIX environment) is to create a directory called /var/www/repos, and then put a symlink to your repo there:
% cd /var/www/repos
% ln -s /home/username/myproject . |
As long as you’re running a web server and making your repo available to the world, you may as well make it easy for people to see what changes you’ve made. You can do this by running make installserver, which installs the program darcs_cgi at /usr/lib/cgi-bin/darcs. You also will need to create a cache directory named /var/cache/darcs_cgi, and make sure the owner of that directory is the same user that your web server runs its cgi scripts as. For me, this is www-data. Now your friends and enemies should be able to easily browse your repos by pointing their web browsers at http://your.server.org/cgi-bin/darcs. You can read more about this interface in Chapter ??.
Ok, so I can now browse your repository using my web browser... so what? How do I get your changes into my repository, where they can do some good? It couldn’t be easier. I just cd into my repository, and there type:
% darcs pull http://your.server.org/repos/yourproject
|
Of course, maybe I don’t even have a copy of your repository. In that case I’d want to do a
% darcs get http://your.server.org/repos/yourproject
|
I could instead create an empty repository and fetch all of your patches with pull. Get is just a more efficient way to clone a whole repository.
Get, pull and push also work over ssh. Ssh-paths are of the same form accepted by scp, namely [username@]host:/path/to/repository.
Darcs is flexible as to how you move patches from one repo to another. This section will introduce all the ways you can get patches from one place to another, starting with the simplest and moving to the most complicated.
The simplest method is the “all-pull” method. This involves making each repository readable (by http, ftp, nfs-mounted disk, whatever), and you run ‘darcs pull’ in the repo you want to move the patch to. This is nice, as it doesn’t require you to give write access to anyone else, and is reasonably simple.
Sometimes you have a machine on which it is not convenient to set up a web server, perhaps because it’s behind a firewall or perhaps for security reasons, or because it is often turned off. In this case you can use darcs send from that computer to generate a patch bundle destined for another repository. You can either let darcs email the patch for you, or save it as a file and transfer it by hand. Then in the destination repository you (or the owner of that repo) run darcs apply to apply the patches contained in the bundle. This is also quite a simple method since, like the all-pull method, it doesn’t require that you give anyone write access to your repository. But it’s less convenient, since you have to keep track of the patch bundle (in the email, or whatever).
If you use the send and apply method with email, you’ll probably want to create a _darcs/prefs/email file containing your email address. This way anyone who sends to your repository will automatically send the patch bundle to your email address.
If you receive many patches by email, you probably will benefit by running darcs apply directly from your mail program. I have in my .muttrc the following
macro pager A "<pipe-entry>darcs apply --verbose --mark-conflicts \
--reply droundy@abridgegame.org --repodir ~/darcs" |
If you use ssh (and preferably also ssh-agent, so you won’t have to keep retyping your password), you can use the push method to transfer changes (using the scp protocol for communication). This method is again not very complicated, since you presumably already have the ssh permissions set up. Push can also be used when the target repository is local, in which case ssh isn’t needed. On the other hand, in this situation you could as easily run a pull, so there isn’t much benefit.
Note that you can use push to administer a multiple-user repository. You just need to create a user for the repository (or repositories), and give everyone with write access ssh access, perhaps using .ssh/authorized_keys. Then they run
% darcs push repouser@repo.server:repo/directory
|
Now we get more subtle. If you like the idea in the previous paragraph about creating a repository user to own a repository which is writable by a number of users, you have one other option.
Push --apply-as can run on either a local repository or one accessed with ssh, but uses sudo to run a darcs apply command (having created a patch bundle as in send) as another user. You can add the following line in your sudoers file to allow the users to apply their patches to a centralized repository:
ALL ALL = (repo-user) NOPASSWD: /usr/bin/darcs apply --repodir /repo/path*
|
Most of the previous methods are a bit clumsy if you don’t want to give each person with write access to a repo an account on your server. Darcs send can be configured to send a cryptographically signed patch by email. You can then set up your mail system to have darcs verify that patches were signed by an authorized user and apply them when a patch is received by email. The results of the apply can be returned to the user by email. Unsigned patches (or patches signed by unauthorized users) will be forwarded to the repository owner (or whoever you configure them to be forwarded to...).
This method is especially nice when combined with the --test option of darcs apply, since it allows you to run the test suite (assuming you have one) and reject patches that fail--and it’s all done on the server, so you can happily go on working on your development machine without slowdown while the server runs the tests.
Setting up darcs to run automatically in response to email is by far the most complicated way to get patches from one repo to another... so it’ll take a few sections to explain how to go about it.
Security considerations When you set up darcs to run apply on signed patches, you should assume that a user with write access can write to any file or directory that is writable by the user under which the apply process runs. Unless you specify the --no-test flag to darcs apply (and this is not the default), you are also allowing anyone with write access to that repository to run arbitrary code on your machine (since they can run a test suite--which they can modify however they like). This is quite a potential security hole.
For these reasons, if you don’t implicitly trust your users, it is recommended that you create a user for each repository to limit the damage an attacker can do with access to your repository. When considering who to trust, keep in mind that a security breach on any developer’s machine could give an attacker access to their private key and passphrase, and thus to your repository.
Installing necessary programs You also must install the following programs: gnupg, a mailer configured to receive mail (e.g. exim, sendmail or postfix), and a web server (usually apache). If you want to be able to browse your repository on the web you must also configure your web server to run cgi scripts and make sure the darcs cgi script was properly installed (by either a darcs-server package, or ‘make install-server’).
Setting up a repository with its own user To create a repository, as root run the ‘darcs-createrepo’. You will be prompted for the email address of the repository and the location of an existing copy of the repository. If your desired email is “myproject@my.url”, this will create a user named “myproject” with a home directory of /var/lib/darcs/repos/myproject. FIXME: I have no idea if the darcs-createrepo program will even run on any system other than debian. Success reports would be appreciated (or of course bug reports if it fails).
The “myproject” user will be configured to run the darcs patcher on any emails it receives. However, the patcher will bounce any emails which aren’t signed by a key in the /var/lib/darcs/repos/myproject/allowed_keys gpg keyring (which is empty). To give yourself access to this repository you will need to create a gpg key. If you don’t know about public key cryptography, take a look at the gnupg manual.
Granting access to a repository You create your gpg key by running (as your normal user):
% gpg --gen-key
|
You now need to export the public key so we can tell the patcher about it. You can do this with the following command (again as your normal user):
% gpg --export "email@address" > /tmp/exported_key
|
(as root)> gpg --keyring /var/lib/darcs/repos/myproject/allowed_keys \
--no-default-keyring --import /tmp/exported_key |
You should now be able to send a patch to the repository by running as your normal user, in a working copy of the repository:
% darcs send --sign http://your.computer/repos/myproject
|
If your gpg key is protected by a passphrase, then executing send with the --sign option might give you the following error:
darcs failed: Error running external program 'gpg'
|
use-agent
|
Setting up a sendable repository using procmail If you don’t have root access on your machine, or perhaps simply don’t want to bother creating a separate user, you can set up a darcs repository using procmail to filter your mail. I will assume that you already use procmail to filter your email. If not, you will need to read up on it, or perhaps should use a different method for routing the email to darcs. To begin with, you must configure your repository so that a darcs send to your repository will know where to send the email. Do this by creating a file in /path/to/your/repo/_darcs/prefs called email containing your email address. As a trick (to be explained below), we will create the email address with “darcs repo” as your name, in an email address of the form “David Roundy <droundy@abridgegame.org>.”
% echo 'my darcs repo <user@host.com>' > /path/to/your/repo/_darcs/prefs/email
|
The next step is to set up a gnupg keyring containing the public keys of people authorized to send to your repo. Here I’ll give a second way of going about this (see above for the first). This time I’ll assume you want to give me write access to your repository. You can do this by:
gpg --no-default-keyring \
--keyring /path/to/the/allowed_keys --recv-keys D3D5BCEC |
Finally, we add a few lines to your .procmailrc:
:0:
* ^TOmy darcs repo |(umask 022; darcs apply --reply user@host.com \ --repodir /path/to/your/repo --verify /path/to/the/allowed_keys) |
I find that I need the “umask 022” in order to keep procmail from setting the umask incorrectly, which causes the repository to no longer be world-readable.
Checking if your e-mail patch was applied After sending a patch with darcs send, you may not receive any feedback, even if the patch is applied. You can confirm whether or not your patch was applied to the remote repo by pointing darcs changes at a remote repo:
darcs changes --last=10 --repo=http://abridgegame.org/repos/darcs
|
That shows you the last 10 changes in the remote repo. You can adjust the options given to changes if a more advanced query is needed.
A Darcs repository contains the patches that Darcs uses to store history, the working directory, and a pristine tree (a copy of the working directory files with no local modifications). For large repositories, this can add up to a fair amount of disk usage.
There are two techniques that can be used to reduce the amount of space used by Darcs repositories: linking and using no pristine tree. The former can be used on any repository; the latter is only suitable in special circumstances, as it makes some operations much slower.
A number of filesystems support linking files, sharing a single file data between different directories. Under some circumstances, when repositories are very similar (typically because they represent different branches of the same piece of software), Darcs will use linking to avoid storing the same file multiple times.
Whenever you invoke darcs get to copy a repository from a local filesystem onto the same filesystem, Darcs will link patches whenever possible.
In order to save time, darcs get does not link pristine trees even when individual files are identical. Additionally, as you pull patches into trees, patches will become unlinked. This will result in a lot of wasted space if two repositories have been living for a long time but are similar. In such a case, you should relink files between the two repositories.
Relinking is an assymmetric operation: you relink one repository (to which you must have write access) to another repository, called the sibling. This is done with darcs optimize --relink, with -the --sibling flag specyfing the sibling.
$ cd /var/repos/darcs-unstable
$ darcs optimize --relink --sibling /var/repos/darcs |
By default, every Darcs repository contains a complete copy of the pristine tree, the working tree as it would be if there were no local edits. By avoiding the need to consult a possibly large number of patches just to find out if a file is modified, the pristine tree makes a lot of operations much faster than they would otherwise be.
Under some circumstances, keeping a whole pristine tree is not desirable. This is the case when preparing a repository to back up, when publishing a repository on a public web server with limited space, or when storing a repository on floppies or small USB keys. In such cases, it is possible to use a repository with no pristine tree.
Darcs automatically recognises a repository with no pristine tree2. In order to create such a tree, specify the --no-pristine-tree flag to darcs initialize or darcs get. There is currently no way to switch an existing repository to use no pristine tree.
The support for --no-pristine-tree repositories is fairly new, and has not been extensively optimised yet. Please let us know if you use this functionality, and which operations you find are too slow.
There are sevaral ways you can adjust darcs’ behavior to suit your needs. The first is to edit files in the _darcs/prefs/ directory of a repository. Such configuration only applies when working with that repository. To configure darcs on a per-user rather than per-repository basis (but with essentially the same methods), you can edit (or create) files in the ~/.darcs/ directory. Finally, the behavior of some darcs commands can be modified by setting appropriate environment variables.
The _darcs directory contains a prefs directory. This directory exists simply to hold user configuration settings specific to this repository. The contents of this directory are intended to be modifiable by the user, although in some cases a mistake in such a modification may cause darcs to behave strangely.
defaults Default values for darcs commands can be configured on a per-repository basis by editing (and possibly creating) the _darcs/prefs/defaults file. Each line of this file has the following form:
COMMAND FLAG VALUE
|
~/.darcs/defaults | provides defaults for this user account |
project/_darcs/pref/defaults | provides defaults for one project, overrules changes per user |
For example, if your system clock is bizarre, you could instruct darcs to always ignore the file modification times by adding the following line to your _darcs/prefs/defaults file. (Note that this would have to be done for each repository!)
ALL ignore-times
|
If you never want to run a test when recording to a particular repository (but still want to do so when running check on that repo), and like to name all your patches “Stupid patch”, you could use the following:
record no-test
record patch-name Stupid patch |
There are some options which are meant specifically for use in _darcs/prefs/defaults. One of them is --disable. As the name suggests, this option will disable every command that got it as argument. So, if you are afraid that you could damage your repositories by inadvertant use of a command like amend-record, add the following line to _darcs/prefs/defaults:
amend-record disable
|
Also, a global preferences file can be created with the name .darcs/defaults in your home directory. Options present there will be added to the repository-specific preferences. If they conflict with repository-specific options, the repository-specific ones will take precedence.
repos The _darcs/prefs/repos file contains a list of repositories you have pulled from or pushed to, and is used for autocompletion of pull and push commands in bash. Feel free to delete any lines from this list that might get in there, or to delete the file as a whole.
author The _darcs/prefs/author file contains the email address (or name) to be used as the author when patches are recorded in this repository, e.g. “David Roundy ¡droundy@abridgegame.org¿”. This file overrides the contents of the environment variables $DARCS_EMAIL and $EMAIL.
boring The _darcs/prefs/boring file may contain a list of regular expressions describing files, such as object files, that you do not expect to add to your project. As an example, the boring file that I use with my darcs repository is:
\.hi$
\.o$ ^\.[^/] ^_ ~$ (^|/)CVS($|/) |
You may want to have the boring file under version control. To do this you can use darcs setpref to set the value “boringfile” to the name of your desired boring file (e.g. “darcs setpref boringfile .boring”, where .boring is the repository path of a file that has been darcs added to your repository). The boringfile pref overrides _darcs/prefs/boring, so be sure to copy that file to the boringfile.
You can also set up a “boring” regexps file in your home directory, named ~/.darcs/boring, which will be used with all of your darcs repositories.
Any file whose repository path (such as manual/index.html) matches any of the boring regular expressions is considered boring. The boring file is used to filter the files provided to darcs add, to allow you to use a simple “darcs add newdir newdir/*” without accidentally adding a bunch of object files. It is also used when the --look-for-adds flag is given to whatsnew or record.
binaries The _darcs/prefs/binaries file may contain a list of regular expressions describing files that should be treated as binary files rather than text files. You probably will want to have the binaries file under version control. To do this you can use darcs setpref to set the value “binariesfile” to the name of your desired binaries file (e.g. “darcs setpref binariesfile ./.binaries”, where .binaries is a file that has been darcs added to your repository). As with the boring file, you can also set up a ~/.darcs/binaries file if you like.
There are a few environment variables whose contents affect darcs’ behavior.
DARCS_EMAIL The DARCS_EMAIL environment variable determines the “author” name used by darcs when recording if no _darcs/prefs/author exists. If DARCS_EMAIL is undefined, the contents of the EMAIL environment variable are used.
DARCS_EDITOR When pulling up an editor (for example, when adding a long comment in record), darcs uses the contents of DARCS_EDITOR if it is defined. If not, it tries the contents of VISUAL, and if that isn’t defined (or fails for some reason), it tries EDITOR. If none of those environment variables are defined, darcs tries vi, emacs, emacs -nw and nano in that order.
DARCS_TMPDIR If the environment variable DARCS_TMPDIR is defined, darcs will use that directory for its temporaries. Otherwise it will use TMPDIR, if that is defined, and if not that then /tmp and if /tmp doesn’t exist, it’ll put the temporaries in _darcs.
This is very helpful, for example, when recording with a test suite that uses MPI, in which case using /tmp to hold the test copy is no good, as /tmp isn’t shared over NFS and thus the mpirun call will fail, since the binary isn’t present on the compute nodes.
HOME HOME is used to find the per-user prefs directory, which is located at $HOME/.darcs.
TERM If darcs is compiled with libcurses support and support for color output, it uses the environment variable TERM to decide whether or not color is supported on the output terminal.
SSH_PORT When using ssh, if the SSH_PORT environment variable is defined, darcs will use that port rather than the default ssh port (which is 22).
DARCS_SSH The DARCS_SSH environment variable defines the command that darcs will use when asked to run ssh. This command is not interpreted by a shell, so you cannot use shell metacharacters, and the first word in the command must be the name of an executable located in your path.
DARCS_SCP and DARCS_SFTP The DARCS_SCP and DARCS_SFTP environment variables define the commands that darcs will use when asked to run scp or sftp. Note that scp and sftp is how darcs accesses repositories whose URL is of the form user@foo.org:foo or foo.org:foo. Darcs will use scp to copy single files (e.g. repository meta-information), and sftp to copy multiple files in batches (e.g. patches). These commands are not interpreted by a shell, so you cannot use shell metacharacters, and the first word in the command must be the name of an executable located in your path.
DARCS_PROXYUSERPWD This environment variable allows DARCS and libcurl to access remote repositories via a password-protected HTTP proxy. The proxy itself is specified with the standard environment variable for this purpose, namely ’http_proxy’. The DARCS_PROXYUSERPWD environment variable specifies the proxy username and password. It must be given in the form username:password.
DARCS_USE_ISPRINT There is currently no way to specify the character encoding of a darcs repository, so darcs will by default print everything that is not printable ASCII characters as hexadecimal escape codes. This protects the terminal from (possibly malicious) control codes. If the repository is encoded in the system’s locale and it is an 8-bit, single-byte encoding, (e.g. ISO 8859-1), darcs can use the library function isPrint to check for printable characters, including non-ASCII. Setting the environment variable DARCS_USE_ISPRINT=1 enables this. It does not work for multi-byte encodings like UTF-8.
DARCS_GET_FOO, DARCS_MGET_FOO and DARCS_APPLY_FOO When trying to access a repository with a url beginning foo://, darcs will invoke the program specified by the DARCS_GET_FOO environment variable (if defined) to download each file, and the command specified by the DARCS_APPLY_FOO environment variable (if defined) when pushing to a foo:// url. This method overrides all other ways of getting foo://xxx urls.
Note that each command should be constructed so that it sends the downloaded content to STDOUT, and the next argument to it should be the URL. Here are some examples that should work for DARCS_GET_HTTP:
fetch -q -o -
curl -s lynx -source wget -q -O - |
If set, DARCS_MGET_FOO will be used to fetch many files from a single repository simultaneously. Replace FOO and foo as appropriate to handle other URL schemes. These commands are not interpreted by a shell, so you cannot use shell metacharacters, and the first word in the command must be the name of an executable located in your path. The GET command will be called with a url for each file, the MGET command will be invoked with a number of urls and is expected to download the files to the current directory, preserving the filename but not the path, the APPLY command will be called with a darcs patchfile piped into its standard input. Example:
wget -q
|
DARCS_MGETMAX When invoking a DARCS_MGET_FOO command, darcs will limit the number of urls presented to the command to the value of this variable, if set, or 200.
DARCS_WGET This is a very old option that is only used if libcurl is not compiled in and one of the DARCS_GET_FOO is not used. Using one of those is recommended instead.
The DARCS_WGET environment variable defines the command that darcs will use to fetch all URLs for remote repositories. The first word in the command must be the name of an executable located in your path. Extra arguments can be included as well, such as:
wget -q
|
Darcs will append -i to the argument list, which it uses to provide a list of URLS to download. This allows wget to download multiple patches at the same time. It’s possible to use another command besides wget with this environment variable, but it must support the -i option in the same way.
These commands are not interpreted by a shell, so you cannot use shell meta-characters.
This chapter is intended to review various scenarios and describe in each case effective ways of using darcs. There is no one “best practice”, and darcs is a sufficiently low-level tool that there are many high-level ways one can use it, which can be confusing to new users. The plan (and hope) is that various users will contribute here describing how they use darcs in different environments. However, this is not a wiki, and contributions will be edited and reviewed for consistency and wisdom.
This section will lay down the concepts around which darcs functions. The aim is to develop a way of thinking that corresponds well to how darcs is behaving -- even in complicated situations.
Darcs is change based. Changes are recorded in patches. Patches are copied to other branches to incorporate the changes there. Patches can be thrown away to make a branch go back in time. Patches are, as much as possible, independent; you can include some patches but exclude others in a branch. This can be used to find out exactly what patch introduced a bug.
In a single darcs repository you can think of two “versions” of the source tree. They are called the working and pristine trees. Working is your normal source tree, with or without darcs alongside. The only thing that makes it part of a darcs repository is the _darcs directory in its root. Pristine is the recorded state of the source tree. The pristine tree is constructed from groups of changes, called patches (some other version control use the term changeset instead of patch).footnoteIf you look inside _darcs you will find files or directories named ‘patches’ and ‘inventories’, which store all the patches ever recorded. If the repository holds a cached pristine tree, it is stored in a directory called pristine or current; otherwise, the fact that there is no prisine tree is marked by the presence of a file called pristine.none or current.none.
If working and pristine are the same, there are “no changes” in the repository. Changes can be introduced (or removed) by editing the files in working. They can also be caused by darcs commands, which can modify both working and pristine. It is important to understand for each darcs command how it modifies working, pristine or both of them.
whatsnew (as well as diff) can show the difference between working and pristine to you. It will be shown as a difference in working. In advanced cases it need not be working that has changed; it can just as well have been pristine, or both. The important thing is the difference and what darcs can do with it.
If you have a difference in working, you do two things with it: record it to keep it, or revert it to lose the changes.1
If you have a difference between working and pristine--for example after editing some files in working--whatsnew will show some “unrecorded changes”. To save these changes, use record. It will create a new patch in pristine with the same changes, so working and pristine are no longer different. To instead undo the changes in working, use revert. It will modify the files in working to be the same as in pristine (where the changes do not exist).
unrecord is a command meant to be run only in private repositories. It’s intention is to allow developers the flexibility to undo patches that haven’t been distributed yet.
However, darcs does not prevent you from unrecording a patch that has been copied to another repository. Be aware of this danger!
If you unrecord a patch, that patch will be deleted from pristine. This will cause working to be different from pristine, and whatsnew to report unrecorded changes. The difference will be the same as just before that patch was recorded. Think about it. record examines what’s different with working and constructs a patch with the same changes in pristine so they are no longer different. unrecord deletes this patch; the changes in pristine disappear and the difference is back.
If the recorded changes included an error, the resulting flawed patch can be unrecorded. When the changes have been fixed, they can be recorded again as a new--hopefully flawless--patch.
If the whole change was wrong it can be discarded from working too, with revert. revert will update working to the state of pristine, in which the changes do no longer exist after the patch was deleted.
Keep in mind that the patches are your history, so deleting them with unrecord makes it impossible to track what changes you really made. Redoing the patches is how you “cover the tracks”. On the other hand, it can be a very convenient way to manage and organize changes while you try them out in your private repository. When all is ready for shipping, the changes can be reorganized in what seems as useful and impressive patches. Use it with care.
All patches are global, so don’t ever replace an already “shipped” patch in this way! If an erroneous patch is deleted and replaced with a better one, you have to replace it in all repositories that have a copy of it. This may not be feasible, unless it’s all private repositories. If other developers have already made patches or tags in their repositories that depend on the old patch, things will get complicated.
Write me!
Write me!
This is how darcs itself is developed. There are many contributors to darcs, but every contribution is reviewed and manually applied by myself. For this sort of a situation, ’darcs send’ is ideal, since the barrier for contributions is very low, which helps encourage contributors.
One could simply set the _darcs/prefs/email value to the project mailing list, but I also use darcs send to send my changes to the main server, so instead the email address is set to “Davids Darcs Repo <droundy@abridgegame.org>”. My .procmailrc file on the server has the following rule:
:0:
* ^TODavids Darcs Repo |(umask 022; darcs apply --reply darcs-devel@abridgegame.org \ --repodir /path/to/repo --verify /path/to/allowed_keys) |
The central darcs repository contains the following values in its _darcs/prefs/defaults:
apply test
apply verbose apply happy-forwarding |
On my development computer, I have in my .muttrc the following alias, which allows me to easily apply patches that I get via email directly to my darcs working directory:
macro pager A "<pipe-entry>(umask 022; darcs apply --no-test -v --repodir ~/darcs)"
|
This section describes the development method used for the density functional theory code DFT++, which is available at http://dft.physics.cornell.edu/dft.
We have a number of workstations which all mount the same /home via NFS. We created a special “dft” user, with the central repository living in that user’s home directory. The ssh public keys of authorized persons are added to the “dft” user’s .ssh/allowed_keys, and we commit patches to this repository using darcs push. As in Section 5.3, we have the central repository set to run the test suite before the push goes through.
Note that no one ever runs as the dft user.
A subtlety that we ran into showed up in the running of the test suite. Since our test suite includes the running of MPI programs, it must be run in a directory that is mounted across our cluster. To achieve this, we set the $DARCS_TMPDIR environment variable to ~/tmp.
Note that even though there are only four active developers at the moment, the distributed nature of darcs still plays a large role. Each developer works on a feature until it is stable, a process that often takes quite a few patches, and only once it is stable pushes to the central repo.
The general format of a darcs command is
% darcs COMMAND OPTIONS ARGUMENTS ...
|
If you wish, you may use any unambiguous beginning of a command name as a shortcut: for darcs record, you could type darcs recor or darcs rec, but not darcs re since that could be confused with darcs replace, darcs revert and darcs remove.
Command overview Not all commands modify the ”patches” of your repository (that is, the named patches which other users can pull), some commands only affect the copy of the source tree you’re working on (your ”working directory”), and some affect both. This table summarizes what you should expect from each one and will hopefully serve as guide when you’re having doubts about which command to use.
Every COMMAND accepts --help as an argument, which tells it to provide a bit of help. Among other things, this help always provides an accurate listing of the options available with that command, and is guaranteed never to be out of sync with the version of darcs you actually have installed (unlike this manual, which could be for an entirely different version of darcs).
% darcs COMMAND --help
|
Every COMMAND accepts the --disable option, which can be used in _darcs/prefs/defaults to disable some commands in the repository. This can be helpful if you want to protect the repository from accidential use of advanced commands like unpull, unrecord or amend-record.
Most commands also accept the --verbose option, which tells darcs to provide additional output. The amount of verbosity varies from command to command.
Another common option is the --repodir option, which allows you to specify the directory of the repository in which to perform the command. This option is used with commands, such as whatsnew, that ordinarily would be performed within a repository directory, and allows you to use those commands without actually being in the repo directory when calling the command. This is useful when running darcs as a pipe, as might be the case when running apply from a mailer.
Selecting patches Many commands operate on a patch or patches that have already been recorded. There are a number of options that specify which patches are selected for these operations: --patch, --match, --tag, and variants on these, which for --patch are --patches, --from-patch, and --to-patch. The --patch and --tag forms simply take (POSIX extended, aka egrep) regular expressions and match them against tag and patch names. --match, described below, allows more powerful patterns.
The plural forms of these options select all matching patches. The singular forms select the last matching patch. The range (from and to) forms select patches after (exclusive) or up to (inclusive) the last matching patch.
These options use the current order of patches in the repository. darcs may reorder patches, so this is not necessarily the order of creation or the order in which patches were applied. However, as long as you are just recording patches in your own repository, they will remain in order.
Match Currently --match accepts three primitive match types, although there are plans to expand it to match more patterns. Also, note that the syntax is still preliminary and subject to change.
The first match type accepts a regular expression which is checked against the patch name. The syntax is
darcs annotate --summary --match 'name foo'
|
The second match type matches the darcs hash for each patch:
darcs annotate --summary --match \
'hash 20040403105958-53a90-c719567e92c3b0ab9eddd5290b705712b8b918ef' |
There is also now rudimentary support for matching by date. This is done using commands such as
darcs annotate --summary --match 'date "last week"'
darcs annotate --summary --match 'date yesterday' darcs annotate --summary --match 'date yesterday' darcs changes --from-match 'date "Sat Jun 30 11:31:30 EDT 2004"' |
Because the date matching is only by day, you may prefer to combine it with a more specific pattern.
darcs annotate --summary --match 'date "last week" && name foo'
|
The --match pattern can include the logical operators &&, || and not, as well as grouping of patterns with parentheses. For example
darcs annotate --summary --match 'name record && not name overrode'
|
Darcs optimizes its operations by keeping track of the modification times of your files. This dramatically speeds up commands such as whatsnew and record which would otherwise require reading every file in the repo and comparing it with a reference version. However, there are times when this can cause problems, such as when running a series of darcs commands from a script, in which case often a file will be modified twice in the same second, which can lead to the second modification going unnoticed. The solution to such predicaments is the --ignore-times option, which instructs darcs not to trust the file modification times, but instead to check each file’s contents explicitly.
Several commands need to be able to identify you. Conventionally, you provide an email address for this purpose, which can include comments, e.g. “David Roundy ¡droundy@abridgegame.org¿”. The easiest way to do this is to define an environment variable EMAIL or DARCS_EMAIL (with the latter overriding the former). You can also override this using the --author flag to any command. Alternatively, you could set your email address on a per-repository basis using the “defaults” mechanism for “ALL” commands, as described in Appendix B. Or, you could specify the author on a per-repository basis using the _darcs/prefs/author file as described in section 4.1.
Also, a global author file can be created with the name .darcs/author in your home directory. This file overrides the contents of the environment variables, but a repository-specific author file overrides the global author file.
By default, darcs commands that write patches to disk will compress the patch files. If you don’t want this, you can choose the --dont-compress option, which causes darcs not to compress the patch file.
Certain commands may have an optional graphical user interface. If such commands are supported, you can activate the graphical user interface by calling darcs with the --gui flag.
The --dry-run option will cause darcs to not actually take the specified action. but only print what would have happened. Not all commands accept --dry-run, but those that do should accept the --summary option.
The --summary show a summary of the patches that would have been pulled/pushed/whatever. The format is similar to the output format of cvs update and looks like this:
A ./added_but_not_recorded.c
A! ./added_but_not_recorded_conflicts.c a ./would_be_added_if_look_for_adds_option_was_used.h M ./modified.t -1 +1 M! ./modified_conflicts.t -1 +1 R ./removed_but_not_recorded.c R! ./removed_but_not_recorded_conflicts.c |
You can probably guess what the flags mean from the clever file names.
A is for files that have been added but not recorded yet. a is for files found using the --look-for-adds option available for whatsnew and record. They have not been added yet, but would be added automatically if --look-for-adds were used with the next record command.
M is for files that have been modified in the working directory but not recorded yet. The number of added and subtracted lines is also shown.
R is for files that have been removed, but the removal is not recorded yet.
An explanation mark appears next to any option that has a conflict.
Resolution of conflicts To resolve conflicts using an external tool, you need to specify a command to use, e.g.
--external-merge 'opendiff %1 %2 -ancestor %a -merge %o'.
|
--external-merge 'xxdiff -m -O -M %o %1 %a %2'
|
--external-merge 'kdiff3 --output %o %a %1 %2'
|
Note that if you do use an external merge tool, most likely you will want to your defaults file _darcs/prefs/defaults (see 4.1) a line such as
ALL external-merge kdiff3 --output %o %a %1 %2
|
Options apart from darcs commands Calling darcs with just “--help” as an argument gives a brief summary of what commands are available. The “--extended-help” option gives a more technical summary of what the commands actually do. Calling darcs with the flag “--version” tells you the version of darcs you are using. Calling darcs with the flag “--exact-version” gives the precise version of darcs, even if that version doesn’t correspond to a released version number. This is helpful with bug reports, especially when running with a “latest” version of darcs. Similarly calling darcs with only “--commands” gives a simple list of available commands. This latter arrangement is primarily intended for the use of command-line autocompletion facilities, as are available in bash.
Usage: darcs initialize [OPTION]...
Options:
--plain-pristine-tree |
|
||
--no-pristine-tree |
|
||
Initialize a new source tree as a darcs repository.
Generally you will only call initialize once for each project you work on, and calling it is just about the first thing you do. Just make sure you are in the main directory of the project, and initialize will set up all the directories and files darcs needs in order to start keeping track of revisions for your project.
initialize actually follows a very simple procedure. It simply creates the directories _darcs, _darcs/current (or _darcs/pristine) and _darcs/patches, and then creates an empty file, _darcs/inventory. However, it is strongly recommended that you use darcs initialize to do this, as this procedure may change in a future version of darcs.
In order to save disk space, you can use initialize with the --no-pristine-tree flag to create a repository with no pristine tree. Please see Section 3.6 for more information.
Usage: darcs get [OPTION]... <REPOSITORY> [<DIRECTORY>]
Options:
--repo-name DIRECTORY |
|
||
--partial |
|
||
--complete |
|
||
--to-match PATTERN |
|
||
--to-patch REGEXP |
|
||
--tag REGEXP |
|
||
--context FILENAME |
|
||
-v | --verbose |
|
|
-q | --quiet |
|
|
--standard-verbosity |
|
||
--set-default |
|
||
--no-set-default |
|
||
--set-scripts-executable |
|
||
--dont-set-scripts-executable |
|
||
--plain-pristine-tree |
|
||
--no-pristine-tree |
|
||
Get is used to get a local copy of a repository. I recommend using the --verbose flag to get, as this command can take a while, and with no feedback, that can be rather boring.
If the remote repo and the current directory are in the same filesystem and that filesystem supports hard links, get will create hard links for the patch files, which means that the additional storage space needed will be minimal. This is very good for your disk usage (and for the speed of running get), so if you want multiple copies of a repository, I strongly recommend first running darcs get to get yourself one copy, and then running darcs get on that copy to make any more you like. The only catch is that the first time you run darcs push or darcs pull from any of these second copies, by default they will access your first copy--which may not be what you want.
You may specify the name of the repository created by providing a second argument to get, which is a directory name.
If you want to get a specific version of a repository, you have a few options. You can either use the --tag, --to-patch or --to-match options, or you can use the --context=FILENAME option, which specifies a file containing a context generated with darcs changes --context. This allows you (for example) to include in your compiled program an option to output the precise version of the repository from which it was generated, and then perhaps ask users to include this information in bug reports.
Note that when specifying --to-patch or --to-match, you may get a version of your code that has never before been seen, if the patches have gotten themselves reordered. If you ever want to be able to precisely reproduce a given version, you need either to tag it or create a context file.
Only get the patches since the last checkpoint. This will save time, bandwidth and disk space, at the expense of losing the history before the checkpoint.
In order to save disk space, you can use get with the --no-pristine-tree flag to create a repository with no pristine tree. Please see Section 3.6 for more information.
Usage: darcs add [OPTION]... <FILE or DIRECTORY> ...
Options:
--boring |
|
||
--case-ok |
|
||
-r | --recursive |
|
|
--not-recursive |
|
||
--date-trick |
|
||
--no-date-trick |
|
||
-v | --verbose |
|
|
-q | --quiet |
|
|
--standard-verbosity |
|
||
--repodir DIRECTORY |
|
||
--dry-run |
|
||
Add needs to be called whenever you add a new file or directory to your project. Of course, it also needs to be called when you first create the project, to let darcs know which files should be kept track of.
Darcs will refuse to add a file or directory that differs from an existing one only in case. This is because the HFS+ file system used on under MacOS treats such files as being one and the same.
The --date-trick option allows you to enable an experimental trick to make add conflicts, in which two users each add a file or directory with the same name, less problematic. While this trick is completely safe, it is not clear to what extent it is beneficial.
Usage: darcs remove [OPTION]... <FILE or DIRECTORY> ...
Options:
-v | --verbose |
|
|
--standard-verbosity |
|
||
--repodir DIRECTORY |
|
||
Remove should be called when you want to remove a file from your project, but don’t actually want to delete the file. Otherwise just delete the file or directory, and darcs will notice that it has been removed. Be aware that the file WILL be deleted from any other copy of the repo to which you later apply the patch.
Usage: darcs mv [OPTION]... <FILE or DIRECTORY> ...
Options:
--case-ok |
|
||
-v | --verbose |
|
|
--standard-verbosity |
|
||
--repodir DIRECTORY |
|
||
Darcs mv needs to be called whenever you want to rename or move a file or directory. Unlike remove, mv actually performs the move itself in your working directory. This is why “mv” isn’t called “move”, since it is really almost equivalent to the unix command “mv”. I could add an equivalent command named “move” for those who like vowels.
Darcs mv will by default refuse to rename a file if there already exists a file having the same name apart from case. This is because doing so could create a repository that could not be used on file systems that are case insensitive (such as Apples HFS+). You can override this by with the flag --case-ok.
Usage: darcs replace [OPTION]... <OLD> <NEW> <FILE> ...
Options:
--token-chars "[CHARS]" |
|
||
--force |
|
||
--no-force |
|
||
-v | --verbose |
|
|
--standard-verbosity |
|
||
Replace allows you to change a specified token wherever it occurs in the specified files. Tokens here are defined by a regexp specifying the characters which are allowed. By default a token corresponds to a C identifier.
The default regexp is [A-Za-z_0-9]), and if one of your tokens contains a ‘-’ or ‘.’, you will then (by default) get the “filename” regexp, which is [A-Za-z_0-9\-\.].
If you prefer to choose a different set of characters to define your token (perhaps because you are programming in some other language), you may do so with the --token-chars option. You may prefer to define tokens in terms of delimiting characters instead of allowed characters using a flag such as --token-chars '[^ \n\t]', which would define a token as being white-space delimited.
If you do choose a non-default token definition, I recommend using _darcs/prefs/defaults to always specify the same --token-chars, since your replace patches will be better behaved (in terms of commutation and merges) if they have tokens defined in the same way.
When using darcs replace, the “new” token may not already appear in the file--if that is the case, the replace change would not be invertible. This limitation holds only on the already-recorded version of the file.
There is a potentially confusing difference, however, when a replace is used to make another replace possible:
% darcs replace newtoken aaack ./foo.c
% darcs replace oldtoken newtoken ./foo.c % darcs record |
% [manually edit foo.c replacing newtoken with aaack]
% darcs replace oldtoken newtoken ./foo.c |
Usage: darcs record [OPTION]... [FILE or DIRECTORY]...
Options:
-m | --patch-name PATCHNAME |
|
|
-A | --author EMAIL |
|
|
--logfile FILE |
|
||
--delete-logfile |
|
||
-v | --verbose |
|
|
--standard-verbosity |
|
||
--no-test |
|
||
--test |
|
||
--leave-test-directory |
|
||
--remove-test-directory |
|
||
--compress |
|
||
--dont-compress |
|
||
-a | --all |
|
|
--pipe |
|
||
--interactive |
|
||
--ask-deps |
|
||
--no-ask-deps |
|
||
--edit-long-comment |
|
||
--skip-long-comment |
|
||
--prompt-long-comment |
|
||
--ignore-times |
|
||
-l | --look-for-adds |
|
|
--dont-look-for-adds |
|
||
--repodir DIRECTORY |
|
||
Record is used to name a set of changes and record the patch to the repository. If you provide one or more files or directories as additional arguments to record, you will only be prompted to changes in those files or directories. Each patch is given a name, which typically would consist of a brief description of the changes. This name is later used to describe the patch. The name must fit on one line (i.e. cannot have any embedded newlines). If you have more to say, stick it in the log. The patch is also flagged with the author of the change, taken by default from the DARCS_EMAIL environment variable, and if that doesn’t exist, from the EMAIL environment variable. The date on which the patch was recorded is also included. Currently there is no provision for keeping track of when a patch enters a given repository. Finally, each changeset should have a full log (which may be empty). This log is for detailed notes which are too lengthy to fit in the name. If you answer that you do want to create a comment file, darcs will open an editor so that you can enter the comment in. The choice of editor proceeds as follows. If one of the $DARCS_EDITOR, $VISUAL or $EDITOR environment variables is defined, its value is used (with precedence proceeding in the order listed). If not, “vi”, “emacs”, “emacs -nw” and “nano” are tried in that order.
There is a problem that shows up with at least some versions of vi which keep them from working properly with darcs. An (ugly) solution to this is to tell vi to use the tty as stdin and stdout:
export DARCS_EDITOR="vi </dev/tty >/dev/tty"
|
If you wish, you may specify the patch name and log using the --logfile flag. If you do so, the first line of the specified file will be taken to be the patch name, and the remainder will be the “long comment”. This feature can be especially handy if you have a test that fails several times on the record (thus aborting the record), so you don’t have to type in the long comment multiple times. The file’s contents will override the --patch-name option.
Each patch may depend on any number of previous patches. If you choose to make your patch depend on a previous patch, that patch is required to be applied before your patch can be applied to a repo. This can be used, for example, if a piece of code requires a function to be defined, which was defined in an earlier patch.
If you want to manually define any dependencies for your patch, you can use the --ask-deps flag, and darcs will ask you for the patch’s dependencies.
If you configure darcs to run a test suite, darcs will run this test on the recorded repo to make sure it is valid. Darcs first creates a pristine copy of the source tree (in a temporary directory), then it runs the test, using its return value to decide if the record is valid. If it is not valid, the record will be aborted. This is a handy way to avoid making stupid mistakes like forgetting to ‘darcs add’ a new file. It also can be tediously slow, so there is an option (--no-test) to skip the test.
If you run record with the --pipe option, you will be prompted for the patch name, patch date and the long comment. The long comment will extend until the end of file of stdin is reached (ctrl-D on unixy systems). This interface is intended for scripting darcs, in particular for writing repository conversion scripts. The prompts are intended mostly as useful guide (since scripts won’t need them), to help you understand the format in which to provide the input.
By default, record works interactively. Probably you only thing you need to know about using this is that you can press ? at the prompt to be shown a list of the rest the options and what they do. The rest should be clear from there. Here’s a ’screenshot’ to demonstrate:
hunk ./hello.pl +2
+#!/usr/bin/perl +print "Hello World!\n"; Shall I record this patch? (2/2) [ynWsfqadjk], or ? for help: ? How to use record... y: record this patch n: don't record it w: wait and decide later, defaulting to no s: don't record the rest of the changes to this file f: record the rest of the changes to this file d: record selected patches a: record all the remaining patches q: cancel record j: skip to next patch k: back up to previous patch h or ?: show this help <Space>: accept the current default (which is capitalized) |
Usage: darcs pull [OPTION]... [REPOSITORY]
Options:
--matches PATTERN |
|
||
-p | --patches REGEXP |
|
|
-t | --tags REGEXP |
|
|
-a | --all |
|
|
--interactive |
|
||
--external-merge COMMAND |
|
||
--compress |
|
||
--dont-compress |
|
||
--test |
|
||
--no-test |
|
||
--dry-run |
|
||
-s | --summary |
|
|
--no-summary |
|
||
-v | --verbose |
|
|
-q | --quiet |
|
|
--standard-verbosity |
|
||
--ignore-times |
|
||
--no-deps |
|
||
--set-default |
|
||
--no-set-default |
|
||
--repodir DIRECTORY |
|
||
--set-scripts-executable |
|
||
--dont-set-scripts-executable |
|
||
Pull is used to bring changes made in another repo into the current repo (that is, either the one in the current directory, or the one specified with the -repodir option). Pull allows you to bring over all or some of the patches that are in that repo but not in the current one. Pull accepts an argument, which is the URL from which to pull, and when called without an argument, pull will use the repository from which you have most recently either pushed or pulled.
You can use an external interactive merge tool to resolve conflicts with the flag --external-merge. For more details see subsection 6.1.
The --patches, --matches, and --tags options can be used to select which patches to pull, as described in subsection 6.1. darcs will silently pull along any other patches upon which the selected patches depend. So --patches bugfix means “pull all the patches with ‘bugfix’ in their name, along with any patches they require.” If you really only want the patches with ‘bugfix’ in their name, you should use the --no-deps option, which makes darcs pull in only the selected patches which have no dependencies (apart from other selected patches).
If you specify the --test option, pull will run the test (if a test exists) on a scratch copy of the repo contents prior to actually performing the pull. If the test fails, the pull will be aborted.
Adding the --verbose option causes another section to appear in the output which also displays a summary of patches that you have and the remote repo lacks. Thus, the following syntax can be used to show you all the patch differences between two repos:
darcs pull --dry-run --verbose
|
Usage: darcs push [OPTION]... [REPOSITORY]
Options:
-v | --verbose |
|
|
-q | --quiet |
|
|
--standard-verbosity |
|
||
--matches PATTERN |
|
||
-p | --patches REGEXP |
|
|
-t | --tags REGEXP |
|
|
-a | --all |
|
|
--interactive |
|
||
--apply-as USERNAME |
|
||
--apply-as-myself |
|
||
--dry-run |
|
||
-s | --summary |
|
|
--no-summary |
|
||
--repodir DIRECTORY |
|
||
--set-default |
|
||
--no-set-default |
|
||
Push is the opposite of pull. Push allows you to move changes from the current repository into another repository.
For obvious reasons, you can only push to repositories to which you have write access. In addition, you can only push to repos that you access either on the local file system or with ssh. In order to apply with ssh, darcs must also be installed on the remote computer. The command invoked to run ssh may be configured by the DARCS_SSH environment variable (see subsection 4.2). The command invoked via ssh is always darcs, i.e., the darcs executable must be in the default path on the remote machine.
Push works by creating a patch bundle, and then running darcs apply in the target repository using that patch bundle. This means that the default options for apply in the target repository (such as, for example, --test) will affect the behavior of push. This also means that push is somewhat less efficient than pull.
When you receive an error message such as
bash: darcs: command not found
|
ssh login@remote.machine darcs
|
ssh login@remote.machine 'echo $PATH'
|
If you give the --apply-as flag, darcs will use sudo to apply the changes as a different user. This can be useful if you want to set up a system where several users can modify the same repository, but you don’t want to allow them full write access. This isn’t secure against skilled malicious attackers, but at least can protect your repository from clumsy, inept or lazy users.
The --patches, --matches, and --tags options can be used to select which patches to push, as described in subsection 6.1. darcs will silently push along any other patches upon which the selected patches depend.
When there are conflicts, the behavior of push is determined by the default flags to apply in the target repository. Most commonly, for pushed-to repositories, you’d like to have --dont-allow-conflicts as a default option to apply (by default, it is alreay the default...). If this is the case, when there are conflicts on push, darcs will fail with an error message. You can then resolve by pulling the conflicting patch, recording a resolution and then pushing the resolution together with the conflicting patch.
Darcs does not have an explict way to tell you which patch conflicted, only the file name. You may want to pull all the patches from the remote repo just to be sure. If you don’t want to do this in your working directory, you can create another darcs working directory for this purpose.
If you want, you could set the target repo to use --allow-conflicts. In this case conflicting patches will be applied, but the conflicts will not be marked in the working directory.
If, on the other hand, you have --mark-conflicts specified as a default flag for apply in the target repository, when there is a conflict, it will be marked in the working directory of the target repository. In this case, you should resolve the conflict in the target repository itself.
Usage: darcs send [OPTION]... [REPOSITORY]
Options:
-v | --verbose |
|
|
-q | --quiet |
|
|
--standard-verbosity |
|
||
--matches PATTERN |
|
||
-p | --patches REGEXP |
|
|
-t | --tags REGEXP |
|
|
-a | --all |
|
|
--interactive |
|
||
--from EMAIL |
|
||
-A | --author EMAIL |
|
|
--to EMAIL |
|
||
--cc EMAIL |
|
||
-o | --output FILE |
|
|
--sign |
|
||
--sign-as KEYID |
|
||
--sign-ssl IDFILE |
|
||
--dont-sign |
|
||
-u | --unified |
|
|
--dry-run |
|
||
-s | --summary |
|
|
--no-summary |
|
||
--context FILENAME |
|
||
--edit-description |
|
||
--set-default |
|
||
--no-set-default |
|
||
--repodir DIRECTORY |
|
||
Send is used to prepare a bundle of patches that can be applied to a target repository. Send accepts the URL of the repository as an argument. When called without an argument, send will use the most recent repository that was either pushed to, pulled from or sent to. By default, the patch bundle is sent by email, although you may save it to a file.
If you want to create a patches having context, you can use the --unified option, which create output vaguely reminiscent of diff -u. This format is still darcs-specific and should not be expected to apply cleanly by patch.
The --output and --to flags determine what darcs does with the patch bundle after creating it. If you provide an --output argument, the patch bundle is saved to that file. If you give one or more --to arguments, the bundle of patches is emailed to those addresses.
If you don’t provide either a --output or a --to flag, darcs will look at the contents of the _darcs/prefs/email file in the target repository (if it exists), and send the patch by email to that address. In this case, you may use the --cc option to specify additional recipients without overriding the default repository email address.
If there is no email address associated with the repository, darcs will prompt you for an email address.
The --patches, --matches, and --tags options can be used to select which patches to send, as described in subsection 6.1. darcs will silently send along any other patches upon which the selected patches depend.
If you want to include a description or explanation along with the bundle of patches, you need to specify the --edit-description flag, which will cause darcs to open up an editor with which you can compose an email to go along with your patches.
Usage: darcs apply [OPTION]... <PATCHFILE>
Options:
--verify PUBRING |
|
||
--verify-ssl KEYS |
|
||
--no-verify |
|
||
--reply FROM |
|
||
--cc EMAIL |
|
||
-v | --verbose |
|
|
--standard-verbosity |
|
||
--ignore-times |
|
||
--compress |
|
||
--dont-compress |
|
||
-a | --all |
|
|
--interactive |
|
||
--mark-conflicts |
|
||
--allow-conflicts |
|
||
--external-merge COMMAND |
|
||
--no-resolve-conflicts |
|
||
--dont-allow-conflicts |
|
||
--no-test |
|
||
--test |
|
||
--happy-forwarding |
|
||
--leave-test-directory |
|
||
--remove-test-directory |
|
||
--repodir DIRECTORY |
|
||
--set-scripts-executable |
|
||
--dont-set-scripts-executable |
|
||
Apply is used to apply a bundle of patches to this repository. Such a bundle may be created using send.
Darcs apply accepts a single argument, which is the name of the patch file to be applied. If you omit this argument, the patch is read from standard input.3 This allows you to use apply with a pipe from your email program, for example.
If you specify the --verify PUBRING option, darcs will check that the patch was gpg-signed by a key which is in PUBRING, and will refuse to apply the patch otherwise.
If you give the --reply FROM option to darcs apply, it will send the results of the application to the sender of the patch. This only works if the patch is in the form of an email with its headers intact, so that darcs can actually know the origin of the patch. The reply email will indicate whether or not the patch was successfully applied. The FROM flag is the email address that will be used as the “from” address when replying. If the darcs apply is being done automatically, it is important that this address not be the same as the address at which the patch was received in order to avoid automatic email loops.
If you want to also send the apply email to another address (for example, to create something like a “commits” mailing list), you can use the --cc option to specify additional recipients. Note that the --cc option requires the --reply option, which provides the “From” address.
The --reply feature of apply is intended primarily for two uses. When used by itself, it is handy for when you want to apply patches sent to you by other developers so that they will know when their patch has been applied. For example, in my .muttrc (the config file for my mailer) I have:
macro pager A "<pipe-entry>darcs apply --verbose \
--reply droundy@abridgegame.org --repodir ~/darcs |
When used in combination with the --verify option, the --reply option allows for a nice pushable repository. When these two options are used together, any patches that don’t pass the verify will be forwarded to the FROM address of the --reply option. This allows you to set up a repository so that anyone who is authorized can push to it and have it automatically applied, but if a stranger pushes to it, the patch will be forwarded to you. Please (for your own sake!) be certain that the --reply FROM address is different from the one used to send patches to a pushable repository, since otherwise an unsigned patch will be forwarded to the repository in an infinite loop.
If you use ‘darcs apply --verify PUBRING --reply’ to create a pushable repo by applying patches automatically as they are received by email, you will also want to use the --dont-allow-conflicts option.
The --dont-allow-conflicts flag causes apply to fail when applying a patch would cause conflicts. This flag is recommended on repositories which will be pushed to or sent to.
--allow-conflicts will allow conflicts, but will keep the local and recorded versions in sync on the repo. This means the conflict will exist in both locations until it is resolved.
--mark-conflicts will add conflict markers to illustrate the the conflict.
You can use an external interactive merge tool to resolve conflicts with the flag --external-merge. For more details see subsection 6.1.
If you provide the --interactive or --gui flag, darcs will ask you for each change in the patch bundle whether or not you wish to apply that change. The opposite is the --all flag, which can be used to override an interactive or gui which might be set in your “defaults” file.
If you specify the --test option, apply will run the test (if a test exists) prior to applying the patch. If the test fails, the patch is not applied. In this case, if the --reply option was used, the results of the test are send in the reply email. You can also specify the --no-test option, which will override the --test option, and prevent the test from being run. This is helpful when setting up a pushable repository, to keep users from running code.
Usage: darcs whatsnew [OPTION]... [FILE or DIRECTORY]...
Options:
-v | --verbose |
|
|
--standard-verbosity |
|
||
-s | --summary |
|
|
--no-summary |
|
||
-u | --unified |
|
|
--ignore-times |
|
||
-l | --look-for-adds |
|
|
--dont-look-for-adds |
|
||
--boring |
|
||
--repodir DIRECTORY |
|
||
Display unrecorded changes in the working directory. whatsnew gives you a view of what changes you’ve made in your working directory that haven’t yet been recorded. The changes are displayed in darcs patch format. Darcs whatsnew will return a non-zero value if there are no changes, which can be useful if you just want to see in a script if anything has been modified. If you want to see some context around your changes, you can use the -u option, to get output similar to the unidiff format.
If you give one or more file or directory names as an argument to whatsnew, darcs whatsnew will output only changes to those files or to files in those directories.
Usage: darcs changes [OPTION]... [FILE or DIRECTORY]...
Options:
--to-match PATTERN |
|
||
--to-patch REGEXP |
|
||
--to-tag REGEXP |
|
||
--from-match PATTERN |
|
||
--from-patch REGEXP |
|
||
--from-tag REGEXP |
|
||
--match PATTERN |
|
||
-p | --patch REGEXP |
|
|
--last NUMBER |
|
||
--matches PATTERN |
|
||
-p | --patches REGEXP |
|
|
-t | --tags REGEXP |
|
|
--context |
|
||
--xml-output |
|
||
--human-readable |
|
||
-s | --summary |
|
|
--no-summary |
|
||
-v | --verbose |
|
|
-q | --quiet |
|
|
--standard-verbosity |
|
||
--reverse |
|
||
--repo URL |
|
||
Changes gives a human-readable list of changes between versions suitable for use as a changelog.
When given one or more files or directories as an argument, changes lists only those patches which affect those files or the contents of those directories, or of course the directories themselves. This includes changes that happened to files before they were moved or renamed.
If changes is given a --from-patch, --from-match, or --from-tag option, it outputs only those changes since that tag or patch.
Without any options to limit the scope of the changes, history will displayed going back as far as possible.
When given the --context flag, darcs changes outputs sufficient information which will allow the current state of the repository to be recreated at a later date. This information should generally be piped to a file, and then can be used later in conjunction with darcs get --context to recreate the current version. Note that while the --context flag may be used in conjunction with --xml-output or --human-readable, in neither case will darcs get be able to read the output. On the other hand, sufficient information will be output for a knowledgeable human to recreate the current state of the repository.
Usage: darcs tag [OPTION]...
Options:
-m | --patch-name PATCHNAME |
|
|
-A | --author EMAIL |
|
|
--checkpoint |
|
||
--compress |
|
||
--dont-compress |
|
||
--pipe |
|
||
--interactive |
|
||
-v | --verbose |
|
|
--standard-verbosity |
|
||
Tag is used to name a version of the tree. Tag differs from record in that it doesn’t record any new changes, and it always depends on all patches residing in the repository when it is tagged. This means that one can later reproduce this version of the repository by calling, for example:
% darcs get --tag "darcs 3.14" REPOLOCATION
|
Each tagged version has a version name. The version is also flagged with the person who tagged it (taken by default from the ‘DARCS_EMAIL’ or ‘EMAIL’ environment variable). The date is also included in the version information.
A tagged version automatically depends on all patches in the repo. This allows you to later reproduce precisely that version. The tag does this by depending on all patches in the repo, except for those which are depended upon by other tags already in the repo. In the common case of a sequential series of tags, this means that the tag depends on all patches since the last tag, plus that tag itself.
The --checkpoint option allows the tag be used later with the --partial flag to get or check.
A partial repository only contains patches from after the checkpoint. A partial repository works just like a normal repository, but any command that needs to look at the contents of a missing patch will complain and abort.
If you run tag with the --pipe option, you will be prompted for the tag name and date. This interface is intended for scripting darcs, in particular for writing repository conversion scripts. The prompts are intended mostly as useful guide (since scripts won’t need them), to help you understand the format in which to provide the input. Here’s an example of what the --pipe prompts looks like:
What is the date? Mon Nov 15 13:38:01 EST 2004
Who is the author? David Roundy What is the version name? 3.0 Finished tagging patch 'TAG 3.0' |
Using tag creates an entry in the repo history just like record. It will show up with darcs changes appearing in the format:
tagged My Tag Name
|
Because the word ’tagged’ is always prepended to the tag name, you can search for tag names by simply passing the output of darcs changes through grep:
darcs changes | grep tagged
|
The above example would display all the tag names in use in the repo.
Usage: darcs setpref [OPTION]... <PREF> <VALUE>
Options:
Usage example:
% darcs setpref test "echo I am not really testing anything."
|
Setpref allows you to set a preferences value in a way that will propagate to other repositories.
Valid preferences are: test predist boringfile binariesfile. If you just want to set the pref value in your repository only, you can just edit “_darcs/prefs/prefs”. Changes you make in that file will be preserved.
The “_darcs/prefs/prefs” holds the only preferences information that can propagate between repositories by pushes and pulls, and the only way this happens is when the setprefs command is used. Note that although prefs settings are included in patches, they are not fully version controlled. In particular, depending on the order in which a series of merges is perform, you may end up with a different final prefs configuration. In practice I don’t expect this to be a problem, as the prefs usually won’t be changed very often.
The following values are valid preferences options which can be configured using setpref:
Usage: darcs check [OPTION]...
Options:
--complete |
|
||
--partial |
|
||
-v | --verbose |
|
|
-q | --quiet |
|
|
--standard-verbosity |
|
||
--no-test |
|
||
--test |
|
||
--leave-test-directory |
|
||
--remove-test-directory |
|
||
--repodir DIRECTORY |
|
||
Check the repository for consistency. Check verifies that the patches stored in the repository, when successively applied to an empty tree, properly recreate the stored pristine tree.
If you have a checkpoint of the repository (as is the case if you got the repo originally using darcs get --partial), by default darcs check will only verify the contents since the most recent checkpoint. You can change this behavior using the --complete flag.
If you like, you can configure your repository to be able to run a test suite of some sort. You can do this by using “setpref” to set the “test” value to be a command to run. e.g.
% darcs setpref test "sh configure && make && make test"
|
Normally darcs deletes the directory in which the test was run afterwards. Sometimes (especially when the test fails) you’d prefer to be able to be able to examine the test directory after the test is run. You can do this by specifying the --leave-test-directory flag. Alas, there is no way to make darcs leave the test directory only if the test fails. The opposite of --leave-test-directory is --remove-test-directory, which could come in handy if you choose to make --leave-test-directory the default (see section 4.1).
If you just want to check the consistency of your repository without running the test, you can call darcs check with the --no-test option.
Usage: darcs optimize [OPTION]...
Options:
--checkpoint |
|
||
--compress |
|
||
--dont-compress |
|
||
--uncompress |
|
||
-t | --tag-name TAGNAME |
|
|
-v | --verbose |
|
|
--standard-verbosity |
|
||
--sibling URL |
|
||
--relink |
|
||
Optimize can help to improve the performance of your repository in a number of cases.
Optimize always writes out a fresh copy of the inventory that minimizes the amount of inventory that need be downloaded when people pull from the repo.
Specifically, it breaks up the inventory on the most recent tag. This speeds up most commands when run remotely, both because a smaller file needs to be transfered (only the most recent inventory). It also because it gives a guarantee that all the patches prior to a given tag are included in that tag, so less commutation and history traversal is needed. This latter issue can become very important in large repositories.
If you use the --checkpoint option optimize creates a checkpoint patch for a tag. You can specify the tag with the --tag option, or just let darcs choose the most recent tag. Note that optimize --checkpoint will fail when used on a “partial” repository. Also, the tag that is to be checkpointed must not be preceeded by any patches that are not included in that tag. If that is the case, no checkpointing is done.
The created checkpoint is used by the --partial flag to get and check. This allows for users to retrieve a working repository with limited history with a savings of disk space and bandwidth.
Some compression options are available, and are indepedent of the --checkpoint option.
By default the patches in the repository are compressed. These use less disk space, which translates into less bandwidth if repository is accessed remotely. Note that patches will always have the ”.gz” extension whether they are compressed or note.
You may want to uncompress the patches when you’ve got enough disk space but are running out of physical memory.
If you give the --compress option, optimize will compress all the patches in the repository. Similarly, if you give the --uncompress, optimize will decompress all the patches in the repository. --dont-compress means ”don’t compress, but don’t uncompress either”. It would be useful if one of the compression options was provided as a default and you wanted to override it.
The --relink option causes Darcs to relink files from a sibling. See Section 3.6.
Usage: darcs amend-record [OPTION]... [FILE or DIRECTORY]...
Options:
--match PATTERN |
|
||
-p | --patch REGEXP |
|
|
-v | --verbose |
|
|
--standard-verbosity |
|
||
--no-test |
|
||
--test |
|
||
--leave-test-directory |
|
||
--remove-test-directory |
|
||
--compress |
|
||
--dont-compress |
|
||
-a | --all |
|
|
--interactive |
|
||
--ignore-times |
|
||
-l | --look-for-adds |
|
|
--dont-look-for-adds |
|
||
--repodir DIRECTORY |
|
||
Amend-record is used to replace a patch with a newer version with additional changes.
If you provide one or more files or directories as additional arguments to amend-record, you will only be prompted to changes in those files or directories.
The old version of the patch is lost and the new patch will include both the old and the new changes. This is mostly the same as unrecording the old patch, fixing the changes and recording a new patch with the same name and description.
amend-record will modify the date of the recorded patch. WARNING: You should ONLY use amend-record on patches which only exist in a single repository!
If you configure darcs to run a test suite, darcs will run this test on the amended repo to make sure it is valid. Darcs first creates a pristine copy of the source tree (in a temporary directory), then it runs the test, using its return value to decide if the amended change is valid.
Usage: darcs rollback [OPTION]...
Options:
--match PATTERN |
|
||
-p | --patch REGEXP |
|
|
--compress |
|
||
--dont-compress |
|
||
-v | --verbose |
|
|
--standard-verbosity |
|
||
--repodir DIRECTORY |
|
||
Rollback is used to undo the effects of a single patch without actually deleting that patch. Instead, it applies the inverse patch as a new patch. Unlike unpull and unrecord (which accomplish a similar goal) rollback is perfectly safe, since it leaves in the repository a record of the patch it is removing. If you decide you didn’t want to roll back a patch after all, you probably should use unrecord to undo the rollback, since like rollback, unrecord doesn’t affect the working directory.
Usage: darcs unrecord [OPTION]...
Options:
--match PATTERN |
|
||
-p | --patch REGEXP |
|
|
-t | --tag REGEXP |
|
|
-v | --verbose |
|
|
--standard-verbosity |
|
||
--compress |
|
||
--dont-compress |
|
||
--repodir DIRECTORY |
|
||
Unrecord is used to undo a single recorded patch. It will prompt you for which patch to unrecord, and then will undo that patch. Unrecord doesn’t affect your working copy of the tree at all.
Unrecord can be thought of as undo-record. If a record is followed by an unrecord, everything looks like before the record; all the previously unrecorded changes are back, and can be recorded again in a new patch. The unrecorded patch however is actually removed from your repository, so there is no way to record it again to get it back.4.
If you want to remove the change from the working copy too (where they otherwise will show up as unrecorded changes again), you’ll also need to darcs revert. To do unrecord and revert in one go, you can use darcs unpull.
If you don’t revert after unrecording, then the changes made by the unrecorded patches are left in your working tree. If these patches are actually from another repository, interaction (either pushes or pulls) with that repository may be massively slowed down, as darcs tries to cope with the fact that you appear to have made a large number of changes that conflict with those present on the other repository. So if you really want to undo the result of a pull operation, use unpull! Unrecord is primarily intended for when you record a patch, realize it needs just one more change, but would rather not have a separate patch for just that one change.
Usage: darcs unpull [OPTION]...
Options:
--match PATTERN |
|
||
-p | --patch REGEXP |
|
|
-t | --tag REGEXP |
|
|
-v | --verbose |
|
|
--standard-verbosity |
|
||
--compress |
|
||
--dont-compress |
|
||
--ignore-times |
|
||
--repodir DIRECTORY |
|
||
Unpull is used to undo a single patch that has been pulled from another repository. It will prompt you for which patch to unpull, and then will undo that patch. Beware that unpull undoes the patch both from the repo records AND from the current working directory, and does NOT check that the patch originated with a pull. In other words, you could lose precious code by unpulling!
Like unrecord, unpull does not just apply an inverse patch to the repository, it actually deletes the patch from the repository. This makes unpull a particularly dangerous command, as it not only deletes the patch from the repo, but also removes the changes from the working directory. It is equivalent to an unrecord followed by a revert, except that revert can be unreverted.
Contrary to what its name suggests, there is nothing in unpull that requires that the “unpulled” patch originate from a different repository. The name was chosen simply to suggest a situation in which it is “safe” to used unpull. If the patch was originally from another repo, then unpulling is safe, because you can always pull the patch again if you decide you want it after all. If you unpull a locally recorded patch, all record of that change is lost, which is what makes this a “dangerous” command, and thus deserving of a obscure name which is more suggestive of when it is safe to use than precisely what it does.
Each of these options is used to select a single patch to unpull. In the case of --tag, what you are unpulling is the tag itself, not any other patches.
Usage: darcs revert [OPTION]... [FILE or DIRECTORY]...
Options:
-v | --verbose |
|
|
--standard-verbosity |
|
||
--ignore-times |
|
||
-a | --all |
|
|
--interactive |
|
||
--repodir DIRECTORY |
|
||
Revert is used to undo changes made to the local tree which have not yet been recorded. You will be prompted for which changes you wish to undo. The actions of a revert may be reversed using the unrevert command (see subsection 6.7.6). However, if you’ve made changes since the revert your mileage may vary, so please be careful.
You can give revert optional arguments indicating files or directories. If you do so it will only prompt you to revert changes in those files or in files in those directories.
Usage: darcs unrevert [OPTION]...
Options:
-v | --verbose |
|
|
--standard-verbosity |
|
||
--ignore-times |
|
||
--repodir DIRECTORY |
|
||
Unrevert is used to undo the results of a revert command.
While this is only guaranteed to work properly if you haven’t made any changes since the revert was performed, it makes a best effort to merge the unreversion with any changes you have since made. In fact, unrevert should even work if you’ve recorded changes since reverting.
Usage: darcs diff [OPTION]... [FILE or DIRECTORY]...
Options:
--to-match PATTERN |
|
||
--to-patch REGEXP |
|
||
--to-tag REGEXP |
|
||
--from-match PATTERN |
|
||
--from-patch REGEXP |
|
||
--from-tag REGEXP |
|
||
--match PATTERN |
|
||
-p | --patch REGEXP |
|
|
--last NUMBER |
|
||
--diff-opts OPTIONS |
|
||
-u | --unified |
|
|
--repodir DIRECTORY |
|
||
Diff can be used to create a diff between two versions which are in your repository. Specifying just -from-patch will get you a diff against the version in your working directory. If you give diff no version arguments, it gives you the same information as whatsnew except that the patch is formatted as the output of a diff command
Diff calls an external “diff” command to do the actual work, and passes any unrecognized flags to this diff command. Thus you can call
% darcs diff -t 0.9.8 -t 0.9.10 -- -u
|
% darcs diff --diff-opts -u -t 0.9.8 -t 0.9.10
|
% diff diff-opts -udp
|
If you want to view only the differences to one or more files, you can do so with a command such as
% darcs diff foo.c bar.c baz/
|
FIXME: I should allow the user to specify the external diff command. Currently it is hardwired to ”diff”.
Usage: darcs annotate [OPTION]... [FILE or DIRECTORY]...
Options:
-v | --verbose |
|
|
--standard-verbosity |
|
||
-s | --summary |
|
|
--no-summary |
|
||
-u | --unified |
|
|
--human-readable |
|
||
--xml-output |
|
||
--match PATTERN |
|
||
-p | --patch REGEXP |
|
|
-t | --tag REGEXP |
|
|
--creator-hash HASH |
|
||
--repodir DIRECTORY |
|
||
Display which patch last modified something, or display patch contents Annotate displays which patches created or last modified a directory file or line. It can also display the contents of a particular patch in darcs format.
When called with just a patch name, annotate outputs the patch in darcs format, which is the same as --human-readable.
--xml-output is the alternative to --human-readable.
--summary can be used with either the --xml-output or the --human-readable options to alter the results. It is documented fully in the ’common options’ portion of the manual.
Giving the --unified flag implies --human-readable, and causes the output to remain in a darcs-specific format that is similar to that produced by diff --unified.
If a directory name is given, annotate will output details of the last modifying patch for each file in the directory and the directory itself. The details look like this:
# Created by [bounce handling patch
# mark**20040526202216] as ./test/m7/bounce_handling.pl bounce_handling.pl |
If a patch name and a directory are given, these details are given for the time after that patch was applied will be output. If a directory and a tag name are given, the details of the patches involved in the specified tagged version will be output.
If a file name is given, the last modifying patch details of that file will be output, along with markup indicating patch details when each line was last (and perhaps next) modified.
The --creator-hash option should only be used in combination with a file or directory to be annotated. In this case, the name of that file or directory is interpereted to be its name at the time it was created, and the hash given along with --creator-hash indicates the patch that created the file or directory. This allows you to (relatively) easily examine a file even if it has been renamed multiple times.
Usage: darcs resolve [OPTION]...
Options:
-v | --verbose |
|
|
--standard-verbosity |
|
||
--ignore-times |
|
||
--repodir DIRECTORY |
|
||
Resolve is used to mark and resolve any conflicts that may exist in a repository. Note that this trashes any unrecorded changes in the working directory.
Usage: darcs dist [OPTION]...
Options:
-d | --dist-name DISTNAME |
|
|
-v | --verbose |
|
|
--standard-verbosity |
|
||
Create a distribution tarball.
Dist is a handy tool for implementing a “make dist” target in your makefile. It creates a tarball of the recorded edition of your tree. Basically, you will typically use it in a makefile rule such as
dist:
darcs dist --dist-name darcs-`./darcs --version` |
% darcs setpref predist "autoconf && automake"
|
Usage: darcs trackdown [OPTION]... [INITIALIZATION] [COMMAND]
Options:
-v | --verbose |
|
|
--standard-verbosity |
|
||
Trackdown tries to find the most recent version in the repository which passes a test. Given no arguments, it uses the default repository test. Given one argument, it treats it as a test command. Given two arguments, the first is an initialization command with is run only once, and the second is the test command.
Trackdown is helpful for locating when something was broken. It creates a temporary directory with the latest repo content in it and cd to it. First, and only once, it runs the initialization command if any, for example
'autoconf; ./configure >/dev/null'
|
'make && cd tests && sh /tmp/test.sh'
|
FIXME: It is still rather primitive. Currently it just goes back over the history in reverse order trying each version. I’d like for it to explore different patch combinations, to try to find the minimum number of patches that you would need to unpull in order to make the test succeed.
FIXME: I also would like to add an interface by which you can tell it which patches it should consider not including. Without such a feature, the following command:
% darcs trackdown 'make && false'
|
If you want to find the last version of darcs that had a FIXME note in the file Record.lhs, you could run
% darcs trackdown 'grep FIXME Record.lhs'
|
To find the latest version that compiles, you can run
% darcs trackdown 'autoconf' './configure && make'
|
Trackdown can also be used to see how other features of the code changed with time. For example
% darcs trackdown 'autoconf; ./configure' \
"make darcs &> /dev/null && cd ~/darcs && time darcs check && false" |
Usage: darcs repair [OPTION]...
Options:
-v | --verbose |
|
|
-q | --quiet |
|
|
--standard-verbosity |
|
||
Repair attempts to fix corruption that may have entered your repository.
Repair currently will only repair damage to the pristine tree. Fortunately this is just the sort of corruption that is most likely to happen.
I think a little background on the author is in order. I am a physicist, and think like a physicist. The proofs and theorems given here are what I would call “physicist” proofs and theorems, which is to say that while the proofs may not be rigorous, they are practical, and the theorems are intended to give physical insight. It would be great to have a mathematician work on this, but I am not a mathematician, and don’t care for math.
From the beginning of this theory, which originated as the result of a series of email discussions with Tom Lord, I have looked at patches as being analogous to the operators of quantum mechanics. I include in this appendix footnotes explaining the theory of patches in terms of the theory of quantum mechanics. I know that for most people this won’t help at all, but many of my friends (and as I write this all three of darcs’ users) are physicists, and this will be helpful to them. To non-physicists, perhaps it will provide some insight into how at least this physicist thinks.
A patch describes a change to the tree. It could be either a primitive patch (such as a file add/remove, a directory rename, or a hunk replacement within a file), or a compositive patch describing many such changes. Every patch type must satisfy the conditions described in this appendix. The theory of patches is independent of the data which the patches manipulate, which is what makes it both powerful and useful, as it provides a framework upon which one can build a revision control system in a sane manner.
Although in a sense, the defining property of any patch is that it can be applied to a certain tree, and thus make a certain change, this change does not wholly define the patch. A patch is defined by a representation, together with a set of rules for how it behaves (which it has in common with its patch type). The representation of a patch defines what change that particular patch makes, and must be defined in the context of a specific tree. The theory of patches is a theory of the many ways one can change the representation of a patch to place it in the context of a different tree. The patch itself is not changed, since it describes a single change, which must be the same regardless of its representation1.
So how does one define a tree, or the context of a patch? The simplest way to define a tree is as the result of a series of patches applied to the empty tree2. Thus, the context of a patch consists of the set of patches that precede it.
Hunks are an example of a complex filepatch. A hunk is a set of lines of a text file to be replaced by a different set of lines. Either of these sets may be empty, which would mean a deletion or insertion of lines.
Although most filepatches will be hunks, darcs is clever enough to support other types of changes as well. A “token replace” patch replaces all instances of a given token with some other version. A token, here, is defined by a regular expression, which must be of the simple [a-z...] type, indicating which characters are allowed in a token, with all other characters acting as delimiters. For example, a C identifier would be a token with the flag [A-Za-z_0-9].
What makes the token replace patch special is the fact that a token replace can be merged with almost any ordinary hunk, giving exactly what you would want. For example, you might want to change the patch type TokReplace to TokenReplace (if you decided that saving two characters of space was stupid). If you did this using hunks, it would modify every line where TokReplace occurred, and quite likely provoke a conflict with another patch modifying those lines. On the other hand, if you did is using a token replace patch, the only change that it could conflict with would be if someone else had used the token “TokenReplace” in their patch rather than TokReplace--and that actually would be a real conflict!
The simplest relationship between two patches is that of “sequential” patches, which means that the context of the second patch (the one on the left) consists of the first patch (on the right) plus the context of the first patch. The composition of two patches (which is also a patch) refers to the patch which is formed by first applying one and then the other. The composition of two patches, P1 and P2 is represented as P2P1, where P1 is to be applied first, then P23
There is one other very useful relationship that two patches can have, which is to be parallel patches, which means that the two patches have an identical context (i.e. their representation applies to identical trees). This is represented by P1 || P2. Of course, two patches may also have no simple relationship to one another. In that case, if you want to do something with them, you’ll have to manipulate them with respect to other patches until they are either in sequence or in parallel.
The most fundamental and simple property of patches is that they must be invertible. The inverse of a patch is described by: P-1. In the darcs implementation, the inverse is required to be computable from knowledge of the patch only, without knowledge of its context, but that (although convenient) is not required by the theory of patches.
Definition 1 The inverse of patch P is P-1, which is the “simplest” patch for
which the composition makes no changes to the tree.
Using this definition, it is trivial to prove the following theorem relating to the inverse of a composition of two patches.
Theorem 1 The inverse of the composition of two patches is
Moreover, it is possible to show that the right inverse of a patch is equal to its left inverse. In this respect, patches continue to be analogous to square matrices, and indeed the proofs relating to these properties of the inverse are entirely analogous to the proofs in the case of matrix multiplication. The compositions proofs can also readily be extended to the composition of more than two patches.
Composite patches are made up of a series of patches intended to be applied sequentially. They are represented by a list of patches, with the first patch in the list being applied first.
The first way (of only two) to change the context of a patch is by commutation, which is the process of changing the order of two sequential patches.
Definition 2 The commutation of patches P1 and P2 is represented by
Here P1' is intended to describe the same change as P1, with the only difference being that P1' is applied after P2' rather than before P2.
The above definition is obviously rather vague, the reason being that what is the
“same change” has not been defined, and we simply assume (and hope) that the
code’s view of what is the “same change” will match those of its human users. The
‘’ operator should be read as something like the == operator in C, indicating
that the right hand side performs identical changes to the left hand side,
but the two patches are in reversed order. When read in this manner, it
is clear that commutation must be a reversible process, and indeed this
means that commutation can fail, and must fail in certain cases. For example,
the creation and deletion of the same file cannot be commuted. When two
patches fail to commute, it is said that the second patch depends on the first,
meaning that it must have the first patch in its context (remembering that the
context of a patch is a set of patches, which is how we represent a tree).
4
Merge The second way one can change the context of a patch is by a merge
operation. A merge is an operation that takes two parallel patches and gives a pair of
sequential patches. The merge operation is represented by the arrow “”.
Note that the sequential patches resulting from a merge are required to commute. This is an important consideration, as without it most of the manipulations we would like to perform would not be possible. The other important fact is that a merge cannot fail. Naively, those two requirements seem contradictory. In reality, what it means is that the result of a merge may be a patch which is much more complex than any we have yet considered5.
The constraint that any two compatible patches (patches which can successfully be applied to the same tree) can be merged is actually quite difficult to apply. The above merge constraints also imply that the result of a series of merges must be independent of the order of the merges. So I’m putting a whole section here for the interested to see what algorithms I use to actually perform the merges (as this is pretty close to being the most difficult part of the code).
The first case is that in which the two merges don’t actually conflict, but don’t trivially merge either (e.g. hunk patches on the same file, where the line number has to be shifted as they are merged). This kind of merge can actually be very elegantly dealt with using only commutation and inversion.
There is a handy little theorem which is immensely useful when trying to merge two patches.
Theorem 2 P2'P1P1'P2 if and only if P1'-1P2'
P2P1-1, provided
both commutations succeed. If either commute fails, this theorem does not apply.
This can easily be proven by multiplying both sides of the first commutation by P1'-1 on the left, and by P1-1 on the right. Besides being used in merging, this theorem is also useful in the recursive commutations of mergers. From Theorem 2, we see that the merge of P1 and P2' is simply the commutation of P2 with P1-1 (making sure to do the commutation the right way). Of course, if this commutation fails, the patches conflict. Moreover, one must check that the merged result actually commutes with P1, as the theorem applies only when both commutations are successful.
Of course, there are patches that actually conflict, meaning a merge where the two patches truly cannot both be applied (e.g. trying to create a file and a directory with the same name). We deal with this case by creating a special kind of patch to support the merge, which we will call a “merger”. Basically, a merger is a patch that contains the two patches that conflicted, and instructs darcs basically to resolve the conflict. By construction a merger will satisfy the commutation property (see Definition 3) that characterizes all merges. Moreover the merger’s properties are what makes the order of merges unimportant (which is a rather critical property for darcs as a whole).
The job of a merger is basically to undo the two conflicting patches, and then apply some sort of a “resolution” of the two instead. In the case of two conflicting hunks, this will look much like what CVS does, where it inserts both versions into the file. In general, of course, the two conflicting patches may both be mergers themselves, in which case the situation is considerably more complicated.
Much of the merger code depends on a routine which recreates from a single merger the entire sequence of patches which led up to that merger (this is, of course, assuming that this is the complicated general case of a merger of mergers of mergers). This “unwind” procedure is rather complicated, but absolutely critical to the merger code, as without it we wouldn’t even be able to undo the effects of the patches involved in the merger, since we wouldn’t know what patches were all involved in it.
Basically, unwind takes a merger such as
M( M(A,B), M(A,M(C,D)))
|
C
A M(A,B) M( M(A,B), M(A,M(C,D))) |
A
M(A,B) |
A
M(A,M(C,D)) |
C
A M(A,M(C,D)) |
C
A A M(A,B) M(A,M(C,D)) |
The catch is that things don’t always turn out this easily. There is no guarantee that the two A’s would come out at the same time, and if they didn’t, we’d have to rearrange things until they did. Or if there was no way to rearrange things so that they would agree, we have to go on to plan B, which I will explain now.
Consider the case of M( M(A,B), M(C,D)). We can easily unwind the two subpatches
A C
M(A,B) M(C,D) |
Giving an unwinding of
C'
A M(A,B) M( M(A,B), M(C,D) ) |
It can sometimes be handy to have a canonical representation of a given patch. We achieve this by defining a canonical form for each patch type, and a function “canonize” which takes a patch and puts it into canonical form. This routine is used by the diff function to create an optimal patch (based on an LCS algorithm) from a simple hunk describing the old and new version of a file. Note that canonization may fail, if the patch is internally inconsistent.
A simpler, faster (and more generally useful) cousin of canonize is the coalescing function. This takes two sequential patches, and tries to turn them into one patch. This function is used to deal with “split” patches, which are created when the commutation of a primitive patch can only be represented by a composite patch. In this case the resulting composite patch must return to the original primitive patch when the commutation is reversed, which a split patch accomplishes by trying to coalesce its contents each time it is commuted.
A file patch is a patch which only modifies a single file. There are some rules which can be made about file patches in general, which makes them a handy class. For example, commutation of two filepatches is trivial if they modify different files. There is an exception when one of the files has a name ending with “-conflict”, in which case it may not commute with a file having the same name, but without the “-conflict.” If they happen to modify the same file, we’ll have to check whether or not they commute.
There is another handy function, which primarily affects file patches (although it can also affect other patches, such as rename patches or dir add/remove patches), which is the submerge-in-directory function. This function changes the patch to act on a patch within a subdirectory rather than in the current directory, and is useful when performing the recursive diff.
The hunk is the simplest patch that has a commuting pattern in which the commuted patches differ from the originals (rather than simple success or failure). This makes commuting or merging two hunks a tad tedious. Hunks, of course, can be coalesced if they have any overlap. Note that coalesce code doesn’t check if the two patches are conflicting. If you are coalescing two conflicting hunks, you’ve already got a bug somewhere.
One of the most important pieces of code is the canonization of a hunk, which is where the “diff” algorithm is performed. This algorithm begins with chopping off the identical beginnings and endings of the old and new hunks. This isn’t strictly necessary, but is a good idea, since this process is O(n), while the primary diff algorithm is something considerably more painful than that... actually the head would be dealt with all right, but with more space complexity. I think it’s more efficient to just chop the head and tail off first.
There are a couple of simple constraints on the routine which determines how to resolve two conflicting patches (which is called ‘glump’). These must be satisfied in order that the result of a series of merges is always independent of their order. Firstly, the output of glump cannot change when the order of the two conflicting patches is switched. If it did, then commuting the merger could change the resulting patch, which would be bad. Secondly, the result of the merge of three (or more) conflicting patches cannot depend on the order in which the merges are performed.
The conflict resolution code (glump) begins by “unravelling” the merger into a set of sequences of patches. Each sequence of patches corresponds to one non-conflicted patch that got merged together with the others. The result of the unravelling of a series of merges must obviously be independent of the order in which those merges are performed. This unravelling code (which uses the unwind code mentioned above) uses probably the second most complicated algorithm. Fortunately, if we can successfully unravel the merger, almost any function of the unravelled merger satisfies the two constraints mentioned above that the conflict resolution code must satisfy.
Of course, in order to store our patches in a file, we’ll have to save them as some sort of strings. The convention is that each patch string will end with a newline, but on parsing we skip any amount of whitespace between patches.
Composite patch A patch made up of a few other patches.
{
<put patches here> (indented two) } |
Split patch A split patch is similar to a composite patch (identical in how it’s stored), but rather than being composed of several patches grouped together, it is created from one patch that has been split apart, typically through a merge or commutation.
(
<put patches here> (indented two) ) |
Hunk Replace a hunk (set of contiguous lines) of text with a new hunk.
hunk FILE LINE#
-LINE ... +LINE ... |
Token replace Replace a token with a new token. Note that this format means that the white space must not be allowed within a token. If you know of a practical application of whitespace within a token, let me know and I may change this.
replace FILENAME [REGEX] OLD NEW
|
Binary file modification Modify a binary file
binary FILENAME
oldhex *HEXHEXHEX ... newhex *HEXHEXHEX ... |
Add file Add an empty file to the tree. addfile filename
Remove file Delete a file from the tree. rmfile filename
Move Rename a file or directory. move oldname newname
Change Pref Change one of the preference settings. Darcs stores a number of simple string settings. Among these are the name of the test script and the name of the script that must be called prior to packing in a make dist.
changepref prefname
oldval newval |
Add dir Add an empty directory to the tree. adddir filename
Remove dir Delete a directory from the tree. rmdir filename
Merger patches Merge two patches. The MERGERVERSION is included to allow some degree of backwards compatibility if the merger algorithm needs to be changed.
merger MERGERVERSION
<first patch> <second patch> |
Named patches Named patches are displayed as a ‘patch id’ which is in square brackets, followed by a patch. Optionally, after the patch id (but before the patch itself) can come a list of dependencies surrounded by angle brackets. Each dependency consists of a patch id.
A repository consists of a working directory, which has within it a directory called _darcs. There must also be subdirectories within _darcs named current and patches. The current directory, called the pristine tree, contains the version of the tree which has been recorded, while patches contains the actual patches which are in the repository.
WARNING! Viewing files in current is perfectly acceptable, but if you view them with an editor (e.g. vi or emacs), that editor may create temporary files in the pristine tree (_darcs/pristine/ or _darcs/current/), which will temporarily cause your repository to be inconsistent. So don’t record any patches while viewing files in _darcs/current with an editor! A better plan would be to restrict yourself to viewing these files with a pager such as more or less.
Also within _darcs is the inventory file, which lists all the patches that are in the repo. Moreover, it also gives the order of the representation of the patches as they are stored. Given a source of patches, i.e. any other set of repositories which have between them all the patches contained in a given repo, that repo can be reproduced based on only the information in the inventory file. Under those circumstances, the order of the patches specified in the inventory file would be unimportant, as this order is only needed to provide context for the interpretation of the stored patches in this repository.
There is a very special patch which may be stored in patches which is called ‘pending’. This patch describes any changes which have not yet been recorded, and cannot be determined by a simple diff. For example file additions or renames are placed in pending until they are recorded. Similarly, token replaces are stored in pending until they are recorded. The _darcs directory also contains a directory called “prefs”, which is described in Chapter 4.
Copyright © 1989, 1991 Free Software Foundation, Inc.
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation’s software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.
Also, for each author’s protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors’ reputations.
Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone’s free use or not licensed at all.
The precise terms and conditions for copying, distribution and modification follow.
This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The “Program”, below, refers to any such program or work, and a “work based on the Program” means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term “modification”.) Each licensee is addressed as “you”.
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and “any later version”, you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
<one line to give the program’s name and a brief idea of what it
does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) <year> <name of author>
Gnomovision comes with ABSOLUTELY NO WARRANTY; for
details type ‘show w’.
This is free software, and you are welcome to redistribute it under
certain conditions; type ‘show c’ for details.
The hypothetical commands show w and show c should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than show w and show c; they could even be mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your school, if any, to sign a “copyright disclaimer” for the program, if necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
program
‘Gnomovision’ (which makes passes at compilers) written by James
Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License.