GNU bug report logs - #19944
25.0.50; vc-git-grep doesn't use grep-read-files correctly

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Rupert Swarbrick <ruperts@HIDDEN>; dated Wed, 25 Feb 2015 11:40:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 25 Feb 2015 11:39:53 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Feb 25 06:39:53 2015
Received: from localhost ([127.0.0.1]:57362 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1YQaJk-0003uQ-R7
	for submit <at> debbugs.gnu.org; Wed, 25 Feb 2015 06:39:53 -0500
Received: from eggs.gnu.org ([208.118.235.92]:45127)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <ruperts@HIDDEN>) id 1YQaJi-0003u8-CQ
 for submit <at> debbugs.gnu.org; Wed, 25 Feb 2015 06:39:51 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <ruperts@HIDDEN>) id 1YQaJc-0002dH-1M
 for submit <at> debbugs.gnu.org; Wed, 25 Feb 2015 06:39:45 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled
 version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:52969)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <ruperts@HIDDEN>) id 1YQaJb-0002dC-Ug
 for submit <at> debbugs.gnu.org; Wed, 25 Feb 2015 06:39:43 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:46831)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <ruperts@HIDDEN>) id 1YQaJa-0003c1-Gl
 for bug-gnu-emacs@HIDDEN; Wed, 25 Feb 2015 06:39:43 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <ruperts@HIDDEN>) id 1YQaJX-0002ak-7h
 for bug-gnu-emacs@HIDDEN; Wed, 25 Feb 2015 06:39:42 -0500
Received: from mail-gw1-out.broadcom.com ([216.31.210.62]:11420)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <ruperts@HIDDEN>) id 1YQaJW-0002aM-Ux
 for bug-gnu-emacs@HIDDEN; Wed, 25 Feb 2015 06:39:39 -0500
X-IronPort-AV: E=Sophos;i="5.09,644,1418112000"; d="scan'208";a="58123883"
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
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
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
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 <bug-gnu-emacs@HIDDEN>; Wed, 25 Feb 2015 03:38:16 -0800 (PST)
Received: by xl-cam-20.broadcom.com (Postfix, from userid 35990)	id
 F0AEC180712; Wed, 25 Feb 2015 11:39:23 +0000 (GMT)
From: Rupert Swarbrick <ruperts@HIDDEN>
To: <bug-gnu-emacs@HIDDEN>
Subject: 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@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
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-Received-From: 2001:4830:134:3::11
X-Spam-Score: -5.0 (-----)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -5.0 (-----)

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 <blah blah> | grep <blah blah>

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]




Acknowledgement sent to Rupert Swarbrick <ruperts@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#19944; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Wed, 25 Feb 2015 11:45:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.