git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Bug Report] git log -L:<funcname>:<file>
@ 2021-05-20  0:11 Weishi Zeng
  2021-05-20  3:18 ` Bagas Sanjaya
  2021-05-20  7:05 ` Atharva Raykar
  0 siblings, 2 replies; 4+ messages in thread
From: Weishi Zeng @ 2021-05-20  0:11 UTC (permalink / raw)
  To: git

Summary:
git log -L:<funcname>:<file>
would fail if there's any java-style comment that appears before the
<funcname> string in the file.


Details:
Thank you for filling out a Git bug report!
Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)
git log -L:'myFunction':~/a.java
The file is a java file that contains comment before the function name.
E.g.
/**
* comments will interrupt the regex match
*/
private static void myFunction() {}

What did you expect to happen? (Expected behavior)
As described, it should return me the commit history that touched this function

What happened instead? (Actual behavior)
It returns error:
fatal: -L parameter 'myFunction' starting at line 1: no match

Anything else you want to add:
If the function name string to search for appears before any
java-style comment, it returns a valid response.

Please review the rest of the bug report below.
You can delete any lines you don't wish to share.


[System Info]
git version:
git version 2.30.1 (Apple Git-130)
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Darwin 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47
PDT 2021; root:xnu-7195.101.2~1/RELEASE_X86_64 x86_64
compiler info: clang: 12.0.5 (clang-1205.0.22.6)
libc info: no libc information available
$SHELL (typically, interactive shell): /bin/zsh


[Enabled Hooks]
post-commit
post-rewrite

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Bug Report] git log -L:<funcname>:<file>
  2021-05-20  0:11 [Bug Report] git log -L:<funcname>:<file> Weishi Zeng
@ 2021-05-20  3:18 ` Bagas Sanjaya
  2021-05-20  6:45   ` Weishi Zeng
  2021-05-20  7:05 ` Atharva Raykar
  1 sibling, 1 reply; 4+ messages in thread
From: Bagas Sanjaya @ 2021-05-20  3:18 UTC (permalink / raw)
  To: Weishi Zeng, git

Hi Weishi,

On 20/05/21 07.11, Weishi Zeng wrote:
> Summary:
> git log -L:<funcname>:<file>
> would fail if there's any java-style comment that appears before the
> <funcname> string in the file.
> 
> 
> Details:
> Thank you for filling out a Git bug report!
> Please answer the following questions to help us understand your issue.
> 
> What did you do before the bug happened? (Steps to reproduce your issue)
> git log -L:'myFunction':~/a.java
> The file is a java file that contains comment before the function name.
> E.g.
> /**
> * comments will interrupt the regex match
> */
> private static void myFunction() {}
> 
> What did you expect to happen? (Expected behavior)
> As described, it should return me the commit history that touched this function
> 
> What happened instead? (Actual behavior)
> It returns error:
> fatal: -L parameter 'myFunction' starting at line 1: no match
> 
> Anything else you want to add:
> If the function name string to search for appears before any
> java-style comment, it returns a valid response.
> 

I can't reproduce this issue on my system (Ubuntu 20.04) using latest Git
(2.32.0-rc0), compiled with gcc 9.3.0.

Please compile latest Git on your system, repeat and report.

-- 
An old man doll... just what I always wanted! - Clara

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Bug Report] git log -L:<funcname>:<file>
  2021-05-20  3:18 ` Bagas Sanjaya
