darcs

Issue 2639 darcs diff crashes with --last=1 and file name

Title darcs diff crashes with --last=1 and file name
Priority Status resolved
Milestone Resolved in 2.15.0
Superseder Nosy List bfrk
Assigned To
Topics

Created on 2020-01-24.14:32:46 by bfrk, last changed 2020-02-15.22:02:16 by noreply.

Messages
msg21693 (view) Author: bfrk Date: 2020-01-24.14:32:43
While playing with [patch1952] I found a bug in darcs diff (current head
of screened). Here is how to reproduce:


franksen@tiber: /tmp/diffbug > darcs init
franksen@tiber: /tmp/diffbug > echo one > file1
franksen@tiber: /tmp/diffbug > cp file1 file2
franksen@tiber: /tmp/diffbug > darcs record -lam one
Do you want to add a long comment? [yn]n
Finished recording patch 'one'
franksen@tiber: /tmp/diffbug > darcs log -v
patch 1cd55eee353f694d17b3d4f148e9a8ca43a1b99f
Author: Ben Franksen <ben.franksen@online.de>
Date:   Fri Jan 24 15:43:15 CET 2020
  * one
    addfile ./file1
    hunk ./file1 1
    +one
    addfile ./file2
    hunk ./file2 1
    +one
franksen@tiber: /tmp/diffbug > echo two > file1
franksen@tiber: /tmp/diffbug > cp file1 file2
franksen@tiber: /tmp/diffbug > darcs-clean diff file1 --last=1
### Error applying:
hunk ./file2 1
-one
### to file file2:
two
### Reason: Hunk wants to remove content that isn't there

I know what causes the problem and will send a test script and a fix.
msg21696 (view) Author: bfrk Date: 2020-01-24.15:18:25
See patch1953 for a test script.
msg21697 (view) Author: bfrk Date: 2020-01-24.15:54:09
Here is what goes wrong:

Whether the diff command takes unrecorded changes into consideration or
not depends on whether the options indicate a secondMatch or not. If we
have a secondMatch then unrecorded changes are ignored, otherwise they
are put into an anonymous named patch that we append to the initial
patchset (consisting of the recorded patches).

If we have a firstMatch but no secondMatch (as is the case with
--last=N), then (in the local rundiff procedure) tounapply contains the
unrecorded changes as its last patch. We then unapply this from a copy
of our current pristine tree (in hashed format) which obviously cannot
succeed.

A possible way to fix this is to check if we have no secondMatch and in
that case first apply the unrecorded changes to our copy of the pristine
tree, so it corresponds to the state of our working tree, not the
pristine tree.
msg21831 (view) Author: noreply Date: 2020-02-15.22:02:14
The following patch sent by Ben Franksen <ben.franksen@online.de> updated issue issue2639 with
status=resolved;resolvedin=2.15.0 HEAD

* resolve issue2639: darcs diff crashes with --last=1 and file name 
Ignore-this: 282c0146f99b69bac724dd9624bb7d700110f3a2d5d343c72d654cfe6ec601d26bbc6e722381796a
History
Date User Action Args
2020-01-24 14:32:46bfrkcreate
2020-01-24 15:18:28bfrksetmessages: + msg21696
2020-01-24 15:54:12bfrksetmessages: + msg21697
2020-02-15 22:02:16noreplysetstatus: unknown -> resolved
messages: + msg21831
resolvedin: 2.15.0