Live data from Hacker News

See the History of a Method with Git log -L

calebhearth.com

1–10 of 26 posts

Re: See the History of a Method with Git log -L

#6

How can this be uses with PHP?

It's just a regex to match the line you want to see the history of. Function would be a common case, but it's completely arbitrary.

For example, `git log -L:members:Cargo.toml` will show the history of constituent rust projects in a Cargo workspace.

Re: See the History of a Method with Git log -L

#7
post #6

How can this be uses with PHP?

It's just a regex to match the line you want to see the history of. Function would be a common case, but it's completely arbitrary. For example, `git log -L:members:Cargo.toml` will show the history of constituent rust projects in a Cargo workspace.

It's a regex? Is it even guaranteed to work then? I would think you have to parse non-regular languages to always find the end of a function in a some languages?

Indeed, it does not always work correctly for Julia, as an arbitrary example I tried. Seems like it goes by indentation? Still nice though and worked out of the box!

Re: See the History of a Method with Git log -L

#9
If you're curious how Git knows the syntax of different languages in order to support this kind of feature, take a look in https://github.com/git/git/blob/master/userdiff.c

Here's how support for Python and Ruby are defined:

    PATTERNS("python",
        "^[ \t]*((class|(async[ \t]+)?def)[ \t].*)$",
        /* -- */
        "[a-zA-Z_][a-zA-Z0-9_]*"
        "|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?"
        "|[-+*/%&^|=!]=|//=?|>=?|\\*\\*=?"),
        /* -- */
    PATTERNS("ruby",
        "^[ \t]*((class|module|def)[ \t].*)$",
        /* -- */
        "(@|@@|\\$)?[a-zA-Z_][a-zA-Z0-9_]*"
        "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?."
        "|//=?|[-+*/%&^|=!]=|>=?|===|\\.{1,3}|::|[!=]~"),

Re: See the History of a Method with Git log -L

#10
post #7
post #6

Earlier quoted context omitted.

It's just a regex to match the line you want to see the history of. Function would be a common case, but it's completely arbitrary. For example, `git log -L:members:Cargo.toml` will show the history of constituent rust projects in a Cargo workspace.

It's a regex? Is it even guaranteed to work then? I would think you have to parse non-regular languages to always find the end of a function in a some languages? Indeed, it does not always work correctly for Julia, as an arbitrary example I tried. Seems like it goes by indentation? Still nice though and worked out of the box!

There's a comment about that here: https://github.com/git/git/blob/bc5204569f7db44d22477485afd5...

    When writing or updating patterns, assume that the contents these
    patterns are applied to are syntactically correct.  The patterns
    can be simple without implementing all syntactical corner cases, as
    long as they are sufficiently permissive.
Post reply on HN