GNU bug report logs - #11894
24.1.50; [PATCH] diff-apply-hunk can be off by 1 line when the hunk is 0-context pure removal

Previous Next

Package: emacs;

Reported by: Dmitry Gutov <dgutov <at> yandex.ru>

Date: Tue, 10 Jul 2012 01:53:01 UTC

Severity: normal

Tags: patch, wontfix

Found in version 24.1.50

Done: Chong Yidong <cyd <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.1.50; [PATCH] diff-apply-hunk can be off by 1 line when the hunk
	is 0-context pure removal
Date: Tue, 10 Jul 2012 05:46:37 +0400
[Message part 1 (text/plain, inline)]
This applies both to context and unified diffs.

To get a 0-context hunk, you invoke diff command with -c0 or -U0 argument.

1. Example files (4 and 3 lines long):

test:
z
abc

def

test2:
z
abc
def

2. Run `diff -c0 test test2 > test.diff`:
*** test	2012-07-09 06:04:04.572209000 +0400
--- test2	2012-07-09 06:04:11.987150600 +0400
***************
*** 3 ****
-
--- 2 ----

3. Open test.diff in Emacs, then:
a) Do `C-u C-c C-a' (reverse hunk) -> see the empty line appear after 
"z", instead of after "abc".
b) Open test2, add empty line after "abc", go to test.diff window, do 
`C-c C-a' (apply hunk), see the newline between "z" and "abc" disappear 
instead.

Not sure if we can rely on the line number being always off by 1 in such 
hunks (there's no insertion, so, technically, the second line number in 
the header could be arbitrary), but at least 3 versions of diff across 2 
different OSes work the same in this regard.

Note that if you try to create such hunk with `diff-split-hunk' (by 
slicing it off a bigger hunk), the line number won't be off by 1.
Maybe that's a bug in `diff-split-hunk'.

--Dmitry
[diff-mode.diff (text/plain, attachment)]

This bug report was last modified 12 years and 234 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.