Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 git-grep path output is often replacing "/" with ":" #1631

Closed
CharlemagneLasse opened this issue Feb 19, 2024 · 1 comment
Closed

Comments

@CharlemagneLasse
Copy link

I wanted to use delta to filter my grep output and then ctrl+click on the filename + line numbers. But I've noticed that the filenames were not displayed correctly and thus the "Open File from Terminal" functionality from KDE konsole was not working.

Simple test case in the OpenWrt repository at commit 3a073a021286bef3fed0ca7884872c5890420d60:

git --no-pager grep -n PKG_CONFIG -- package/network/config/ > raw_git_output

The git-grep raw output is:

package/network/config/firewall/Makefile:22:PKG_CONFIG_DEPENDS := CONFIG_IPV6
package/network/config/ltq-adsl-app/Makefile:23:PKG_CONFIG_DEPENDS:=\

But delta 1.16.5 (linux amd64) is creating following output (just by running git grep -n PKG_CONFIG -- package/network/config/):

package/network/config/firewall/Makefile:22: PKG_CONFIG_DEPENDS := CONFIG_IPV6
package/network/config/ltq:adsl-app/Makefile:23:PKG_CONFIG_DEPENDS:=\

Screenshot_20240219_093831

The error is in the second line because it replaced ltq- with ltq:.

My complete .gitconfig during this test is:

[core]
	pager = delta

But it is also reproducible when using (to work around the tab bug):

[core]
	pager = delta --color-only
@dandavison
Copy link
Owner

Hi @CharlemagneLasse, I'd love someone to improve this but for now I've done my best with this situation. Traditional grep output is not unambiguously parseable: it uses characters as separators that may appear in file names. In my defense,

  1. See the ~500 lines of unit tests here: https://github.com/dandavison/delta/blob/main/src/handlers/grep.rs#L653-L1177. If you can improve the parsing while keeping all those tests passing (and hopefully adding a test for what you're fixing) that would be fantastic.

  2. This is documented in the manual: https://dandavison.github.io/delta/grep.html

    If you don't need special features of git grep, then for best results pipe rg --json output to delta: this avoids parsing ambiguities that are inevitable with the output of git grep and grep.

Personally, I have gone all-in on ripgrep, using rg --json | delta in all my rip grep aliases / shell commands / fzf utilities etc. But I do understand that git grep can do things that rg cannot.

If you don't mind I'm going to close this, since I'm not personally planning more development on it (but would welcome contributions) and it's a dup of #1083 and #1259. But as always please don't interpret a closed issue as discouragement to keep discussing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants