all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Wolfgang Scherer <Wolfgang.Scherer@gmx.de>
To: 37189@debbugs.gnu.org
Subject: bug#37189: 25.4.1: vc-hg-ignore implementation is missing
Date: Thu, 29 Aug 2019 17:52:21 +0200	[thread overview]
Message-ID: <b8d1f5c9-8df1-f090-3c05-83fa821427e2@gmx.de> (raw)
In-Reply-To: <95da41e8-7a55-a15c-cfa7-d70366f9ee6b@gmx.de>

[-- 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-Provide-vc-hg-ignore-to-make-vc-ignore-work-correctl.patch --]
[-- Type: text/x-patch; name="0001-Provide-vc-hg-ignore-to-make-vc-ignore-work-correctl.patch", Size: 3990 bytes --]

From 4fb25acadedc81a6d654bed89e816906aff07178 Mon Sep 17 00:00:00 2001
From: Wolfgang Scherer <wolfgang.scherer@gmx.de>
Date: Thu, 29 Aug 2019 17:49:54 +0200
Subject: [PATCH] Provide vc-hg-ignore to make vc-ignore work correctly

* lisp/vc/vc-hg.el: (vc-hg-ignore) Ignore file of directory.  Add
filepath relative to directory of Mercurial .hgignore file.  The
filepath is quoted according to the active ignore syntax (Bug#37189).
(vc-hg--py-regexp-quote) Quote string as regexp to match exactly
string.
---
 lisp/vc/vc-hg.el | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el
index f287adf..9cbd9d4 100644
--- a/lisp/vc/vc-hg.el
+++ b/lisp/vc/vc-hg.el
@@ -1153,6 +1153,50 @@ REV is ignored."
   (expand-file-name ".hgignore"
 		    (vc-hg-root file)))

