git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	git@vger.kernel.org, Jakub Narebski <jnareb@gmail.com>,
	Jeff King <peff@peff.net>
Subject: [PATCH 0/7] Re: Problems with Git's "perl" userdiff driver
Date: Sat, 21 May 2011 13:53:14 -0500	[thread overview]
Message-ID: <20110521185314.GA10530@elie> (raw)
In-Reply-To: <BANLkTi=OXznTspN-CJjM0YXfqARxL=J+Ow@mail.gmail.com>

Hi Ævar,

Ævar Arnfjörð Bjarmason wrote:

> The POD rule doesn't work properly. I suspect it has to be:

Thanks.  Some context is here (thanks to Thomas for his notes/full
branch).

 http://thread.gmane.org/gmane.comp.version-control.git/164184

Quick thoughts before fixing them:

>     "^=head[0-9] .*",
>
> Instead of the current:
>
>     "^=head[0-9] ",

Good catch.

> And actually it applies very badly to POD in general, since the "sub"
> rule will be tried first, so e.g. in Perldoc we'll often end up
> finding some "sub" example halfway up the file, instead of the =head1*
> or =item* section a few lines up.

I have another worry of the same kind.  If my source file consists of
multiple packages (like git-svn.perl does), then the "package" rule
can be useful for getting bearings in a diff:

	diff --git a/git-svn.perl b/git-svn.perl
	index dc66803..74d8612 100755
	--- a/git-svn.perl
	+++ b/git-svn.perl
	@@ -4000,7 +4000,6 @@ package SVN::Git::Fetcher;
	 use strict;
	 use warnings;
	 use Carp qw/croak/;
	-use File::Temp qw/tempfile/;
	 use IO::File qw//;
	 use vars qw/$_ignore_regex/;

But as soon as "git diff" encounters a subroutine, that replaces the
context.  It seems that the --show-function mechanism works best for
files structured such that every line has a scope, with no nesting:

	sub foo {
		... lines of foo come here ...
	}

	sub bar {
		... lines of bar come here ...
	}

and does not cope as well with nested scopes or lines that do not
fall in any scope.

The upshot is that all these patterns should be anchored at the left
margin for now, and it might be worth considering teaching userdiff to
push and pop scopes so that lines outside the innermost scope are
correctly attributed, as in the last two lines below:

	package Foo::Bar::Baz

	=head1 NAME

	Foo::Bar::Baz - well-documented frobber

	=cut

	use strict;
	use Qux::Quux;

That would also take care of your example of

	=item B<something>

	Use it like so:

		sub example {
			something else;
		}

	... more documentation that should be attributed to the =item,
	not the sub ...

> And it looks like the regex only catches:
>
>     sub foo {
>     }
>
> Not:
>
>     sub foo
>     {
>     }

Yep, that seems worth fixing, too.  Patches follow, with a few unrelated
cleanups thrown in.  These patches are based against "maint" for no
particular reason.  Bugs and improvements welcome, of course. :)

Jonathan Nieder (7):
  t4018 (diff funcname patterns): make .gitattributes state easier to
    track
  t4018 (diff funcname patterns): make configuration easier to track
  t4018 (diff funcname patterns): minor tweaks
  userdiff/perl: anchor "sub" and "package" patterns on the left
  userdiff/perl: match full line of POD headers
  userdiff/perl: catch subs with brace on second line
  tests: make test_expect_code quieter on success

 t/t4018-diff-funcname.sh |  148 ++++++++++++++++++++++++++++++++++++---------
 t/test-lib.sh            |    7 +-
 userdiff.c               |   22 ++++++-
 3 files changed, 139 insertions(+), 38 deletions(-)

  parent reply	other threads:[~2011-05-21 18:53 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-15 18:14 Problems with Git's "perl" userdiff driver Ævar Arnfjörð Bjarmason
2011-05-15 20:02 ` Junio C Hamano
2011-05-15 20:13   ` Ævar Arnfjörð Bjarmason
2011-05-21 18:53 ` Jonathan Nieder [this message]
2011-05-21 19:11   ` [PATCH 1/7] t4018 (funcname patterns): make .gitattributes state easier to track Jonathan Nieder
2011-05-21 19:22   ` [PATCH 2/7] t4018 (funcname patterns): make configuration " Jonathan Nieder
2011-05-21 19:25   ` [PATCH 3/7] t4018 (funcname patterns): minor cleanups Jonathan Nieder
2011-05-21 19:29   ` [PATCH 4/7] userdiff/perl: anchor "sub" and "package" patterns on the left Jonathan Nieder
2011-05-21 19:35   ` [PATCH 5/7] userdiff/perl: match full line of POD headers Jonathan Nieder
2011-05-21 19:38   ` [PATCH 6/7] userdiff/perl: catch sub with brace on second line Jonathan Nieder
2011-05-22 17:29     ` [PATCH 8/7] userdiff/perl: tighten BEGIN/END block pattern to reject here-doc delimiters Jonathan Nieder
2011-05-21 19:40   ` [PATCH 7/7] tests: make test_expect_code quieter on success Jonathan Nieder
2011-05-22  8:04   ` [PATCH 0/7] Re: Problems with Git's "perl" userdiff driver Ævar Arnfjörð Bjarmason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110521185314.GA10530@elie \
    --to=jrnieder@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jnareb@gmail.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).