[darcs-users] The future of darcs - glowing or gloomy

Ian Lynagh igloo at earth.li
Tue Mar 10 13:12:19 UTC 2009

On Sun, Mar 08, 2009 at 07:56:29PM +0100, Thorkil Naur wrote:
> > > This was really an innocent remark.
> > > I was just saying that darcs does 
> > > not use heuristics to determine where hunks should be applied; it does
> > > so with exact knowledge and hence, preserves user intent.
> This is only true if the hunks faithfully represent the user's intent. Which, 
> as I understand the word "intent", they fairly obviously don't, in most 
> cases, and certainly, in general, cannot. Let me explain.

Yes, "preserves user intent" is the wrong phrase, but darcs does
preserve the meaning of the patch. I'll try to explain what I mean...

> When adding a line to a file, I rarely know anything about the 
> number of the line that I am inserting, nevertheless the line number is part 
> of the hunk that represents my change.

The line number is just an implementation detail; it's just how darcs
happens to identify lines.

Let's take this slightly simpler example:

hunk f.txt 3
-Old line 3
+New line 3

In this hunk, darcs will replace the line "Old line 3" with "New line
3", and it really is /the/ line "Old line 3", not /a/ line "Old line 3".
It's hard to talk about this formally without giving some lower level
definitions (e.g. defining identity of lines in a file), but if this
line is shifted up or down (by removing or adding lines earlier in
f.txt), then it is the same line that will be changed. And if you remove
the line, and then add back a new one with the same text:

hunk f.txt 3
-Old line 3

hunk f.txt 3
+Old line 3

then the original hunk will no longer apply.

However, the darcs patch theory is not maintaining your intent. It is
maintaining what it was you told it to do when you recorded the hunk.
In your other example, you could have recorded any of the following 3
patches (although the last one doesn't actually exist, and the darcs
implementation only has a way to record one of the others (and
essentially a random one at that; in the next version of darcs you might
only be able to record the other one)):

hunk ./f.txt 1
-Line 1
hunk ./f.txt 2
+Line 1

hunk ./f.txt 1
+Line 2
hunk ./f.txt 3
-Line 2

Swap ./f.txt 1 2

and depending on which one you recorded, you would be able to commute
with a different set of other patches, but in each case darcs would
preserve the meaning of the patch.

> In choosing the hunk to represent some change, surely heuristics are
> involved.

Yes, the theory doesn't talk about how patches are created, but about
what happens to them after that.


More information about the darcs-users mailing list