From: Dmitry Gutov Date: Mon, 7 Jun 2021 01:52:30 +0000 (+0300) Subject: Support old BSD find and "root dir symlink" better X-Git-Tag: emacs-28.0.90~2174 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=45bdc37c8127142504f5f93bcb1327a635f6da1b;p=emacs.git Support old BSD find and "root dir symlink" better * lisp/progmodes/grep.el (grep-compute-defaults): Add '-H' to grep-find-template (bug#48471). * lisp/cedet/semantic/symref/grep.el (semantic-symref-perform-search): Pass the root directory name without the trailing slash. * lisp/progmodes/xref.el (xref-matches-in-directory): Ditto. * test/lisp/progmodes/xref-tests.el (xref--xref-file-name-display-is-abs) (xref--xref-file-name-display-is-relative-to-project-root): Make tests more strict again. --- diff --git a/lisp/cedet/semantic/symref/grep.el b/lisp/cedet/semantic/symref/grep.el index 46027f1f91e..180d779a780 100644 --- a/lisp/cedet/semantic/symref/grep.el +++ b/lisp/cedet/semantic/symref/grep.el @@ -168,7 +168,7 @@ This shell should support pipe redirect syntax." (erase-buffer) (setq default-directory rootdir) (let ((cmd (semantic-symref-grep-use-template - (file-name-as-directory (file-local-name rootdir)) + (directory-file-name (file-local-name rootdir)) filepattern grepflags greppat))) (process-file semantic-symref-grep-shell nil b nil shell-command-switch cmd))) diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index 80c3e7840f0..8647c7089d5 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el @@ -774,25 +774,24 @@ The value depends on `grep-command', `grep-template', (let ((gcmd (format "%s %s " grep-program grep-options)) (null (if grep-use-null-device - (format "%s " (null-device)) - ""))) - (cond ((eq grep-find-use-xargs 'gnu) - (format "%s -type f -print0 | \"%s\" -0 %s" - find-program xargs-program gcmd)) - ((eq grep-find-use-xargs 'gnu-sort) - (format "%s -type f -print0 | sort -z | \"%s\" -0 %s" - find-program xargs-program gcmd)) - ((eq grep-find-use-xargs 'exec) - (format "%s -type f -exec %s %s %s%s" - find-program gcmd quot-braces null quot-scolon)) - ((eq grep-find-use-xargs 'exec-plus) - (format "%s -type f -exec %s %s%s +" - find-program gcmd null quot-braces)) - (t - (format "%s -type f -print | \"%s\" %s" - find-program xargs-program gcmd)))))))) - - ;; Save defaults for this host. + (format "%s " (null-device)) + ""))) + (cond ((eq grep-find-use-xargs 'gnu) + (format "%s -H -type f -print0 | \"%s\" -0 %s" + find-program xargs-program gcmd)) + ((eq grep-find-use-xargs 'gnu-sort) + (format "%s -H -type f -print0 | sort -z | \"%s\" -0 %s" + find-program xargs-program gcmd)) + ((eq grep-find-use-xargs 'exec) + (format "%s -H -type f -exec %s %s %s%s" + find-program gcmd quot-braces null quot-scolon)) + ((eq grep-find-use-xargs 'exec-plus) + (format "%s -H -type f -exec %s %s%s +" + find-program gcmd null quot-braces)) + (t + (format "%s -H -type f -print | \"%s\" %s" + find-program xargs-program gcmd)))))))) + ;; Save defaults for this host. (setq grep-host-defaults-alist (delete (assq host-id grep-host-defaults-alist) grep-host-defaults-alist)) diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index d307c31df8b..b7a926f82e0 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -1464,7 +1464,7 @@ IGNORES is a list of glob patterns for files to ignore." ;; do that reliably enough, without creating false negatives? (command (xref--rgrep-command (xref--regexp-to-extended regexp) files - (file-name-as-directory + (directory-file-name (file-name-unquote (file-local-name (expand-file-name dir)))) ignores)) diff --git a/test/lisp/progmodes/xref-tests.el b/test/lisp/progmodes/xref-tests.el index 66099dc110c..d29452243b2 100644 --- a/test/lisp/progmodes/xref-tests.el +++ b/test/lisp/progmodes/xref-tests.el @@ -117,18 +117,14 @@ (should (null (marker-position (cdr (nth 0 (cdr cons2)))))))) (ert-deftest xref--xref-file-name-display-is-abs () - (let* ((xref-file-name-display 'abs) - ;; Some older BSD find versions can produce '//' in the output. - (expected (list - (concat xref-tests--data-dir "/?file1.txt") - (concat xref-tests--data-dir "/?file2.txt"))) - (actual (delete-dups - (mapcar 'xref-location-group - (xref-tests--locations-in-data-dir "\\(bar\\|foo\\)"))))) - (should (= (length expected) (length actual))) - (should (cl-every (lambda (e1 e2) - (string-match-p e1 e2)) - expected actual)))) + (let ((xref-file-name-display 'abs)) + (should (equal + (delete-dups + (mapcar 'xref-location-group + (xref-tests--locations-in-data-dir "\\(bar\\|foo\\)"))) + (list + (concat xref-tests--data-dir "file1.txt") + (concat xref-tests--data-dir "file2.txt")))))) (ert-deftest xref--xref-file-name-display-is-nondirectory () (let ((xref-file-name-display 'nondirectory)) @@ -144,17 +140,13 @@ (file-name-directory (directory-file-name xref-tests--data-dir))) (project-find-functions (lambda (_) (cons 'transient data-parent-dir))) - (xref-file-name-display 'project-relative) - ;; Some older BSD find versions can produce '//' in the output. - (expected (list - "xref-resources//?file1.txt" - "xref-resources//?file2.txt")) - (actual (delete-dups - (mapcar 'xref-location-group - (xref-tests--locations-in-data-dir "\\(bar\\|foo\\)"))))) - (should (and (= (length expected) (length actual)) - (cl-every (lambda (e1 e2) - (string-match-p e1 e2)) - expected actual))))) + (xref-file-name-display 'project-relative)) + (should (equal + (delete-dups + (mapcar 'xref-location-group + (xref-tests--locations-in-data-dir "\\(bar\\|foo\\)"))) + (list + "xref-resources/file1.txt" + "xref-resources/file2.txt"))))) ;;; xref-tests.el ends here