GNU bug report logs - #37185
24.5.1: vc--add-line, vc--remove-regexp are sub-optimal

Previous Next

Package: emacs;

Reported by: Wolfgang Scherer <Wolfgang.Scherer <at> gmx.de>

Date: Sun, 25 Aug 2019 21:01:02 UTC

Severity: normal

Found in version 24.5.1

Done: Dmitry Gutov <dgutov <at> yandex.ru>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 37185 in the body.
You can then email your comments to 37185 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#37185; Package emacs. (Sun, 25 Aug 2019 21:01:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Wolfgang Scherer <Wolfgang.Scherer <at> gmx.de>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 25 Aug 2019 21:01:02 GMT) Full text and rfc822 format available.

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

From: Wolfgang Scherer <Wolfgang.Scherer <at> gmx.de>
To: Emacs Bugs <bug-gnu-emacs <at> gnu.org>
Subject: 24.5.1: vc--add-line, vc--remove-regexp are sub-optimal
Date: Sun, 25 Aug 2019 22:32:35 +0200
In a *vc-dir* buffer for mercurial, ignoring a file with `vc-dir-ignore':

- If the file `.hgignore' is not found, an error is raised:

    vc--add-line: Opening input file: datei oder Verzeichnis nicht gefunden, /srv/install/linux/emacs/check/.hgignore

  This error is unnecesary and serves no real purpose.

