From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id AD48B1F55B for ; Wed, 27 May 2020 22:48:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725747AbgE0Ws0 (ORCPT ); Wed, 27 May 2020 18:48:26 -0400 Received: from cloud.peff.net ([104.130.231.41]:58234 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725267AbgE0Ws0 (ORCPT ); Wed, 27 May 2020 18:48:26 -0400 Received: (qmail 24555 invoked by uid 109); 27 May 2020 22:48:26 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Wed, 27 May 2020 22:48:26 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 9043 invoked by uid 111); 27 May 2020 22:48:25 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Wed, 27 May 2020 18:48:25 -0400 Authentication-Results: peff.net; auth=none Date: Wed, 27 May 2020 18:48:24 -0400 From: Jeff King To: Zach Riggle Cc: git@vger.kernel.org Subject: Re: git grep --show-function treats GOTO labels as function names Message-ID: <20200527224824.GA546534@coredump.intra.peff.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Wed, May 27, 2020 at 05:29:08PM -0500, Zach Riggle wrote: > It looks like there is an issue with how the parser handles "goto" > labels, as it treats them the same as a function name. By default, the function-finding isn't aware of the specific content in the file. But you can associate extensions with particular types, like: $ echo '*.cpp diff=cpp' >~/.gitattributes $ git config --global core.attributesFile ~/.gitattributes $ git grep --no-index --show-function -e FOO test2.cpp test2.cpp=int main() { test2.cpp: FOO test2.cpp: FOO Usually this is done in-repo, but since your example used --no-index, I showed how to set up a per-user attribute file. The "diff" attribute covers both diff and grep (for diff, the hunk headers will also show the function). The "cpp" diff regexes are built-in to the git binary. We just don't associate any filenames by default. You can also add your own; see the section "Defining a custom hunk-header" from "git help attributes". -Peff