Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Commits on May 23, 2011
  1. @jrn @gitster

    userdiff/perl: tighten BEGIN/END block pattern to reject here-doc del…

    jrn authored gitster committed
    A naive method of treating BEGIN/END blocks with a brace on the second
    line as diff/grep funcname context involves also matching unrelated
    lines that consist of all-caps letters:
    	sub foo {
    		print <<'EOF'
    	text goes here
    		... rest of foo ...
    That's not so great, because it means that "git diff" and "git grep
    --show-function" would write "=EOF" or "@@ EOF" as context instead of
    a more useful reminder like "@@ sub foo {".
    To avoid this, tighten the pattern to only match the special block
    names that perl accepts (namely BEGIN, END, INIT, CHECK, UNITCHECK,
    AUTOLOAD, and DESTROY).  The list is taken from perl's toke.c.
    Suggested-by: Jakub Narebski <>
    Signed-off-by: Jonathan Nieder <>
    Signed-off-by: Junio C Hamano <>
Commits on May 22, 2011
  1. @jrn @gitster

    userdiff/perl: catch sub with brace on second line

    jrn authored gitster committed
    	sub foo
    as an alternative to a more common style that introduces perl
    functions with a brace on the first line (and likewise for BEGIN/END
    blocks).  The new regex is a little hairy to avoid matching
    	# forward declaration
    	sub foo;
    while continuing to match "sub foo($;@) {" and
    	sub foo { # This routine is interesting;
    		# in fact, the lines below explain how...
    While at it, pay attention to Perl 5.14's "package foo {" syntax as an
    alternative to the traditional "package foo;".
    Requested-by: Ævar Arnfjörð Bjarmason <>
    Signed-off-by: Jonathan Nieder <>
    Signed-off-by: Junio C Hamano <>
  2. @jrn @gitster

    userdiff/perl: match full line of POD headers

    jrn authored gitster committed
    The builtin perl userdiff driver is not greedy enough about catching
    POD header lines.  Capture the whole line, so instead of just
    declaring that we are in some "@@ =head1" section, diff/grep output
    can explain that the enclosing section is about "@@ =head1 OPTIONS".
    Reported-by: Ævar Arnfjörð Bjarmason <>
    Signed-off-by: Jonathan Nieder <>
    Signed-off-by: Junio C Hamano <>
  3. @jrn @gitster

    userdiff/perl: anchor "sub" and "package" patterns on the left

    jrn authored gitster committed
    The userdiff funcname mechanism has no concept of nested scopes ---
    instead, "git diff" and "git grep --show-function" simply label the
    diff header with the most recent matching line.  Unfortunately that
    means text following a subroutine in a POD section:
    	=head1 DESCRIPTION
    	You might use this facility like so:
    		sub example {
    	Now, having said that, let's say more about the facility.
    	Blah blah blah ... etc etc.
    gets the subroutine name instead of the POD header in its diff/grep
    funcname header, making it harder to get oriented when reading a
    diff without enough context.
    The fix is simple: anchor the funcname syntax to the left margin so
    nested subroutines and packages like this won't get picked up.  (The
    builtin C++ funcname pattern already does the same thing.)  This means
    the userdiff driver will misparse the idiom
    		my $static;
    		sub foo {
    			... use $static ...
    but I think that's worth it; we can revisit this later if the userdiff
    mechanism learns to keep track of the beginning and end of nested
    Reported-by: Ævar Arnfjörð Bjarmason <>
    Signed-off-by: Jonathan Nieder <>
    Signed-off-by: Junio C Hamano <>
Commits on Jan 18, 2011
  1. @jrn @gitster

    userdiff: simplify word-diff safeguard

    jrn authored gitster committed
    git's diff-words support has a detail that can be a little dangerous:
    any text not matched by a given language's tokenization pattern is
    treated as whitespace and changes in such text would go unnoticed.
    Therefore each of the built-in regexes allows a special token type
    consisting of a single non-whitespace character [^[:space:]].
    To make sure UTF-8 sequences remain human readable, the builtin
    regexes also have a special token type for runs of bytes with the high
    bit set.  In English, non-ASCII characters are usually isolated so
    this is analogous to the [^[:space:]] pattern, except it matches a
    single _multibyte_ character despite use of the C locale.
    Unfortunately it is easy to make typos or forget entirely to include
    these catch-all token types when adding support for new languages (see
    v1.7.3.5~16, userdiff: fix typo in ruby and python word regexes,
    2010-12-18).  Avoid this by including them automatically within the
    PATTERNS and IPATTERN macros.
    While at it, change the UTF-8 sequence token type to match exactly one
    non-ASCII multi-byte character, rather than an arbitrary run of them.
    Suggested-by: Thomas Rast <>
    Signed-off-by: Jonathan Nieder <>
    Signed-off-by: Junio C Hamano <>
Commits on Dec 27, 2010
  1. @jrn @gitster

    diff: funcname and word patterns for perl

    jrn authored gitster committed
    The default function name discovery already works quite well for Perl
    code... with the exception of here-documents (or rather their ending).
     sub foo {
    	print <<END
    	return 1;
    The default funcname pattern treats the unindented END line as a
    function declaration and puts it in the @@ line of diff and "grep
    --show-function" output.
    With a little knowledge of perl syntax, we can do better.  You can
    try it out by adding "*.perl diff=perl" to the gitattributes file.
    Signed-off-by: Jonathan Nieder <>
    Signed-off-by: Junio C Hamano <>
Something went wrong with that request. Please try again.