From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Rupert Swarbrick Newsgroups: gmane.emacs.bugs Subject: bug#19944: 25.0.50; vc-git-grep doesn't use grep-read-files correctly Date: Wed, 25 Feb 2015 11:39:23 +0000 Message-ID: <889lhjmb4pg.fsf@broadcom.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1424864475 2463 80.91.229.3 (25 Feb 2015 11:41:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 25 Feb 2015 11:41:15 +0000 (UTC) To: 19944@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Feb 25 12:41:02 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YQaKs-0003wC-4z for geb-bug-gnu-emacs@m.gmane.org; Wed, 25 Feb 2015 12:41:02 +0100 Original-Received: from localhost ([::1]:53821 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQaKr-00068C-H3 for geb-bug-gnu-emacs@m.gmane.org; Wed, 25 Feb 2015 06:41:01 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47019) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQaK1-0004ZZ-EW for bug-gnu-emacs@gnu.org; Wed, 25 Feb 2015 06:40:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YQaJv-0002mb-EK for bug-gnu-emacs@gnu.org; Wed, 25 Feb 2015 06:40:09 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:53764) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQaJv-0002m9-8A for bug-gnu-emacs@gnu.org; Wed, 25 Feb 2015 06:40:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YQaJu-0003ux-M7 for bug-gnu-emacs@gnu.org; Wed, 25 Feb 2015 06:40:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Rupert Swarbrick Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 25 Feb 2015 11:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 19944 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: Original-Received: via spool by submit@debbugs.gnu.org id=B.142486439315034 (code B ref -1); Wed, 25 Feb 2015 11:40:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 25 Feb 2015 11:39:53 +0000 Original-Received: from localhost ([127.0.0.1]:57362 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YQaJk-0003uQ-R7 for submit@debbugs.gnu.org; Wed, 25 Feb 2015 06:39:53 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:45127) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YQaJi-0003u8-CQ for submit@debbugs.gnu.org; Wed, 25 Feb 2015 06:39:51 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YQaJc-0002dH-1M for submit@debbugs.gnu.org; Wed, 25 Feb 2015 06:39:45 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:52969) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQaJb-0002dC-Ug for submit@debbugs.gnu.org; Wed, 25 Feb 2015 06:39:43 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46831) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQaJa-0003c1-Gl for bug-gnu-emacs@gnu.org; Wed, 25 Feb 2015 06:39:43 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YQaJX-0002ak-7h for bug-gnu-emacs@gnu.org; Wed, 25 Feb 2015 06:39:42 -0500 Original-Received: from mail-gw1-out.broadcom.com ([216.31.210.62]:11420) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQaJW-0002aM-Ux for bug-gnu-emacs@gnu.org; Wed, 25 Feb 2015 06:39:39 -0500 X-IronPort-AV: E=Sophos;i="5.09,644,1418112000"; d="scan'208";a="58123883" Original-Received: from irvexchcas08.broadcom.com (HELO IRVEXCHCAS08.corp.ad.broadcom.com) ([10.9.208.57]) by mail-gw1-out.broadcom.com with ESMTP; 25 Feb 2015 06:09:10 -0800 Original-Received: from IRVEXCHSMTP2.corp.ad.broadcom.com (10.9.207.52) by IRVEXCHCAS08.corp.ad.broadcom.com (10.9.208.57) with Microsoft SMTP Server (TLS) id 14.3.174.1; Wed, 25 Feb 2015 03:39:25 -0800 Original-Received: from mail-irva-13.broadcom.com (10.10.10.20) by IRVEXCHSMTP2.corp.ad.broadcom.com (10.9.207.52) with Microsoft SMTP Server id 14.3.174.1; Wed, 25 Feb 2015 03:39:24 -0800 Original-Received: from xl-cam-20.broadcom.com (xl-cam-20.cam.broadcom.com [10.177.132.80]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id 4FE0540FE8 for ; Wed, 25 Feb 2015 03:38:16 -0800 (PST) Original-Received: by xl-cam-20.broadcom.com (Postfix, from userid 35990) id F0AEC180712; Wed, 25 Feb 2015 11:39:23 +0000 (GMT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.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.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:99795 Archived-At: The vc-git-grep function uses grep-read-files to figure out the list of files to check. This gets glued to the end of the git grep command line. With the default value of grep-files-aliases, if the user enters "all" for their files, grep-read-files returns the string "* .*". If you do the following: cd /path/to/my/git/repo git grep foo -- * .* then you get something like: /path/to/my/git/repo> git grep foo -- * .* fatal: ..: '..' is outside repository because .* expands to a list including "..". Now, the code in vc-git-grep constructs a string that looks basically like the above. If you run vc-git-grep in the top-level directory of a git repository and select "all" for file type then it errors out because of this problem. I did wonder whether this was a bug in grep.el, but it isn't: grep-read-files seems to be used only in "grep" and "lgrep", which construct commands like grep -nH foo * .* Since the grep invocation is non-recursive, this isn't a problem. If you run rgrep, it generates something more like find -name | grep and doesn't seem to use grep-read-files at all. We're also doing the wrong thing when the user gives a pattern. For example, if I go into the top-level Emacs directory and run M-x vc-git-grep enter vc-git-grep as the string to search for and enter *g* for the files to search, then I get: Grep started at Wed Feb 25 11:17:28 git --no-pager grep -n -e vc-git-grep -- *g* Grep finished with no matches found at Wed Feb 25 11:17:28 If I type '*g*' instead, I get: git --no-pager grep -n -e vc-git-grep -- '*g*' lisp/ChangeLog:16437: * vc/vc-git.el (vc-git-grep): Disable pager. lisp/ChangeLog.14:16592: (vc-git-extra-menu, vc-git-extra-status-menu, vc-git-grep): lisp/ChangeLog.16:18483: * vc/vc-git.el (vc-git-grep): Remove --no-color. (Bug#9408) lisp/ChangeLog.16:18484: (vc-git-grep): Prepend "PAGER=" to `compilation-environment' lisp/ChangeLog.16:18662: * vc/vc-git.el (vc-git-grep): Use --no-color. (Bug#9408) lisp/vc/vc-git.el:1124: '(menu-item "Git grep..." vc-git-grep lisp/vc/vc-git.el:1152:(defun vc-git-grep (regexp &optional files dir) Grep finished (matches found) at Wed Feb 25 11:18:17 (The strange looking pattern is so that there would be a match for the shell glob in the top level directory to make sure it got expanded: if I'd typed *.el, things would have worked as expected because there are no elisp files in the top-level Emacs directory) One possible fix is to write a vc-git-grep-read-files function that behaves very similarly to grep-read-files, but overrides some of the mapping with a vc-git-grep-files-aliases variable. That should be an alist that contains at least '("all" . "") by default. If it successfully looked up something in the dictionary, the function would then split on spaces and then shell quote each resulting word. If the result isn't from a dictionary lookup, an easy approach is to do the same thing: split on spaces and then quote. This lets the user enter something like *.c *.h and have the right thing happen. It doesn't allow the user to enter 'with a space.*' but maybe we don't care. Rupert In GNU Emacs 25.0.50.1 (x86_64-unknown-linux-gnu, X toolkit, Xaw scroll bars) of 2015-02-09 on lc-cam-077 Repository revision: 2f7008715326a49770fcb82003ed78eab28c0626 Windowing system distributor `The X.Org Foundation', version 11.0.11300000 System Description: Red Hat Enterprise Linux Server release 6.4 (Santiago) Configured using: `configure --prefix=/snipped/ --with-xml2 --without-sound --without-rsvg --without-imagemagick --with-x-toolkit=lucid' Configured features: XPM JPEG TIFF GIF PNG GPM DBUS GCONF NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE XFT ZLIB [Rest snipped: it's not relevant to this bug report]