hunk move as primitive change
Ben Franksen <benjamin.franksen <at> bessy.de>
2013-04-30 23:51:42 GMT
This is something I have on my wish-list for longer than I can think. The
idea is quite simple: a primitive change type that says "this sequence of
lines moved from file X line N to file Y line M". Here, X and Y need not be
different, i.e. a hunk move need not be between different files.
To my knowledge no existing VCS has such a feature. There are two advantages
(1) Moving code around is something I do regularly in the process of
cleaning up my (or other's) code. Currently such changes are represented
(e.g. when using record or whatsnew) as "remove these lines from file X line
N (long block of code follows), add these lines to file Y line M (another
long block of code follows)". The remove and insert changes need not even be
adjacent to one another (they typically are not) and even if they are it is
very hard for the human eye to spot small differences in a long stretch of
text. So if the tool told me I have a move (or I could tell it that this is
the case) then I could be confident that no functional change occurred.
(2) A hunk move commutes with changes /inside/ the hunk, or at least I can
see no reason why it should not. This is not the case for the way such a
move is represented now (as a remove and insert). This would mean more
changes commute and thus less (accidental, unwanted) conflicts.
Even though the idea is simple, this is certainly not "low hanging fruit".
It would be necessary to somehow record that the context for changes further
down in the affected files translates up resp. down (by the number of lines
moved), and to update this information when commuting such a change with
other changes. On the other hand, for regular hunks we do that already, so
maybe it is not that difficult after all. In any case adding a new primitive
change type most probably counts as a "deep" change to the Darcs code; and I
wonder if the repository format would have to be adapted and whether this
could be done in a backward compatible way.
BTW, a "better record command" as in the GSOC proposal (which I find very
promising) could be tought to detect hunk moves and present them to the user
as such. It could even propose to record a move if there /are/ additional
changes inside such a moved hunk, i.e. separate the move from (minor)
changes made to the affected lines, using some kind of similarity measure.
I would love to hear what you think about that.
() ascii ribbon campaign - against html e-mail
/\ www.asciiribbon.org - against proprietary attachm€nts
darcs-users mailing list
darcs-users <at> darcs.net