Skip to content

Commit b26098f

Browse files
author
Eric Wong
committed
git-svn: reduce scope of input record separator change
Reducing the scope of where we change the record separator ($/) avoids bugs in calls which rely on the input record separator further down, such as the 'chomp' usage in command_oneline. This is necessary for a future change to git-svn, but exists in Git.pm since it seems useful for gitweb and our other Perl scripts, too. Signed-off-by: Eric Wong <[email protected]>
1 parent 3cdd5d1 commit b26098f

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

git-svn.perl

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
command_close_pipe
4545
command_bidi_pipe
4646
command_close_bidi_pipe
47+
get_record
4748
);
4849

4950
BEGIN {
@@ -1880,10 +1881,9 @@ sub get_commit_entry {
18801881
{
18811882
require Encode;
18821883
# SVN requires messages to be UTF-8 when entering the repo
1883-
local $/;
18841884
open $log_fh, '<', $commit_msg or croak $!;
18851885
binmode $log_fh;
1886-
chomp($log_entry{log} = <$log_fh>);
1886+
chomp($log_entry{log} = get_record($log_fh, undef));
18871887

18881888
my $enc = Git::config('i18n.commitencoding') || 'UTF-8';
18891889
my $msg = $log_entry{log};

perl/Git.pm

+15-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ require Exporter;
5959
command_bidi_pipe command_close_bidi_pipe
6060
version exec_path html_path hash_object git_cmd_try
6161
remote_refs prompt
62-
get_tz_offset
62+
get_tz_offset get_record
6363
credential credential_read credential_write
6464
temp_acquire temp_is_locked temp_release temp_reset temp_path);
6565

@@ -538,6 +538,20 @@ sub get_tz_offset {
538538
return sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
539539
}
540540

541+
=item get_record ( FILEHANDLE, INPUT_RECORD_SEPARATOR )
542+
543+
Read one record from FILEHANDLE delimited by INPUT_RECORD_SEPARATOR,
544+
removing any trailing INPUT_RECORD_SEPARATOR.
545+
546+
=cut
547+
548+
sub get_record {
549+
my ($fh, $rs) = @_;
550+
local $/ = $rs;
551+
my $rec = <$fh>;
552+
chomp $rec if defined $rs;
553+
$rec;
554+
}
541555

542556
=item prompt ( PROMPT , ISPASSWORD )
543557

perl/Git/SVN/Editor.pm

+5-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use SVN::Delta;
77
use Carp qw/croak/;
88
use Git qw/command command_oneline command_noisy command_output_pipe
99
command_input_pipe command_close_pipe
10-
command_bidi_pipe command_close_bidi_pipe/;
10+
command_bidi_pipe command_close_bidi_pipe
11+
get_record/;
12+
1113
BEGIN {
1214
@ISA = qw(SVN::Delta::Editor);
1315
}
@@ -57,11 +59,9 @@ sub generate_diff {
5759
push @diff_tree, "-l$_rename_limit" if defined $_rename_limit;
5860
push @diff_tree, $tree_a, $tree_b;
5961
my ($diff_fh, $ctx) = command_output_pipe(@diff_tree);
60-
local $/ = "\0";
6162
my $state = 'meta';
6263
my @mods;
63-
while (<$diff_fh>) {
64-
chomp $_; # this gets rid of the trailing "\0"
64+
while (defined($_ = get_record($diff_fh, "\0"))) {
6565
if ($state eq 'meta' && /^:(\d{6})\s(\d{6})\s
6666
($::sha1)\s($::sha1)\s
6767
([MTCRAD])\d*$/xo) {
@@ -173,9 +173,7 @@ sub rmdirs {
173173

174174
my ($fh, $ctx) = command_output_pipe(qw/ls-tree --name-only -r -z/,
175175
$self->{tree_b});
176-
local $/ = "\0";
177-
while (<$fh>) {
178-
chomp;
176+
while (defined($_ = get_record($fh, "\0"))) {
179177
my @dn = split m#/#, $_;
180178
while (pop @dn) {
181179
delete $rm->{join '/', @dn};

perl/Git/SVN/Fetcher.pm

+5-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use Carp qw/croak/;
99
use File::Basename qw/dirname/;
1010
use Git qw/command command_oneline command_noisy command_output_pipe
1111
command_input_pipe command_close_pipe
12-
command_bidi_pipe command_close_bidi_pipe/;
12+
command_bidi_pipe command_close_bidi_pipe
13+
get_record/;
1314
BEGIN {
1415
@ISA = qw(SVN::Delta::Editor);
1516
}
@@ -86,11 +87,9 @@ sub _mark_empty_symlinks {
8687
my $printed_warning;
8788
chomp(my $empty_blob = `git hash-object -t blob --stdin < /dev/null`);
8889
my ($ls, $ctx) = command_output_pipe(qw/ls-tree -r -z/, $cmt);
89-
local $/ = "\0";
9090
my $pfx = defined($switch_path) ? $switch_path : $git_svn->path;
9191
$pfx .= '/' if length($pfx);
92-
while (<$ls>) {
93-
chomp;
92+
while (defined($_ = get_record($ls, "\0"))) {
9493
s/\A100644 blob $empty_blob\t//o or next;
9594
unless ($printed_warning) {
9695
print STDERR "Scanning for empty symlinks, ",
@@ -179,9 +178,7 @@ sub delete_entry {
179178
my ($ls, $ctx) = command_output_pipe(qw/ls-tree
180179
-r --name-only -z/,
181180
$tree);
182-
local $/ = "\0";
183-
while (<$ls>) {
184-
chomp;
181+
while (defined($_ = get_record($ls, "\0"))) {
185182
my $rmpath = "$gpath/$_";
186183
$self->{gii}->remove($rmpath);
187184
print "\tD\t$rmpath\n" unless $::_q;
@@ -247,9 +244,7 @@ sub add_directory {
247244
my ($ls, $ctx) = command_output_pipe(qw/ls-tree
248245
-r --name-only -z/,
249246
$self->{c});
250-
local $/ = "\0";
251-
while (<$ls>) {
252-
chomp;
247+
while (defined($_ = get_record($ls, "\0"))) {
253248
$self->{gii}->remove($_);
254249
print "\tD\t$_\n" unless $::_q;
255250
push @deleted_gpath, $gpath;

0 commit comments

Comments
 (0)