Re: [PATCH 1/6] templates: Use heredoc in pre-commit hook

2013-07-15 Thread Junio C Hamano
Richard Hartmann  writes:

> On Sun, Jul 14, 2013 at 9:20 PM, Junio C Hamano  wrote:
>
>> Shells on modern distros and platforms have "echo" built-in, so this
>> patch replaces series of writes internal to the shell with a fork to
>> cat with heredoc (which often is implemented with a temporary file).
>
> True; fwiw, I replaced my one single echo with heredoc as you
> suggested I do that. I don't mind undoing that, or I can drop it from
> this series altogether.

The _real_ reason you wanted to do this change in the context of
this series is to make it easier to reword the messages and also
have the messages span the full width of the source line, to match
the expected output better, isn't it?  Git is not _only_ about
performance, so even if using "cat 

Re: [PATCH 1/6] templates: Use heredoc in pre-commit hook

2013-07-14 Thread Junio C Hamano
Jonathan Nieder  writes:

>> Based on 98770971aef8d1cbc78876d9023d10aa25df0526 in original patch
>> series from 2013-06-10.
>
> Please don't include this.  The audience for the commit message
> doesn't have that commit to compare to.
>
> If you want to preserve the original date, the way to do that is
> a "Date:" field at the top of the message body.
>
>   Date: Fri, 28 Jun 2013 21:16:19 +0530

And you generally should not do that, either.

The first date of the publication of _this_ version is recorded on
the Date: header of this message, not the "original path series"
that this round which is _based on_ (meaning, "different from") that
old one.  We do not want to see the date of the old one, either.

>
>   Spawning a new subprocess for ...
>
> [...]
>> --- a/templates/hooks--pre-commit.sample
>> +++ b/templates/hooks--pre-commit.sample
>> @@ -31,18 +31,19 @@ if [ "$allownonascii" != "true" ] &&
>>  test $(git diff --cached --name-only --diff-filter=A -z $against |
>>LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
>>  then
>> -echo "Error: Attempt to add a non-ascii file name."
>> -echo
>> -echo "This can cause problems if you want to work"
>> -echo "with people on other platforms."
>> -echo
>> -echo
>> -echo "If you know what you are doing you can disable this"
>> -echo "check using:"
>> -echo
>> -echo "  git config hooks.allownonascii true"
>> -echo
>> +cat <<-EOF
>> +Error: Attempt to add a non-ascii file name.
>
> Using
>
>   cat <<\EOF
>
> would make reading easier since the reader then doesn't have to worry
> about whether the text being cat'ed is indented or uses variable
> substitutions.
>
>> -echo "To be portable it is advisable to rename the file ..."
>> +To be portable it is advisable to rename the file.
>
> Yes, nice.
>
> With the above nits addressed, this change looks to be going in the
> right direction.  Thanks.
>
> Hope that helps,
> Jonathan
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/6] templates: Use heredoc in pre-commit hook

2013-07-14 Thread Jonathan Nieder
Richard Hartmann wrote:

>   fwiw, I replaced my one single echo with heredoc as you
> suggested I do that. I don't mind undoing that, or I can drop it from
> this series altogether.
>
> Guidance would be appreciated. :)

Thanks for your work, and no problem.

Both Junio's and my responses were about the (confusing and false)
commit message.  Code is not the only thing that matters when
submitting a patch --- commit messages become part of the product,
too, and are especially important as documentation that guides future
contributors.

So my advice is to fix the commit message, prepare improvements to
later patches in the series with help from reviewers where needed,
and then resubmit.

My review also included some advice about the code.  Naturally I
would be happy if that was of use, too. ;-)

Hope that helps,
Jonathan
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/6] templates: Use heredoc in pre-commit hook

2013-07-14 Thread Richard Hartmann
On Sun, Jul 14, 2013 at 9:20 PM, Junio C Hamano  wrote:

> Shells on modern distros and platforms have "echo" built-in, so this
> patch replaces series of writes internal to the shell with a fork to
> cat with heredoc (which often is implemented with a temporary file).

