git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git-svn: avoid warning on undef readline()

From
EWEric Wong <e@80x24.org>
Date
Apr 6, 2018, 20:49 UTC
Message-ID
<20180406204906.GA27677@whir>
In-Reply-To
<87y3i0yz1t.fsf@evledraar.gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
Show 25 quoted lines
> 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.

Show 6 quoted lines
> 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));
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 8 of 11 in “git 2.17.0: uninitialized value $rec in scalar chomp at ...Git.pm line 557”
  1. Joseph MingroneApr 6, 2018
  2. Johannes SchindelinApr 6, 2018
  3. Joseph MingroneApr 6, 2018
  4. git-svn: avoid warning on undef readline()Ævar Arnfjörð Bjarmason, Apr 6, 2018
  5. Johannes SchindelinApr 6, 2018
  6. Eric WongApr 6, 2018
  7. Ævar Arnfjörð BjarmasonApr 6, 2018
  8. Eric WongApr 6, 2018
  9. Ævar Arnfjörð BjarmasonApr 6, 2018
  10. Junio C HamanoApr 9, 2018
  11. brian m. carlsonApr 7, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.