git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	Joseph Mingrone <jrm@ftfl.ca>,
	garga@FreeBSD.org,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Ben Caradoc-Davies <ben@transient.nz>,
	894997@bugs.debian.org
Subject: Re: [PATCH] git-svn: avoid warning on undef readline()
Date: Fri, 6 Apr 2018 20:49:07 +0000	[thread overview]
Message-ID: <20180406204906.GA27677@whir> (raw)
In-Reply-To: <87y3i0yz1t.fsf@evledraar.gmail.com>

Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> On Fri, Apr 06 2018, Eric Wong wrote:
> > Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> >
> >> --- a/perl/Git.pm
> >> +++ b/perl/Git.pm
> >> @@ -554,7 +554,7 @@ sub get_record {
> >>  	my ($fh, $rs) = @_;
> >>  	local $/ = $rs;
> >>  	my $rec = <$fh>;
> >> -	chomp $rec if defined $rs;
> >> +	chomp $rec if defined $rs and defined $rec;
> >
> > I'm struggling to understand the reason for the "defined $rs"
> > check.  I think it was a braino on my part and meant to use:
> >
> > 	chomp $rec if defined $rec;
> 
> Whether this makes any sense is another question, but you seem to have
> explicitly meant this at the time. The full function definition with
> documentation:
> 
>     =item get_record ( FILEHANDLE, INPUT_RECORD_SEPARATOR )
> 
>     Read one record from FILEHANDLE delimited by INPUT_RECORD_SEPARATOR,
>     removing any trailing INPUT_RECORD_SEPARATOR.

I've always known chomp to respect the value of $/; so chomp($rec)
whould only cut out whatever $rs is, and be a no-op if $rs is undef.

> It doesn't make to remove the trailing record separator if it's not
> defined, otherwise we'd be coercing undef to "\n" while at the same time
> returning multiple records. But then of course the only user of this
> with an "undef" argument just does:
> 
>     chomp($log_entry{log} = get_record($log_fh, undef));

Subtle difference, that chomp() still sees $/ as "\n".
$/ is only undef inside get_record.

> So we could also remove that chomp(), adn not check defined $rs, but IMO
> it's cleaner & more consistent this way.

I think the chomp is necessary. In git-svn.perl /^sub get_commit_entry {:

	# <snip>
	open my $log_fh, '>', $commit_editmsg or croak $!;

	# <snip>
		$msgbuf =~ s/\s+$//s;

	# <snip>

		print $log_fh $msgbuf or croak $!;

	# <snip>
	close $log_fh or croak $!;

# Above, we ensured the contents of $commit_editmsg has no trailing newline

	if ($_edit || ($type eq 'tree')) {
		chomp(my $editor = command_oneline(qw(var GIT_EDITOR)));
		system('sh', '-c', $editor.' "$@"', $editor, $commit_editmsg);
	}

# However, $editor is likely to introduce a trailing newline

	rename $commit_editmsg, $commit_msg or croak $!;
	{
		require Encode;
		# SVN requires messages to be UTF-8 when entering the repo
		open $log_fh, '<', $commit_msg or croak $!;
		binmode $log_fh;

# chomp trailing newline introduced by $editor:

		chomp($log_entry{log} = get_record($log_fh, undef));

  reply	other threads:[~2018-04-06 20:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-06 12:01 git 2.17.0: uninitialized value $rec in scalar chomp at ...Git.pm line 557 Joseph Mingrone
2018-04-06 12:21 ` Johannes Schindelin
2018-04-06 12:32   ` Joseph Mingrone
2018-04-06 13:15 ` [PATCH] git-svn: avoid warning on undef readline() Ævar Arnfjörð Bjarmason
2018-04-06 14:30   ` Johannes Schindelin
2018-04-06 16:56   ` Eric Wong
2018-04-06 18:23     ` Ævar Arnfjörð Bjarmason
2018-04-06 20:49       ` Eric Wong [this message]
2018-04-06 21:05         ` Ævar Arnfjörð Bjarmason
2018-04-09  2:09     ` Junio C Hamano
2018-04-07 19:20   ` brian m. carlson

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20180406204906.GA27677@whir \
    --to=e@80x24.org \
    --cc=894997@bugs.debian.org \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=avarab@gmail.com \
    --cc=ben@transient.nz \
    --cc=garga@FreeBSD.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrm@ftfl.ca \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).