From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#37189: 25.4.1: vc-hg-ignore implementation is missing Date: Fri, 21 Feb 2020 02:05:50 +0200 Message-ID: <9929b44f-37da-23c8-16cc-c6ca89602149@yandex.ru> References: <1ba53ae2-42a4-3ab3-d4f2-2ceae565d198@gmx.de> <57825d73-27a4-d5f5-8198-a172796a558a@gmx.de> <1ebc6077-9175-65ba-4996-282bb2c8eca5@yandex.ru> <6145d6f6-37a8-7166-731b-57669086b145@gmx.de> <838slmk90j.fsf@gnu.org> <83h806gp2w.fsf@gnu.org> <8336bmg1o9.fsf@gnu.org> <2354821b-5c1e-f9e3-3a64-4ff978ded33b@gmx.de> <83sgjkdev5.fsf@gnu.org> <3fb73dbc-bf31-233b-4afc-2147c4ffd5b7@gmx.de> <5622487d-a21f-49cf-5420-21f87415af4f@gmx.de> <83wo8ubfbo.fsf@gnu.org> <83zhdpqbas.fsf@gnu.org> <2c8419ae-723d-c7ae-a60e-59d1b1cbc2c1@gmx.de> <83o8u3r6wg.fsf@gnu.org> <6f3ba261-e1f9-cf19-cc22-ec8c24cf3298@gmx.de> <83blq2qzqp.fsf@gnu.org> <83ftfdplo8.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------D2612A5E2B24387BABF1E3D5" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="70467"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 Cc: 37189@debbugs.gnu.org, Wolfgang Scherer To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Feb 21 01:06:15 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j4vpe-000IDi-Lh for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 21 Feb 2020 01:06:14 +0100 Original-Received: from localhost ([::1]:50636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4vpd-0004eR-Nd for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 20 Feb 2020 19:06:13 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60565) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4vpU-0004e7-Fx for bug-gnu-emacs@gnu.org; Thu, 20 Feb 2020 19:06:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j4vpS-0003gE-Q0 for bug-gnu-emacs@gnu.org; Thu, 20 Feb 2020 19:06:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40136) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j4vpS-0003g6-MR for bug-gnu-emacs@gnu.org; Thu, 20 Feb 2020 19:06:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1j4vpS-00054C-H5 for bug-gnu-emacs@gnu.org; Thu, 20 Feb 2020 19:06:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 21 Feb 2020 00:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37189 X-GNU-PR-Package: emacs Original-Received: via spool by 37189-submit@debbugs.gnu.org id=B37189.158224356119469 (code B ref 37189); Fri, 21 Feb 2020 00:06:02 +0000 Original-Received: (at 37189) by debbugs.gnu.org; 21 Feb 2020 00:06:01 +0000 Original-Received: from localhost ([127.0.0.1]:46109 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j4vpQ-00053x-MO for submit@debbugs.gnu.org; Thu, 20 Feb 2020 19:06:01 -0500 Original-Received: from mail-wr1-f54.google.com ([209.85.221.54]:43227) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j4vpP-00053k-Bb for 37189@debbugs.gnu.org; Thu, 20 Feb 2020 19:06:00 -0500 Original-Received: by mail-wr1-f54.google.com with SMTP id r11so21133wrq.10 for <37189@debbugs.gnu.org>; Thu, 20 Feb 2020 16:05:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=xut4NBzXifoe7kSsvbdGjGQgM9KcsPU41xz4nwrEQK4=; b=BxViCo/7qJCgRc5N8/hB447HUf+Yo0AKK16DU2p7qFHhalBQmhCdrxiMuRyFaJZPZL DUi0pArzVV+1uCR36WwK9ZoQ4BljD+pP1vIWOOfOohXqOHv4j58lqF/IjvNKe4PAZyJB bYtXSiFzLD9tcfxLFvVFY3trPcbIi3zxqraOEKhIjvJzbTdgtj3PDFTMg1Rr1I4javkL H3OiBvpRbuA3gbbeTGOPJgbWPGzLNecg3UN6ejIomoINJ7GisGVi1itxAqMhAiFAh/ku +9BvqwfU2P7uqe1PfapsGiZrAszqa7UqqGHcEDZrqQZr55ZtO6rjTAqr1/XaR1eOi7Cd eSNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=xut4NBzXifoe7kSsvbdGjGQgM9KcsPU41xz4nwrEQK4=; b=nW/G4O8fY3c85d4xZkJoFFQpKIa2awatSGaeIFEc+tjm4CttBbJuqNBbtSGrX/owgV nRzV4FUMMJ23fJw9V4Y5MBg+HXtakg+a7Ckhh5VCkRJezUd2aT0s2jBI74Z97FTf1bta 5A8HktGJrl7ceCUaFuG7W8HC7zAyCzGoX1PyjTjJX0S5j4PrJQNZzTk7v79KngH+EyC3 UMumScaD44MVDVJZn5m44UidcuXTVHRg5Ux7T2jXU2z9PGfwwY4UipCeY/rh3eGbyLBH nxQKRGUFfQrWXgZVcnaqCv7t60leRtV5qfskXDHtGqPx4YqswEqJQc1xRtD+VpTYKRj6 98Dg== X-Gm-Message-State: APjAAAVQW9ZD7V5JRfB2lNzyFZmNvIH1rnil53wR5h3k7qm3y59miCdt y5NCaO1lbWVK/4ZEfiKzNQI= X-Google-Smtp-Source: APXvYqx9RYwMxgFGq88EpPEdwkwpbNvYzRiZi+wWZshQwT8m7ReS2iBN+gjiCy9iBrCbI3M625ZbtQ== X-Received: by 2002:a5d:614a:: with SMTP id y10mr46760521wrt.73.1582243553415; Thu, 20 Feb 2020 16:05:53 -0800 (PST) Original-Received: from [192.168.0.3] ([66.205.73.129]) by smtp.googlemail.com with ESMTPSA id c15sm1540178wrt.1.2020.02.20.16.05.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Feb 2020 16:05:52 -0800 (PST) In-Reply-To: <83ftfdplo8.fsf@gnu.org> Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:176325 Archived-At: This is a multi-part message in MIME format. --------------D2612A5E2B24387BABF1E3D5 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 14.02.2020 11:23, Eli Zaretskii wrote: >> Cc: 37189@debbugs.gnu.org >> From: Dmitry Gutov >> Date: Fri, 14 Feb 2020 01:40:31 +0200 >> >> I think the first thing I'll have to do is revert a part of an earlier >> patch to vc-default-ignore which changed its semantics a little, because >> it doesn't look like this discussion is going to culminate in a patch >> small enough for emacs-27 anyway. > > Which part? Can you show a proposed patch? See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=37217. The patch fixed a legitimate scenario, but made an existing one work worse. Trying to vc-ignore, say, '*.c' from a subdirectory in a Git repo, for instance, will now prepend the intermediary directories to it. (Mentioned this before: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=37189#41) Now, one could argue that one use case is more important than the other one, and that vc-ignore has for a while been geared toward entering plain file names rather than glob patterns. I have little opinion on this subject, however, since I mostly edit ignore files by hand, and do so very rarely. So as far as I'm concerned, we could remove this feature altogether and not lose much. But maybe it's more valuable for SVN users? Where the ignore configuration is more tricky and the DIRECTORY argument is actually important. So the options at hand are: - Revert almost all of the patch from bug#37217, reverting to the previous, admittedly broken behavior, and continue to discuss a better improvement for Emacs 28. - Try to resolve the ambiguity of purpose in favor either entering patterns on file names only. Probably the latter, later vc-ignore to vc-ignore-file. - Try to sit on both chairs... Basically, that means using the user input unaltered. Allowing them to enter a file name as well, but treat it as a pattern, without escaping or the like. This would be close to the original intent behind vc-ignore, AFAICT. To do the last one, read-file-name would need to be called with the second argument provided, the directory against which the file path should be relative. For most backend, we can reuse the find-ignore-file backend command, but SVN (and RCS, etc) don't have it defined. Roughly and handwavy, we can take this case to mean "use default-directory". As you noted, the use of read-file-name at all in vc-ignore is somewhat problematic, but let's see if we can keep the function sane without removing it first. Attaching a patch. Eli, Wolfgang, any objections? >> Then, naturally, we'll have to look for small changes that improve the >> situation but provide as little breakage as possible. > > Agreed. Alas, the attached patch is probably not a "small" one. Option 1 would pass this criterion, though. > 1) vc-dir-ignore: > > It calculates the file name for the entry into the ignore file, and > thus must escape any characters in the file name that are special in > ignore files -- which is backend-specific. > > The file name should also be "anchored", at least ideally, so that no > other file is accidentally ignored. This is also backend-specific. I think we can add a new backend action that would escape and anchor a file name (and maybe turn it from an absolute into a relative one). That should take care of it. > VC's support for directory-specific ignore files is inconsistent: they > are supported for CVS (and actually mandatory there) and maybe SVN, > but not for Git/Bazaar/Mercurial/Monotone -- for the latter we only > support ignore files in the repository root. This could be improved > in the future, but for now I don't see an immediate need. Agreed. > For the same reason, using read-file-name here is too naïve, as well > as yielding an absolute file name from what the user types. For now, I kept the former but decided against the latter. > If you agree with the above, we then need to decide what, if anything, > of this should be fixed for Emacs 27. E.g., vc-dir-ignore seems to be > OK if the file name doesn't include special characters, does it? With the attached patch, it needed a small adjustment, but with that should work okay-ish again. --------------D2612A5E2B24387BABF1E3D5 Content-Type: text/x-patch; name="vc-ignore.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="vc-ignore.diff" diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el index 033cb27e33..e5c5e16a17 100644 --- a/lisp/vc/vc-dir.el +++ b/lisp/vc/vc-dir.el @@ -879,7 +879,9 @@ vc-dir-ignore (vc-ignore (vc-dir-fileinfo->name filearg)) t)) vc-ewoc) - (vc-ignore (vc-dir-current-file)))) + (vc-ignore + (file-relative-name (vc-dir-current-file)) + default-directory))) (defun vc-dir-current-file () (let ((node (ewoc-locate vc-ewoc))) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index ec252b74d4..72bd4d3910 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -1406,16 +1406,21 @@ vc-ignore prefix argument is given, in which case prompt for a file FILE to remove from the list of ignored files." (interactive - (list - (if (not current-prefix-arg) - (read-file-name "File to ignore: ") - (completing-read - "File to remove: " - (vc-call-backend - (or (vc-responsible-backend default-directory) - (error "Unknown backend")) - 'ignore-completion-table default-directory))) - nil current-prefix-arg)) + (let* ((backend (vc-responsible-backend default-directory)) + (rel-dir + (condition-case nil + (file-name-directory + (vc-call-backend backend 'find-ignore-file + default-directory)) + (vc-not-supported + default-directory))) + (file (read-file-name "File to ignore: "))) + (when (and (file-name-absolute-p file) + (file-in-directory-p file rel-dir)) + (setq file (file-relative-name file rel-dir))) + (list file + rel-dir + current-prefix-arg))) (let* ((directory (or directory default-directory)) (backend (or (vc-responsible-backend default-directory) (error "Unknown backend")))) @@ -1423,23 +1428,18 @@ vc-ignore (defun vc-default-ignore (backend file &optional directory remove) "Ignore FILE under the VCS of DIRECTORY (default is `default-directory'). -FILE is a wildcard specification, either relative to -DIRECTORY or absolute. +FILE is a wildcard specification relative to DIRECTORY. 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))) - 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))) + (vc-call-backend backend + 'find-ignore-file + (or directory default-directory)))) (if remove - (vc--remove-regexp (concat "^" (regexp-quote pattern ) "\\(\n\\|$\\)") ignore) - (vc--add-line pattern ignore)))) + (vc--remove-regexp (concat "^" (regexp-quote file) "\\(\n\\|$\\)") ignore) + (vc--add-line file ignore)))) (defun vc-default-ignore-completion-table (backend file) "Return the list of ignored files under BACKEND." --------------D2612A5E2B24387BABF1E3D5--