[darcs-users] darcs convert

Max Brown max.e.brown at gmail.com
Thu Aug 13 18:26:58 UTC 2009


> Indeed, many thanks for getting back to us!  How would you feel about
> writing this up as an FAQ?

Hi Eric,

here is something I wrote. I tried to put this into the wiki, but
every time I hit 'preview', the page just hangs (it never loads and
eventually times out?).

If you think it might be useful, feel free to put it up.

Max
-------------- next part --------------
``darcs convert`` fails!
~~~~~~~~~~~~~~~~~~~~~~~~

The problem: Suppose you have a plain darcs 1 repository, and want to convert it to darcs 2 format, and get an error message of the following type:

::

	darcs failed:  Error applying hunk to file foo

What are possible problems, and their solutions?

One possible cause is that you have some "corrupt hunks" within some of your patches.

An example:
Suppose in file foo contains only the line 'abc'

A patch that deletes the first line 'abc' and replaces it with 'def' (created e.g. with diff -u) might contain something like the following

::

	@@ -1 +1 @@
	-abc
	+def

The problem now arises if you have a patch that tries to delete the first line 'ghi' and replace it with 'def'. This will not work, because the first line actually reads 'abc', and not 'ghi'. Such a patch might might look like this:

::

	@@ -1 +1 @@
	-ghi
	+def

The original, plain darcs 1 repositories can (with some ingenuity...) be brought into a state where you have such corrupt hunks that fail to apply. This can become obvious when you try to ``darcs convert`` because the new formats try to prevent this kind of corruption.

How can you fix it?
1) Create a new repository with ``darcs init --old-fashioned-inventory``
2) Pull your patches from the dubious repository, one by one, until you identify a patch that fails. Write down the timestamp associated with the patch.
3) Figure out why the patch fails: create a patch file manually:
``darcs diff -p 'thefailingpatchname' filename > fail.patch``
where 'thefailingpatchname' is a pattern that identifies the patch, filename is the name of the file for which the hunk fails to apply
4) Try to apply the patch manually:
``patch filename fail.patch``
and see what happens. It also helps to look at the patch, and the file it is trying to patch, you can for instance see if the patch wants to change a line in the file which does not exist.
5) Try to find a way to make the patch apply. Use ``darcs revert`` to revert the file to the original state, and then edit the patch by hand. For example, if the problem is that the patch should be replacing the line 'abc' with 'def' instead of trying to replace 'ghi' with 'def', replace 'ghi' with 'abc'.
6) Once you have a version of the patch that applies, 
6a) make a temporary copy of the dubious repository (e.g. with ``cp -R``),
6b) and change the corresponding patch in the temporary repository: The patches are in ``_darcs/patches``, and filenames start with a number that indicates the timestamp (see step 2). ``20091001104115``.... is a patch that was made on the 1st of October 2009, at 10:41 and 15 seconds (GMT). To edit the patches you need to gunzip them, make the changes, and then gzip them.
7) Repeat steps 1 and 2, pulling from the temporary copy of the dubious repository, and see whether you can now pull the fixed patch.

Repeat for any remaining failing patches.

8) Once you have a repository with no more remaining failing patches, you can run ``darcs convert``.


More information about the darcs-users mailing list