+(defvar vc-hg-ignore-detect-wildcard "[*^$]"
+  "Regular expresssion to detect wildcards in an ignored file
+  specification.")
+
+(defun vc-hg-ignore (file &optional directory remove)
+  "Ignore FILE of DIRECTORY (default is `default-directory').
+If FILE matches the regular expression
+`vc-hg-ignore-detect-wildcard', it is appended to .hgignore
+unmodified.
+Otherwise, FILE is either relative to DIRECTORY or absolute. FILE
+is converted to a path relative to the project root of DIRECTORY.
+It is then further escaped/expanded according to the active
+syntax in .hgignore.  If the syntax is `regexp', FILE is quoted
+as anchored literal Python regexp and if FILE is a directory, the
+trailing `$' is omitted.  Otherwise, if the syntax is `glob',
+FILE is used unquoted and if FILE is a directory, a `*' is
+appended.
+If REMOVE is non-nil, remove the pattern derived from FILE from
+ignored files."
+  (let ((ignore (vc-hg-find-ignore-file (or directory default-directory)))
+        (pattern file)
+        root-dir file-path syntax)
+    (unless (string-match vc-hg-ignore-detect-wildcard 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)))
+      (save-match-data
+        (with-current-buffer (find-file-noselect ignore)
+          (goto-char (point-max))
+          (setq syntax
+                (if (re-search-backward "^ *syntax: *\\(regexp\\|glob\\)$" nil t)
+                    (match-string 1)
+                  "regexp")))
+        (setq pattern
+              (if (string= syntax "regexp")
+                  (concat "^" (vc-hg--py-regexp-quote pattern)
+                          (and (not (file-directory-p file-path)) "$"))
+                (concat pattern (and (file-directory-p file-path) "*"))))))
+    (if remove
+        (vc--remove-regexp (concat "^" (regexp-quote pattern ) "\\(\n\\|$\\)") ignore)
+      (vc--add-line pattern ignore))))
+
 ;; Modeled after the similar function in vc-bzr.el
 (defun vc-hg-checkout (file &optional rev)
   "Retrieve a revision of FILE.
@@ -1451,6 +1495,24 @@ This function differs from vc-do-command in that it invokes
 (defun vc-hg-root (file)
   (vc-find-root file ".hg"))

+(defvar vc-hg--py-regexp-special-chars
+  (mapcar
+   (function
+    (lambda (_c)
+      (cons _c (concat "\\" (char-to-string _c)))))
+   (append "()[]{}?*+-|^$\\.&~# \t\n\r\v\f" nil))
+  "Characters that have special meaning in Python regular expressions.")
+
+(defun vc-hg--py-regexp-quote (string)
+  "Return a Python regexp string which matches exactly STRING and nothing else.
+Ported from Python v3.7"
+  (mapconcat
+   (function
+    (lambda (_c)
+      (or (cdr (assq _c vc-hg--py-regexp-special-chars))
+          (char-to-string _c))))
+   string ""))
+
 (provide 'vc-hg)

 ;;; vc-hg.el ends here
--
2.7.4


  reply	other threads:[~2019-08-29 15:52 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-26  0:21 bug#37189: 25.4.1: vc-hg-ignore implementation is missing Wolfgang Scherer
     [not found] ` <handler.37189.B.15667808855126.ack@debbugs.gnu.org>
2019-08-26 23:25   ` bug#37189: Acknowledgement (25.4.1: vc-hg-ignore implementation is missing) Wolfgang Scherer
2019-08-27  7:45     ` Eli Zaretskii
2019-08-28  1:46       ` bug#37189: *** GMX Spamverdacht *** " Wolfgang Scherer
2019-08-28  6:16         ` Eli Zaretskii
2019-08-29  1:23           ` bug#37189: 25.4.1: vc-hg-ignore implementation is missing Wolfgang Scherer
2019-08-29  0:38         ` Wolfgang Scherer
2019-08-29 15:52           ` Wolfgang Scherer [this message]
2019-12-25  0:16             ` Dmitry Gutov
2020-01-05  3:46               ` Wolfgang Scherer
2020-01-05  8:58                 ` Andreas Schwab
2020-01-05 17:25                   ` Wolfgang Scherer
2020-01-14  1:14                 ` Dmitry Gutov
2020-02-01  1:20                   ` Wolfgang Scherer
2020-02-01  8:27                     ` Eli Zaretskii
2020-02-03  1:16                       ` Wolfgang Scherer
2020-02-04 18:55                         ` Eli Zaretskii
2020-02-05  5:18                           ` Wolfgang Scherer
2020-02-05 19:06                           ` Wolfgang Scherer
2020-02-07  9:57                             ` Eli Zaretskii
2020-02-08  9:57                               ` Dmitry Gutov
2020-02-08 19:45                                 ` Wolfgang Scherer
2020-02-08 20:05                                   ` Eli Zaretskii
2020-02-08 23:12                                     ` Wolfgang Scherer
2020-02-09 13:57                                       ` Wolfgang Scherer
2020-02-09 14:07                                         ` Wolfgang Scherer
2020-02-09 13:57                                       ` Wolfgang Scherer
2020-02-09 13:57                                       ` Wolfgang Scherer
2020-02-10 16:02                                         ` Eli Zaretskii
2020-02-11  1:45                                           ` Wolfgang Scherer
2020-02-11 17:32                                             ` Eli Zaretskii
2020-02-11 22:28                                               ` Wolfgang Scherer
2020-02-12 18:34                                                 ` Eli Zaretskii
     [not found]                                                   ` <6f3ba261-e1f9-cf19-cc22-ec8c24cf3298@gmx.de>
2020-02-12 23:20                                                     ` Wolfgang Scherer
2020-02-13  1:18                                                       ` Wolfgang Scherer
2020-02-13 15:09                                                         ` Eli Zaretskii
2020-02-13 16:30                                                           ` Wolfgang Scherer
2020-02-13 23:43                                                           ` Richard Stallman
2020-02-14  1:49                                                             ` Wolfgang Scherer
2020-02-16  2:29                                                               ` Richard Stallman
2020-02-13 15:21                                                         ` Eli Zaretskii
2020-02-13 23:40                                                           ` Dmitry Gutov
2020-02-14  9:23                                                             ` Eli Zaretskii
2020-02-21  0:05                                                               ` Dmitry Gutov
2020-02-21  8:10                                                                 ` Eli Zaretskii
2020-02-21 22:22                                                                 ` Wolfgang Scherer
2020-02-22  7:44                                                                   ` Eli Zaretskii
2020-02-22 13:46                                                                     ` Wolfgang Scherer
2020-02-22 14:30                                                                       ` Eli Zaretskii
2020-02-22 19:14                                                                         ` Dmitry Gutov
2020-02-22 22:04                                                                           ` Wolfgang Scherer
2020-02-22 23:32                                                                         ` Wolfgang Scherer
2020-02-23 15:20                                                                           ` Eli Zaretskii
2020-02-23 19:16                                                                             ` Wolfgang Scherer
2020-02-22 19:30                                                                   ` Dmitry Gutov
2020-02-22 22:00                                                                     ` Wolfgang Scherer
2020-02-22 23:58                                                                       ` Dmitry Gutov
2020-02-23  0:29                                                                         ` Wolfgang Scherer
2020-02-24 23:07                                                                           ` Dmitry Gutov
2020-02-25  2:22                                                                             ` Wolfgang Scherer
2020-03-19 23:42                                                                               ` Dmitry Gutov
2020-07-03 20:53                                                                                 ` Wolfgang Scherer
2020-07-03 21:49                                                                                   ` Dmitry Gutov
2020-02-12 17:23                                               ` Wolfgang Scherer
2020-02-08 23:59                                     ` Wolfgang Scherer
2020-02-09 21:06                               ` Wolfgang Scherer

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

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

  git send-email \
    --in-reply-to=b8d1f5c9-8df1-f090-3c05-83fa821427e2@gmx.de \
    --to=wolfgang.scherer@gmx.de \
    --cc=37189@debbugs.gnu.org \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.