- If the file `.hgignore' exists, `vc--add-line' reads the file
  from the filesysstem into a temporary buffer and saves the
  modified buffer back into the filesystem.

  If the file `.hgignore' was already open in a different buffer,
  a prompt is displayed, when trying to modify the contents of
  that buffer:

    File .hgignore changed on disk.  Reread from disk? (y or n) y

  This is at least annoying, if not seriously wrong.

- When adding a new entry to a `.hgignore' file that is already
  terminated with a newline, `vc--add-line' produces an empty
  line and the file ends without a newline, which seriously
  interferes with diffs.

  I fail to see any purpose for such a behavior.

Since `vc-cvs-append-to-ignore' uses `find-file-no-select', there
should be no problem applying the same semantics for mercurial.
The following patch agains the Savannah repository implements the
algorithm from `vc-cvs-append-to-ignore' in `vc--add-line' and
`vc--remove-regexp' as applicable.

diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 4cac153..bd0b601 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1449,20 +1449,21 @@ Argument BACKEND is the backend you are using."
 ;; Subroutine for `vc-git-ignore' and `vc-hg-ignore'.
 (defun vc--add-line (string file)
   "Add STRING as a line to FILE."
-  (with-temp-buffer
-    (insert-file-contents file)
+  (with-current-buffer (find-file-noselect file)
+    (goto-char (point-min))
     (unless (re-search-forward (concat "^" (regexp-quote string) "$") nil t)
       (goto-char (point-max))
-      (insert (concat "\n" string))
-      (write-region (point-min) (point-max) file))))
+      (unless (bolp) (insert "\n"))
+      (insert string "\n")
+      (save-buffer))))
 
 (defun vc--remove-regexp (regexp file)
   "Remove all matching for REGEXP in FILE."
-  (with-temp-buffer
-    (insert-file-contents file)
+  (with-current-buffer (find-file-noselect file)
+    (goto-char (point-min))
     (while (re-search-forward regexp nil t)
       (replace-match ""))
-    (write-region (point-min) (point-max) file)))
+    (save-buffer)))
 
 (defun vc-checkout (file &optional rev)
   "Retrieve a copy of the revision REV of FILE.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#37185; Package emacs. (Mon, 26 Aug 2019 06:45:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Wolfgang Scherer <Wolfgang.Scherer <at> gmx.de>
Cc: 37185 <at> debbugs.gnu.org
Subject: Re: bug#37185: 24.5.1: vc--add-line, vc--remove-regexp are sub-optimal
Date: Mon, 26 Aug 2019 09:44:10 +0300
> From: Wolfgang Scherer <Wolfgang.Scherer <at> gmx.de>
> Date: Sun, 25 Aug 2019 22:32:35 +0200
> 
> diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
> index 4cac153..bd0b601 100644
> --- a/lisp/vc/vc.el
> +++ b/lisp/vc/vc.el
> @@ -1449,20 +1449,21 @@ Argument BACKEND is the backend you are using."
>  ;; Subroutine for `vc-git-ignore' and `vc-hg-ignore'.
>  (defun vc--add-line (string file)
>    "Add STRING as a line to FILE."
> -  (with-temp-buffer
> -    (insert-file-contents file)

Thank you for your contributions.  I expect them to be reviewed soon,
but let me point out that the patches you are sending (in this and
other bug reports) have 2 problems which will make their application
harder than necessary:

  . the whitespace is converted to 0x00a0 NBSP characters, which do
    not exist in the original sources
  . the patches lack commit log messages, in the format described in
    the file CONTRIBUTE in the top-level directory of the Emacs
    sources

It is best to generate your patches using "git format-patch" and then
send them as an attachment, I think this will solve these problems,
assuming that you commit locally with the appropriate log message as
described in CONTRIBUTE.

Thanks again for your interest in Emacs.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#37185; Package emacs. (Mon, 26 Aug 2019 22:54:02 GMT) Full text and rfc822 format available.

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

From: Wolfgang Scherer <Wolfgang.Scherer <at> gmx.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 37185 <at> debbugs.gnu.org
Subject: Re: *** GMX Spamverdacht *** Re: bug#37185: 24.5.1: vc--add-line,
 vc--remove-regexp are sub-optimal
Date: Tue, 27 Aug 2019 00:52:47 +0200
[Message part 1 (text/plain, inline)]
> It is best to generate your patches using "git format-patch" and then
> send them as an attachment, I think this will solve these problems,
OK. I gave it a shot. Patch is attached.
Since it is slightly different than the first submission, please use this new version for review.
[0001-vc-add-line-vc-remove-regexp-enhanced.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#37185; Package emacs. (Tue, 27 Aug 2019 07:38:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Wolfgang Scherer <Wolfgang.Scherer <at> gmx.de>
Cc: 37185 <at> debbugs.gnu.org
Subject: Re: *** GMX Spamverdacht *** Re: bug#37185: 24.5.1: vc--add-line,
 vc--remove-regexp are sub-optimal
Date: Tue, 27 Aug 2019 10:37:01 +0300
> Cc: 37185 <at> debbugs.gnu.org
> From: Wolfgang Scherer <Wolfgang.Scherer <at> gmx.de>
> Date: Tue, 27 Aug 2019 00:52:47 +0200
> 
> > It is best to generate your patches using "git format-patch" and then
> > send them as an attachment, I think this will solve these problems,
> OK. I gave it a shot. Patch is attached.

Thanks, it looks good, but please wait for our VC expert to review it.

> Copyright-paperwork-exempt: yes

I don't think you need this, since your copyright assignment from 2002
is still on file.  If it became invalid since then, I suggest to start
your renewal legal paperwork now, as your contributions are already
beyond the limit we can accept without an assignment.  But if it is
still valid, then just don't use the Copyright-paperwork-exempt
header in the future.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#37185; Package emacs. (Tue, 27 Aug 2019 23:39:02 GMT) Full text and rfc822 format available.

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

From: Wolfgang Scherer <Wolfgang.Scherer <at> gmx.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 37185 <at> debbugs.gnu.org
Subject: Re: *** GMX Spamverdacht *** Re: *** GMX Spamverdacht *** Re:
 bug#37185: 24.5.1: vc--add-line, vc--remove-regexp are sub-optimal
Date: Wed, 28 Aug 2019 01:38:29 +0200
Am 27.08.19 um 09:37 schrieb Eli Zaretskii:
>>
>>> It is best to generate your patches using "git format-patch" and then
>>> send them as an attachment, I think this will solve these problems,
>> OK. I gave it a shot. Patch is attached.
> Thanks, it looks good, but please wait for our VC expert to review it.
Sure I managed for many years, so I am not in a hurry :-)
>> Copyright-paperwork-exempt: yes
> I don't think you need this, since your copyright assignment from 2002
> is still on file.  If it became invalid since then, I suggest to start
> your renewal legal paperwork now, as your contributions are already
> beyond the limit we can accept without an assignment.  But if it is
> still valid, then just don't use the Copyright-paperwork-exempt
> header in the future.

I wasn't sure, if it was still on file. That copyright assignment is
still perfectly valid. I will not use the header any more.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#37185; Package emacs. (Sat, 14 Sep 2019 00:46:02 GMT) Full text and rfc822 format available.

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

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Eli Zaretskii <eliz <at> gnu.org>, Wolfgang Scherer <Wolfgang.Scherer <at> gmx.de>
Cc: 37185 <at> debbugs.gnu.org
Subject: Re: bug#37185: *** GMX Spamverdacht *** Re: bug#37185: 24.5.1:
 vc--add-line, vc--remove-regexp are sub-optimal
Date: Sat, 14 Sep 2019 03:45:03 +0300
On 27.08.2019 10:37, Eli Zaretskii wrote:
> Thanks, it looks good, but please wait for our VC expert to review it.

Not really an expert on those particular functions, but the changes and 
the explanations look good to me as well.

Wolfgang, do you have commit access?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#37185; Package emacs. (Mon, 16 Sep 2019 17:15:02 GMT) Full text and rfc822 format available.

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

From: Wolfgang Scherer <wolfgang.scherer <at> gmx.de>
To: Dmitry Gutov <dgutov <at> yandex.ru>, Eli Zaretskii <eliz <at> gnu.org>
Cc: 37185 <at> debbugs.gnu.org
Subject: Re: bug#37185: *** GMX Spamverdacht *** Re: bug#37185: 24.5.1:
 vc--add-line, vc--remove-regexp are sub-optimal
Date: Mon, 16 Sep 2019 19:14:26 +0200
Am 14.09.19 um 02:45 schrieb Dmitry Gutov:
> On 27.08.2019 10:37, Eli Zaretskii wrote:
>> Thanks, it looks good, but please wait for our VC expert to review it.
>
> Not really an expert on those particular functions, but the changes
> and the explanations look good to me as well.
>
> Wolfgang, do you have commit access?


No, I don't.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#37185; Package emacs. (Mon, 16 Sep 2019 17:16:01 GMT) Full text and rfc822 format available.

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

From: Wolfgang Scherer <wolfgang.scherer <at> gmx.de>
To: Dmitry Gutov <dgutov <at> yandex.ru>, Eli Zaretskii <eliz <at> gnu.org>
Cc: 37185 <at> debbugs.gnu.org
Subject: Re: bug#37185: *** GMX Spamverdacht *** Re: bug#37185: 24.5.1:
 vc--add-line, vc--remove-regexp are sub-optimal
Date: Mon, 16 Sep 2019 19:15:35 +0200
Am 14.09.19 um 02:45 schrieb Dmitry Gutov:
> On 27.08.2019 10:37, Eli Zaretskii wrote:
>> Thanks, it looks good, but please wait for our VC expert to review it.
>
> Not really an expert on those particular functions, but the changes
> and the explanations look good to me as well.
>
> Wolfgang, do you have commit access?


No, I don't.





Reply sent to Dmitry Gutov <dgutov <at> yandex.ru>:
You have taken responsibility. (Tue, 24 Dec 2019 22:40:02 GMT) Full text and rfc822 format available.

Notification sent to Wolfgang Scherer <Wolfgang.Scherer <at> gmx.de>:
bug acknowledged by developer. (Tue, 24 Dec 2019 22:40:02 GMT) Full text and rfc822 format available.

Message #31 received at 37185-done <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Wolfgang Scherer <wolfgang.scherer <at> gmx.de>, Eli Zaretskii <eliz <at> gnu.org>
Cc: 37185-done <at> debbugs.gnu.org
Subject: Re: bug#37185: *** GMX Spamverdacht *** Re: bug#37185: 24.5.1:
 vc--add-line, vc--remove-regexp are sub-optimal
Date: Wed, 25 Dec 2019 00:39:50 +0200
On 16.09.2019 20:15, Wolfgang Scherer wrote:
> Am 14.09.19 um 02:45 schrieb Dmitry Gutov:
>> On 27.08.2019 10:37, Eli Zaretskii wrote:
>>> Thanks, it looks good, but please wait for our VC expert to review it.
>>
>> Not really an expert on those particular functions, but the changes
>> and the explanations look good to me as well.
>>
>> Wolfgang, do you have commit access?
> 
> 
> No, I don't.

Installed with some changes in the commit message.

Thanks you.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 22 Jan 2020 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 96 days ago.

Previous Next


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