* bug#37217: [PATCH] vc-default-ignore implementation is incorrect
@ 2019-08-29 0:53 Wolfgang Scherer
[not found] ` <handler.37217.B.15670400118803.ack@debbugs.gnu.org>
2019-09-15 13:06 ` bug#37217: [PATCH] vc-default-ignore implementation is incorrect Lars Ingebrigtsen
0 siblings, 2 replies; 3+ messages in thread
From: Wolfgang Scherer @ 2019-08-29 0:53 UTC (permalink / raw)
To: 37217
[-- Attachment #1: Type: text/plain, Size: 245 bytes --]
Only the basename of FILE is written to the ignore file. This is
wrong for all filenames relative to project root with one ore
more parent directories.
The remove option is also implemented incorrectly.
The attached patch fixes these errors.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fixes-vc-default-ignore.patch --]
[-- Type: text/x-patch; name="0001-Fixes-vc-default-ignore.patch", Size: 2037 bytes --]
From 7ca81822189035db9a117b66ed8365b4eb2ab88b Mon Sep 17 00:00:00 2001
From: Wolfgang Scherer <wolfgang.scherer@gmx.de>
Date: Thu, 29 Aug 2019 02:51:03 +0200
Subject: [PATCH] Fixes vc-default-ignore
* lisp/vc/vc.el: (vc-default-ignore) Treat FILE parameter as relative
to DIRECTORY parameter. Construct a file-path relative to directory
of ignore file. When removing, use properly anchored regexp. Remove
entire line, not just the match.
---
lisp/vc/vc.el | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 4cac153..2b1f163 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1417,17 +1417,22 @@ remove from the list of ignored files."
(defun vc-default-ignore (backend file &optional directory remove)
"Ignore FILE under the VCS of DIRECTORY (default is `default-directory').
-FILE is a file wildcard, relative to the root directory of DIRECTORY.
+FILE is a wildcard specification, either relative to
+DIRECTORY or absolute.
When called from Lisp code, if DIRECTORY is non-nil, the
repository to use will be deduced by DIRECTORY; if REMOVE is
non-nil, remove FILE from ignored files.
Argument BACKEND is the backend you are using."
(let ((ignore
(vc-call-backend backend 'find-ignore-file (or directory default-directory)))
- (pattern (file-relative-name
- (expand-file-name file) (file-name-directory file))))
+ file-path root-dir pattern)
+ (setq file-path (expand-file-name file directory))
+ (setq root-dir (file-name-directory ignore))
+ (when (not (string= (substring file-path 0 (length root-dir)) root-dir))
+ (error "Ignore spec %s is not below project root %s" file-path root-dir))
+ (setq pattern (substring file-path (length root-dir)))
(if remove
- (vc--remove-regexp pattern ignore)
+ (vc--remove-regexp (concat "^" (regexp-quote pattern ) "\n?") ignore)
(vc--add-line pattern ignore))))
(defun vc-default-ignore-completion-table (backend file)
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
[parent not found: <handler.37217.B.15670400118803.ack@debbugs.gnu.org>]
* bug#37217: Acknowledgement ([PATCH] vc-default-ignore implementation is incorrect)
[not found] ` <handler.37217.B.15670400118803.ack@debbugs.gnu.org>
@ 2019-08-29 15:44 ` Wolfgang Scherer
0 siblings, 0 replies; 3+ messages in thread
From: Wolfgang Scherer @ 2019-08-29 15:44 UTC (permalink / raw)
To: 37217
[-- Attachment #1: Type: text/plain, Size: 88 bytes --]
A unit test showed, that the removal regexp was faulty. New version of patch attached.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-vc-default-ignore.patch --]
[-- Type: text/x-patch; name="0001-Fix-vc-default-ignore.patch", Size: 2044 bytes --]
From d2638e621c8da1f93345a5d87691b165d5a05569 Mon Sep 17 00:00:00 2001
From: Wolfgang Scherer <wolfgang.scherer@gmx.de>
Date: Thu, 29 Aug 2019 17:39:21 +0200
Subject: [PATCH] Fix vc-default-ignore
* lisp/vc/vc.el: (vc-default-ignore) Treat FILE parameter as relative
to DIRECTORY parameter. Construct a file-path relative to directory
of ignore file. When removing, use properly anchored regexp. Remove
entire line, not just the match.
---
lisp/vc/vc.el | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 4cac153..c982b02 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1417,17 +1417,22 @@ remove from the list of ignored files."
(defun vc-default-ignore (backend file &optional directory remove)
"Ignore FILE under the VCS of DIRECTORY (default is `default-directory').
-FILE is a file wildcard, relative to the root directory of DIRECTORY.
+FILE is a wildcard specification, either relative to
+DIRECTORY or absolute.
When called from Lisp code, if DIRECTORY is non-nil, the
repository to use will be deduced by DIRECTORY; if REMOVE is
non-nil, remove FILE from ignored files.
Argument BACKEND is the backend you are using."
(let ((ignore
(vc-call-backend backend 'find-ignore-file (or directory default-directory)))
- (pattern (file-relative-name
- (expand-file-name file) (file-name-directory file))))
+ file-path root-dir pattern)
+ (setq file-path (expand-file-name file directory))
+ (setq root-dir (file-name-directory ignore))
+ (when (not (string= (substring file-path 0 (length root-dir)) root-dir))
+ (error "Ignore spec %s is not below project root %s" file-path root-dir))
+ (setq pattern (substring file-path (length root-dir)))
(if remove
- (vc--remove-regexp pattern ignore)
+ (vc--remove-regexp (concat "^" (regexp-quote pattern ) "\\(\n\\|$\\)") ignore)
(vc--add-line pattern ignore))))
(defun vc-default-ignore-completion-table (backend file)
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* bug#37217: [PATCH] vc-default-ignore implementation is incorrect
2019-08-29 0:53 bug#37217: [PATCH] vc-default-ignore implementation is incorrect Wolfgang Scherer
[not found] ` <handler.37217.B.15670400118803.ack@debbugs.gnu.org>
@ 2019-09-15 13:06 ` Lars Ingebrigtsen
1 sibling, 0 replies; 3+ messages in thread
From: Lars Ingebrigtsen @ 2019-09-15 13:06 UTC (permalink / raw)
To: Wolfgang Scherer; +Cc: 37217
Wolfgang Scherer <Wolfgang.Scherer@gmx.de> writes:
> Only the basename of FILE is written to the ignore file. This is
> wrong for all filenames relative to project root with one ore
> more parent directories.
>
> The remove option is also implemented incorrectly.
[...]
> A unit test showed, that the removal regexp was faulty. New version of
> patch attached.
Thanks; I've only lightly tested this, but if I read the code correctly,
I think it makes sense, so I've now applied it to Emacs 27.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-09-15 13:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-29 0:53 bug#37217: [PATCH] vc-default-ignore implementation is incorrect Wolfgang Scherer
[not found] ` <handler.37217.B.15670400118803.ack@debbugs.gnu.org>
2019-08-29 15:44 ` bug#37217: Acknowledgement ([PATCH] vc-default-ignore implementation is incorrect) Wolfgang Scherer
2019-09-15 13:06 ` bug#37217: [PATCH] vc-default-ignore implementation is incorrect Lars Ingebrigtsen
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).