vc-git.el vc-git-grep does not work with git 1.9 in trusty

Bug #1315551 reported by Jason Gunthorpe
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
emacs23 (Ubuntu)
New
Undecided
Unassigned

Bug Description

For emacs to properly parse the result of git grep it must not be fed through a pager (like less) and it must not include colourization escape codes.

If a pager is spawned, it might blow up with this:

git grep -n -e ClkIB -- *
WARNING: terminal is not fully functional
- (press RETURN)

If colourization is turned on then the output from git no longer matches the grep filename regex. For instance grepping for 'COPYRIGHT' gives colourized lines like this:

Makefile.[36m:.[m2.[36m:.[m# .[1;31mCOPYRIGHT.[m (c) 2011-2012 O

(where [ is the ESC). Git has colour'd the : characters as well as the matching string. The standard emacs grep regex is not prepared to handle the escape characters.

Within vc-git.el/vc-git-grep, setting the environment PAGER="" used to be enough:

      (when command
        (let ((default-directory dir)
              (compilation-environment '("PAGER=")))
          ;; Setting process-setup-function makes exit-message-function work
          ;; even when async processes aren't supported.
          (compilation-start command 'grep-mode))

But for whatever reason with git 1.9 this still spawns a pager.

Updating to GIT_PAGER="" does not spawn a pager, but still colourizes the output.

The only fix I can find would be to replace:

              (grep-expand-template "git grep -n -e <R> -- <F>" regexp files))

with:

              (grep-expand-template "git --no-pager grep --no-color -n -e <R> -- <F>" regexp files))

This restores the behaviour older git's had with PAGER="" and allows emacs to properly parse the result.

However, I would expect that it won't be compatible with older gits.

Since Ubuntu does not ship older gits it seems reasonable to patch vc-git.el and let upstream figure out how to make this generic.

emacs23-el:
  Installed: 23.4+1-4.1ubuntu1
  Candidate: 23.4+1-4.1ubuntu1
  Version table:
 *** 23.4+1-4.1ubuntu1 0

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.