[darcs-users] How to reset a file to an older state?

Thomas Schwinge tschwinge at gnu.org
Fri Apr 28 14:22:43 UTC 2006


On Wed, Apr 26, 2006 at 07:55:32PM +0200, Juliusz Chroboczek wrote:
> Very interesting problem.

:-)

> What I would suggest would be to write a script in the text-processing
> language of your choice (it should be easy enough in sed, but even perl
> might be usable if you've got the docs handy) that takes a classic
> patch and a context, and produces a Darcs patch bundle.  You'd then be
> able to do
> 
>   $ darcs changes --context --to-patch V > /tmp/context
>   $ mkbundle P context > bundle
>   $ darcs apply bundle
> 
> which will automatically commute the patch into the right position in
> the history.

That sounds like a very neat idea, but the ``transform a classic patch
into a darcs patch'' is not as trivial as one might think.  At least if
you assume that darcs is rather strict with the input it accepts, which I
did, since I don't know better.  Pointers to documentation of valid input
would be gladly accepted.


> For extra points, your script should be able to grok a number of
> different patch formats, including GNU unidiff and context diffs.

I decided to only go for `diff -U0' for now.

I basically have this transform working--using sed--when I stumbled on
the following:

#v+
diff -U0                                darcs whatsnew

@@ -0,0 +1,3 @@                         hunk ./a 1
+line -2                                +line -2
+line -1                                +line -1
+line 0                                 +line 0
@@ -2,3 +5,5 @@                         hunk ./a 5
-line 2                                 -line 2
-line 3                                 -line 3
-line 4                                 -line 4
+line 3a                                +line 3a
+line 3b                                +line 3b
+line 4a                                +line 4a
+line 4b                                +line 4b
+line 4c                                +line 4c
@@ -6,2 +10,0 @@                        hunk ./a 11
-line 6                                 -line 6
-line 7                                 -line 7
@@ -9 +12 @@                            hunk ./a 12
-line 9                                 -line 9
+line 9-nine                            +line 9-nine
@@ -10,0 +14 @@                         hunk ./a 14
+line 11                                +line 11
#v-

(Note the offsets of the third hunk.)  It seems that calculating will
also be involved.


> If that functionality is useful enough, it could be implemented in
> Darcs itself,
> 
>   darcs apply --alien-context=C P
> 
> but only if someone volunteers to write a patch parser in Haskell.

What about `darcs record --at-{match,patch,tag}=...'?  This would
internally reset the repository to the specified state and then record
either the whole repository or only potentially specified files.


Regards,
 Thomas




More information about the darcs-users mailing list