@ 2021-05-20  6:45   ` Weishi Zeng
  0 siblings, 0 replies; 4+ messages in thread
From: Weishi Zeng @ 2021-05-20  6:45 UTC (permalink / raw)
  To: Bagas Sanjaya; +Cc: git

Thanks Bagas.
Looking at it further the problem seems to be with the leading space/tab.
Here's a single line I can reproduce in the latest version.
===
    private static Optional<String> myFunction(String a) {}
===
It works if you delete the 2 leading tab. (same for 4 leading space)
Command executed:
git log -L:'myFunction':~/a.java

On Wed, May 19, 2021 at 8:18 PM Bagas Sanjaya <bagasdotme@gmail.com> wrote:
>
> Hi Weishi,
>
> On 20/05/21 07.11, Weishi Zeng wrote:
> > Summary:
> > git log -L:<funcname>:<file>
> > would fail if there's any java-style comment that appears before the
> > <funcname> string in the file.
> >
> >
> > Details:
> > Thank you for filling out a Git bug report!
> > Please answer the following questions to help us understand your issue.
> >
> > What did you do before the bug happened? (Steps to reproduce your issue)
> > git log -L:'myFunction':~/a.java
> > The file is a java file that contains comment before the function name.
> > E.g.
> > /**
> > * comments will interrupt the regex match
> > */
> > private static void myFunction() {}
> >
> > What did you expect to happen? (Expected behavior)
> > As described, it should return me the commit history that touched this function
> >
> > What happened instead? (Actual behavior)
> > It returns error:
> > fatal: -L parameter 'myFunction' starting at line 1: no match
> >
> > Anything else you want to add:
> > If the function name string to search for appears before any
> > java-style comment, it returns a valid response.
> >
>
> I can't reproduce this issue on my system (Ubuntu 20.04) using latest Git
> (2.32.0-rc0), compiled with gcc 9.3.0.
>
> Please compile latest Git on your system, repeat and report.
>
> --
> An old man doll... just what I always wanted! - Clara

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Bug Report] git log -L:<funcname>:<file>
  2021-05-20  0:11 [Bug Report] git log -L:<funcname>:<file> Weishi Zeng
  2021-05-20  3:18 ` Bagas Sanjaya
@ 2021-05-20  7:05 ` Atharva Raykar
  1 sibling, 0 replies; 4+ messages in thread
From: Atharva Raykar @ 2021-05-20  7:05 UTC (permalink / raw)
  To: Weishi Zeng; +Cc: git

On 20-May-2021, at 05:41, Weishi Zeng <amwish.zeng@gmail.com> wrote:
> 
> Summary:
> git log -L:<funcname>:<file>
> would fail if there's any java-style comment that appears before the
> <funcname> string in the file.
> 
> 
> Details:
> Thank you for filling out a Git bug report!
> Please answer the following questions to help us understand your issue.
> 
> What did you do before the bug happened? (Steps to reproduce your issue)
> git log -L:'myFunction':~/a.java
> The file is a java file that contains comment before the function name.
> E.g.
> /**
> * comments will interrupt the regex match
> */
> private static void myFunction() {}

I was able to reproduce a similar problem, but it was not the comments
that were causing it. It was happening to methods that were indented
(ie, defined within a class, as is always the case in Java).

> What did you expect to happen? (Expected behavior)
> As described, it should return me the commit history that touched this function
> 
> What happened instead? (Actual behavior)
> It returns error:
> fatal: -L parameter 'myFunction' starting at line 1: no match

Can you try adding a .gitattributes file at the root of your repository,
with the following contents:

*.java diff=java

After that, try running the command again, and see if that helps.

I suspect the default regex that tries to locate your function might not
be matching as well as it should, and does not handle indented function
definitions properly.

(More on what the .gitattributes file does:
https://git-scm.com/docs/gitattributes#_defining_a_custom_hunk_header)

> Anything else you want to add:
> If the function name string to search for appears before any
> java-style comment, it returns a valid response.
> 
> Please review the rest of the bug report below.
> You can delete any lines you don't wish to share.
> 
> 
> [System Info]
> git version:
> git version 2.30.1 (Apple Git-130)
> cpu: x86_64
> no commit associated with this build
> sizeof-long: 8
> sizeof-size_t: 8
> shell-path: /bin/sh
> uname: Darwin 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47
> PDT 2021; root:xnu-7195.101.2~1/RELEASE_X86_64 x86_64
> compiler info: clang: 12.0.5 (clang-1205.0.22.6)
> libc info: no libc information available
> $SHELL (typically, interactive shell): /bin/zsh
> 
> 
> [Enabled Hooks]
> post-commit
> post-rewrite

--
Atharva Raykar

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-05-20  7:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-20  0:11 [Bug Report] git log -L:<funcname>:<file> Weishi Zeng
2021-05-20  3:18 ` Bagas Sanjaya
2021-05-20  6:45   ` Weishi Zeng
2021-05-20  7:05 ` Atharva Raykar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).