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 <e@80x24.org>
Eric Wong committed
Oct 14, 2016 at 00:27 UTC
b26098fc2f76131f4258d800e0892e87f9138331
4 files changed
+27
-20
git-svn.perl
+2
-2
@@ -44,6 +44,7 @@ use Git qw(
44
command_close_pipe
45
command_bidi_pipe
46
command_close_bidi_pipe
47
+ get_record
48
);
49
50
BEGIN {
@@ -1880,10 +1881,9 @@ sub get_commit_entry {
1881
{
1882
require Encode;
1883
# SVN requires messages to be UTF-8 when entering the repo
1883
- local $/;
1884
open $log_fh, '<', $commit_msg or croak $!;
1885
binmode $log_fh;
1886
- chomp($log_entry{log} = <$log_fh>);
1886
+ chomp($log_entry{log} = get_record($log_fh, undef));
1887
1888
my $enc = Git::config('i18n.commitencoding') || 'UTF-8';
1889
my $msg = $log_entry{log};
perl/Git.pm
+15
-1
@@ -59,7 +59,7 @@ require Exporter;
59
command_bidi_pipe command_close_bidi_pipe
60
version exec_path html_path hash_object git_cmd_try
61
remote_refs prompt
62
- get_tz_offset
62
+ get_tz_offset get_record
63
credential credential_read credential_write
64
temp_acquire temp_is_locked temp_release temp_reset temp_path);
65
@@ -538,6 +538,20 @@ sub get_tz_offset {
538
return sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
539
}
540
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
+}
555
556
=item prompt ( PROMPT , ISPASSWORD )
557
perl/Git/SVN/Editor.pm
+5
-7
@@ -7,7 +7,9 @@ use SVN::Delta;
7
use Carp qw/croak/;
8
use Git qw/command command_oneline command_noisy command_output_pipe
9
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
+
13
BEGIN {
14
@ISA = qw(SVN::Delta::Editor);
15
}
@@ -57,11 +59,9 @@ sub generate_diff {
59
push @diff_tree, "-l$_rename_limit" if defined $_rename_limit;
60
push @diff_tree, $tree_a, $tree_b;
61
my ($diff_fh, $ctx) = command_output_pipe(@diff_tree);
60
- local $/ = "\0";
62
my $state = 'meta';
63
my @mods;
63
- while (<$diff_fh>) {
64
- chomp $_; # this gets rid of the trailing "\0"
64
+ while (defined($_ = get_record($diff_fh, "\0"))) {
65
if ($state eq 'meta' && /^:(\d{6})\s(\d{6})\s
66
($::sha1)\s($::sha1)\s
67
([MTCRAD])\d*$/xo) {
@@ -173,9 +173,7 @@ sub rmdirs {
173
174
my ($fh, $ctx) = command_output_pipe(qw/ls-tree --name-only -r -z/,
175
$self->{tree_b});
176
- local $/ = "\0";
177
- while (<$fh>) {
178
- chomp;
176
+ while (defined($_ = get_record($fh, "\0"))) {
177
my @dn = split m#/#, $_;
178
while (pop @dn) {
179
delete $rm->{join '/', @dn};
perl/Git/SVN/Fetcher.pm
+5
-10
@@ -9,7 +9,8 @@ use Carp qw/croak/;
9
use File::Basename qw/dirname/;
10
use Git qw/command command_oneline command_noisy command_output_pipe
11
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/;
14
BEGIN {
15
@ISA = qw(SVN::Delta::Editor);
16
}
@@ -86,11 +87,9 @@ sub _mark_empty_symlinks {
87
my $printed_warning;
88
chomp(my $empty_blob = `git hash-object -t blob --stdin < /dev/null`);
89
my ($ls, $ctx) = command_output_pipe(qw/ls-tree -r -z/, $cmt);
89
- local $/ = "\0";
90
my $pfx = defined($switch_path) ? $switch_path : $git_svn->path;
91
$pfx .= '/' if length($pfx);
92
- while (<$ls>) {
93
- chomp;
92
+ while (defined($_ = get_record($ls, "\0"))) {
93
s/\A100644 blob $empty_blob\t//o or next;
94
unless ($printed_warning) {
95
print STDERR "Scanning for empty symlinks, ",
@@ -179,9 +178,7 @@ sub delete_entry {
178
my ($ls, $ctx) = command_output_pipe(qw/ls-tree
179
-r --name-only -z/,
180
$tree);
182
- local $/ = "\0";
183
- while (<$ls>) {
184
- chomp;
181
+ while (defined($_ = get_record($ls, "\0"))) {
182
my $rmpath = "$gpath/$_";
183
$self->{gii}->remove($rmpath);
184
print "\tD\t$rmpath\n" unless $::_q;
@@ -247,9 +244,7 @@ sub add_directory {
244
my ($ls, $ctx) = command_output_pipe(qw/ls-tree
245
-r --name-only -z/,
246
$self->{c});
250
- local $/ = "\0";
251
- while (<$ls>) {
252
- chomp;
247
+ while (defined($_ = get_record($ls, "\0"))) {
248
$self->{gii}->remove($_);
249
print "\tD\t$_\n" unless $::_q;
250
push @deleted_gpath, $gpath;