1

I've been trying to find instances of the t() function in source code on the dev branch using git. Came up with the following line

git branch -a | tr -d \* | sed '/->/d' | xargs git grep -E -e "/(t\(\').*\'\)/sU" 

Here the search is done on all branches, but still I get no results from the query. Simple search queries ( git grep "t('" ) work perfectly fine, but is not usable for this purpose. ExtendedRexp is enabled from git config.

Anybody had similar issues?

7
  • why xargs git grep, shouldn't it be just xargs grep ? Commented Apr 10, 2018 at 15:29
  • git grep is used to search for tracked files in the GitHub repository. Commented Apr 10, 2018 at 15:57
  • The syntax of the regular expression /…/sU is strange, it seems you confuse grep and sed. What exactly you're trying to search? What the "flags" sU are supposed to do? Commented Apr 10, 2018 at 16:28
  • 2
    U is a PHP/PCRE modifier that switches greediness. grep with POSIX ERE does not support lazy/possessive quantifiers, it only supprots greedy ones. s is a modifier that does not work with grep since grep works on a per line basis, and s modifier makes a . in a PCRE regex match line break chars that it does not match by default. Commented Apr 10, 2018 at 16:36
  • Are you looking for commits where calls to the function were added, change, or deleted historically or instances in the head of each branch? Commented Apr 10, 2018 at 18:15

1 Answer 1

1

Escaping the single quotes in the regular expression should not be necessary. Also, to avoid matching other functions that end with a 't', such as get, you can use \W which will match any non non-word character.

git branch -a | tr -d \* | sed '/->/d' | xargs git grep -E -e "\Wt\('.*'\)" 

If you want to capture a group within the matching result, then you can add additional parentheses. For example:

Rubular example

Sign up to request clarification or add additional context in comments.

4 Comments

Yes that is definitely a better regex for finding the t function!. Still no results from the git grep though :/
If you are still not seeing results, then I would recommend making the regex less restrictive. Note that this will currently only match if the arguments to t are passed as literals with single quotes. You can see this in my example test strings.
Regex works as expected while running on example strings. I think the problem is with the usage of git grep.
I verified that it worked with git grep by putting a t in one of my git checkouts. It could be a git configuration issue.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.