unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: 11894@debbugs.gnu.org
Subject: bug#11894: 24.1.50; [PATCH] diff-apply-hunk can be off by 1 line when the hunk is 0-context pure removal
Date: Wed, 18 Jul 2012 08:53:15 -0400	[thread overview]
Message-ID: <jwvvchl1bvk.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <4FFB897D.7080303@yandex.ru> (Dmitry Gutov's message of "Tue, 10 Jul 2012 05:46:37 +0400")

> 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.

This looks like a bug in those versions of diff (not that I know
a non-buggy version, tho).  Could you report it to GNU diffutils.

> 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.

Oh, right, so there is a "version of diff" that doesn't have this bug ;-)

> Maybe that's a bug in `diff-split-hunk'.

I doubt it.  At least `patch' seems to agree with diff-mode.el:

   % diff -c0 footest1 footest2 |patch -o footest3 footest1
   patching file footest1
   patch: **** replacement text or line numbers mangled in hunk at line 8
   % 

> -        (goto-char (point-min)) (forward-line (1- (string-to-number line)))
> +        (let ((line-num (string-to-number line)))
> +          ;; When the hunk is pure deletion, line number is off by 1.
> +          (when (string= (if reverse (car old) (car new)) "")
> +            (incf line-num))
> +          (goto-char (point-min)) (forward-line (1- line-num)))

Context/unified diffs with 0 context are pretty rare, so I'd rather not
work around such a bug if I don't really have to.


        Stefan





  reply	other threads:[~2012-07-18 12:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-10  1:46 bug#11894: 24.1.50; [PATCH] diff-apply-hunk can be off by 1 line when the hunk is 0-context pure removal Dmitry Gutov
2012-07-18 12:53 ` Stefan Monnier [this message]
2012-07-18 13:28   ` Andreas Schwab
2012-07-19  7:58     ` Stefan Monnier
2012-07-19  8:40       ` Andreas Schwab
2012-07-18 17:25   ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvvchl1bvk.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=11894@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).