In blame.c
::cmd_blame, we send the 'path' field of the 'sb
' 'struct blame_scoreboard
' as the 'path
' argument to 'line-range.c::parse_range_arg
', but 'sb.path
' is not set yet; it's set to the local variable 'path
' a few lines later at line 1137.
This 'path
' argument is only used in 'parse_range_arg
' if we are blaming a funcname, i.e. git blame -L :<funcname> <path>
(man), and in that case it is sent to 'parse_range_funcname
', where it is used to determine if a userdiff
driver should be used for said <path>
to match the given funcname.
Since 'path
' is yet unset, the userdiff driver is never used, so we fall back to the default funcname regex, which is usually not appropriate for paths that are set to use a specific userdiff driver, and thus either we match some unrelated lines, or we die with
fatal: -L parameter '<funcname>' starting at line 1: no match
This has been the case ever since git blame
(man) learned to blame a funcname
in 13b8f68c1f ("log -L
: :pattern:file
syntax to find by funcname
", 2013-03-28, Git v1.8.4-rc0 -- merge).
Enable funcname blaming for paths using specific userdiff drivers by initializing 'sb.path
' earlier in 'cmd_blame
', when some of its other fields are initialized, so that it is set when passed to 'parse_range_arg
'.
git version 2.35.1
中,如果您正在寻找一个 C++ 类的成员函数,并且您想要做合理的事情,即像这样完全限定函数名称以及类名称:git blame -L :SomeClass::SomeMemberFunction -- ./some_source_file.cpp
,它返回一个使用错误。[续] - bgoodrSomeClass::
限定符:git blame -L :SomeMemberFunction -- ./some_source_file.cpp
。在我看来,这可能会浪费时间:如果不幸的是,您正在研究在同一源文件中定义了两个或更多类,每个类都包含SomeMemberFunction
的定义,那么Git将选择分析哪个类的成员函数呢? - bgoodr-L“:SomeClass :: SomeMemberFunction”
? - VonC