True; fwiw, I replaced my one single echo with heredoc as you
suggested I do that. I don't mind undoing that, or I can drop it from
this series altogether.

Guidance would be appreciated. :)


Richard
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/6] templates: Use heredoc in pre-commit hook

2013-07-14 Thread Junio C Hamano
Richard Hartmann  writes:

> Spawning a new subprocess for every line printed is inefficient.

This is not a valid justification at all, is it?  

Shells on modern distros and platforms have "echo" built-in, so this
patch replaces series of writes internal to the shell with a fork to
cat with heredoc (which often is implemented with a temporary file).




> Use heredoc, instead.
>
> Based on 98770971aef8d1cbc78876d9023d10aa25df0526 in original patch
> series from 2013-06-10.
>
> Signed-off-by: Richard Hartmann 
> ---
>  templates/hooks--pre-commit.sample |   25 +
>  1 file changed, 13 insertions(+), 12 deletions(-)
>
> diff --git a/templates/hooks--pre-commit.sample 
> b/templates/hooks--pre-commit.sample
> index 18c4829..889967c 100755
> --- a/templates/hooks--pre-commit.sample
> +++ b/templates/hooks--pre-commit.sample
> @@ -31,18 +31,19 @@ if [ "$allownonascii" != "true" ] &&
>   test $(git diff --cached --name-only --diff-filter=A -z $against |
> LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
>  then
> - echo "Error: Attempt to add a non-ascii file name."
> - echo
> - echo "This can cause problems if you want to work"
> - echo "with people on other platforms."
> - echo
> - echo "To be portable it is advisable to rename the file ..."
> - echo
> - echo "If you know what you are doing you can disable this"
> - echo "check using:"
> - echo
> - echo "  git config hooks.allownonascii true"
> - echo
> + cat <<-EOF
> +Error: Attempt to add a non-ascii file name.
> +
> +This can cause problems if you want to work
> +with people on other platforms.
> +
> +To be portable it is advisable to rename the file.
> +
> +If you know what you are doing you can disable this
> +check using:
> +
> +  git config hooks.allownonascii true
> +EOF
>   exit 1
>  fi
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/6] templates: Use heredoc in pre-commit hook

2013-07-14 Thread Jonathan Nieder
Hi,

Richard Hartmann wrote:

> Spawning a new subprocess for every line printed is inefficient.
> Use heredoc, instead.

I think this makes sense as a code clarity, simplicity, and
internationalizability improvement, but don't like the precedent of
eliminating 'echo' for the sake of fork removal (unless we have
measurements showing it's worthwhile, which would be included here).

Maybe a simpler commit message could sidestep the issue?

Use a heredoc instead of an "echo" for each line.

> Based on 98770971aef8d1cbc78876d9023d10aa25df0526 in original patch
> series from 2013-06-10.

Please don't include this.  The audience for the commit message
doesn't have that commit to compare to.

If you want to preserve the original date, the way to do that is
a "Date:" field at the top of the message body.

Date: Fri, 28 Jun 2013 21:16:19 +0530

Spawning a new subprocess for ...

[...]
> --- a/templates/hooks--pre-commit.sample
> +++ b/templates/hooks--pre-commit.sample
> @@ -31,18 +31,19 @@ if [ "$allownonascii" != "true" ] &&
>   test $(git diff --cached --name-only --diff-filter=A -z $against |
> LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
>  then
> - echo "Error: Attempt to add a non-ascii file name."
> - echo
> - echo "This can cause problems if you want to work"
> - echo "with people on other platforms."
> - echo
> - echo
> - echo "If you know what you are doing you can disable this"
> - echo "check using:"
> - echo
> - echo "  git config hooks.allownonascii true"
> - echo
> + cat <<-EOF
> +Error: Attempt to add a non-ascii file name.

Using

cat <<\EOF

would make reading easier since the reader then doesn't have to worry
about whether the text being cat'ed is indented or uses variable
substitutions.

> - echo "To be portable it is advisable to rename the file ..."
> +To be portable it is advisable to rename the file.

Yes, nice.

With the above nits addressed, this change looks to be going in the
right direction.  Thanks.

Hope that helps,
Jonathan
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html