Git::SVN: use accessors internally for path

Then later it can be canonicalized automatically rather than everywhere its used. Later patch will make other things use it. [ew: commit title, reformatted accessor to match existing style] Signed-off-by: Eric Wong <normalperson@yhbt.net>

Michael G. Schwern committed Jul 27, 2012 at 13:00 UTC 5578ed744ddcf4e43d4fffa40fe3c76e38a91d11
1 file changed +55 -31
perl/Git/SVN.pm
+55 -31
@@ -314,12 +314,12 @@ sub init_remote_config {
314 print STDERR "Using higher level of URL: ",
315 "$url => $min_url\n";
316 }
317 - my $old_path = $self->{path};
318 - $self->{path} = $url;
319 - $self->{path} =~ s!^\Q$min_url\E(/|$)!!;
317 + my $old_path = $self->path;
318 + $url =~ s!^\Q$min_url\E(/|$)!!;
319 if (length $old_path) {
321 - $self->{path} .= "/$old_path";
320 + $url .= "/$old_path";
321 }
322 + $self->path($url);
323 $url = $min_url;
324 }
325 }
@@ -343,11 +343,13 @@ sub init_remote_config {
343 unless ($no_write) {
344 command_noisy('config',
345 "svn-remote.$self->{repo_id}.url", $url);
346 - $self->{path} =~ s{^/}{};
347 - $self->{path} =~ s{%([0-9A-F]{2})}{chr hex($1)}ieg;
346 + my $path = $self->path;
347 + $path =~ s{^/}{};
348 + $path =~ s{%([0-9A-F]{2})}{chr hex($1)}ieg;
349 + $self->path($path);
350 command_noisy('config', '--add',
351 "svn-remote.$self->{repo_id}.fetch",
350 - "$self->{path}:".$self->refname);
352 + $self->path.":".$self->refname);
353 }
354 $self->{url} = $url;
355 }
@@ -435,17 +437,22 @@ sub new {
437 }
438 }
439 my $self = _new($class, $repo_id, $ref_id, $path);
438 - if (!defined $self->{path} || !length $self->{path}) {
440 + if (!defined $self->path || !length $self->path) {
441 my $fetch = command_oneline('config', '--get',
442 "svn-remote.$repo_id.fetch",
443 ":$ref_id\$") or
444 die "Failed to read \"svn-remote.$repo_id.fetch\" ",
445 "\":$ref_id\$\" in config\n";
444 - ($self->{path}, undef) = split(/\s*:\s*/, $fetch);
446 + my($path) = split(/\s*:\s*/, $fetch);
447 + $self->path($path);
448 + }
449 + {
450 + my $path = $self->path;
451 + $path =~ s{/+}{/}g;
452 + $path =~ s{\A/}{};
453 + $path =~ s{/\z}{};
454 + $self->path($path);
455 }
446 - $self->{path} =~ s{/+}{/}g;
447 - $self->{path} =~ s{\A/}{};
448 - $self->{path} =~ s{/\z}{};
456 $self->{url} = command_oneline('config', '--get',
457 "svn-remote.$repo_id.url") or
458 die "Failed to read \"svn-remote.$repo_id.url\" in config\n";
@@ -567,7 +574,7 @@ sub _set_svm_vars {
574 }
575
576 my $r = $ra->get_latest_revnum;
570 - my $path = $self->{path};
577 + my $path = $self->path;
578 my %tried;
579 while (length $path) {
580 unless ($tried{"$self->{url}/$path"}) {
@@ -728,7 +735,7 @@ sub prop_walk {
735 $path =~ s#^/*#/#g;
736 my $p = $path;
737 # Strip the irrelevant part of the path.
731 - $p =~ s#^/+\Q$self->{path}\E(/|$)#/#;
738 + $p =~ s#^/+\Q@{[$self->path]}\E(/|$)#/#;
739 # Ensure the path is terminated by a `/'.
740 $p =~ s#/*$#/#;
741
@@ -749,7 +756,7 @@ sub prop_walk {
756
757 foreach (sort keys %$dirent) {
758 next if $dirent->{$_}->{kind} != $SVN::Node::dir;
752 - $self->prop_walk($self->{path} . $p . $_, $rev, $sub);
759 + $self->prop_walk($self->path . $p . $_, $rev, $sub);
760 }
761 }
762
@@ -920,19 +927,19 @@ sub rewrite_uuid {
927 sub metadata_url {
928 my ($self) = @_;
929 ($self->rewrite_root || $self->{url}) .
923 - (length $self->{path} ? '/' . $self->{path} : '');
930 + (length $self->path ? '/' . $self->path : '');
931 }
932
933 sub full_url {
934 my ($self) = @_;
928 - $self->{url} . (length $self->{path} ? '/' . $self->{path} : '');
935 + $self->{url} . (length $self->path ? '/' . $self->path : '');
936 }
937
938 sub full_pushurl {
939 my ($self) = @_;
940 if ($self->{pushurl}) {
934 - return $self->{pushurl} . (length $self->{path} ? '/' .
935 - $self->{path} : '');
941 + return $self->{pushurl} . (length $self->path ? '/' .
942 + $self->path : '');
943 } else {
944 return $self->full_url;
945 }
@@ -1048,20 +1055,20 @@ sub do_git_commit {
1055
1056 sub match_paths {
1057 my ($self, $paths, $r) = @_;
1051 - return 1 if $self->{path} eq '';
1052 - if (my $path = $paths->{"/$self->{path}"}) {
1058 + return 1 if $self->path eq '';
1059 + if (my $path = $paths->{"/".$self->path}) {
1060 return ($path->{action} eq 'D') ? 0 : 1;
1061 }
1055 - $self->{path_regex} ||= qr/^\/\Q$self->{path}\E\//;
1062 + $self->{path_regex} ||= qr{^/\Q@{[$self->path]}\E/};
1063 if (grep /$self->{path_regex}/, keys %$paths) {
1064 return 1;
1065 }
1066 my $c = '';
1060 - foreach (split m#/#, $self->{path}) {
1067 + foreach (split m#/#, $self->path) {
1068 $c .= "/$_";
1069 next unless ($paths->{$c} &&
1070 ($paths->{$c}->{action} =~ /^[AR]$/));
1064 - if ($self->ra->check_path($self->{path}, $r) ==
1071 + if ($self->ra->check_path($self->path, $r) ==
1072 $SVN::Node::dir) {
1073 return 1;
1074 }
@@ -1075,14 +1082,14 @@ sub find_parent_branch {
1082 unless (defined $paths) {
1083 my $err_handler = $SVN::Error::handler;
1084 $SVN::Error::handler = \&Git::SVN::Ra::skip_unknown_revs;
1078 - $self->ra->get_log([$self->{path}], $rev, $rev, 0, 1, 1,
1085 + $self->ra->get_log([$self->path], $rev, $rev, 0, 1, 1,
1086 sub { $paths = $_[0] });
1087 $SVN::Error::handler = $err_handler;
1088 }
1089 return undef unless defined $paths;
1090
1091 # look for a parent from another branch:
1085 - my @b_path_components = split m#/#, $self->{path};
1092 + my @b_path_components = split m#/#, $self->path;
1093 my @a_path_components;
1094 my $i;
1095 while (@b_path_components) {
@@ -1235,7 +1242,7 @@ sub mkemptydirs {
1242 close $fh;
1243 }
1244
1238 - my $strip = qr/\A\Q$self->{path}\E(?:\/|$)/;
1245 + my $strip = qr/\A\Q@{[$self->path]}\E(?:\/|$)/;
1246 foreach my $d (sort keys %empty_dirs) {
1247 $d = uri_decode($d);
1248 $d =~ s/$strip//;
@@ -1858,7 +1865,7 @@ sub make_log_entry {
1865 $commit_email ||= "$author\@$uuid";
1866 } elsif ($self->use_svnsync_props) {
1867 my $full_url = $self->svnsync->{url};
1861 - $full_url .= "/$self->{path}" if length $self->{path};
1868 + $full_url .= "/".$self->path if length $self->path;
1869 remove_username($full_url);
1870 my $uuid = $self->svnsync->{uuid};
1871 $log_entry{metadata} = "$full_url\@$rev $uuid";
@@ -1905,7 +1912,7 @@ sub set_tree {
1912 tree_b => $tree,
1913 editor_cb => sub {
1914 $self->set_tree_cb($log_entry, $tree, @_) },
1908 - svn_path => $self->{path} );
1915 + svn_path => $self->path );
1916 if (!Git::SVN::Editor->new(\%ed_opts)->apply_diff) {
1917 print "No changes\nr$self->{last_rev} = $tree\n";
1918 }
@@ -2276,10 +2283,27 @@ sub _new {
2283
2284 $_[3] = $path = '' unless (defined $path);
2285 mkpath([$dir]);
2279 - bless {
2286 + my $obj = bless {
2287 ref_id => $ref_id, dir => $dir, index => "$dir/index",
2281 - path => $path, config => "$ENV{GIT_DIR}/svn/config",
2288 + config => "$ENV{GIT_DIR}/svn/config",
2289 map_root => "$dir/.rev_map", repo_id => $repo_id }, $class;
2290 +
2291 + # Ensure it gets canonicalized
2292 + $obj->path($path);
2293 +
2294 + return $obj;
2295 +}
2296 +
2297 +sub path {
2298 + my $self = shift;
2299 +
2300 + if (@_) {
2301 + my $path = shift;
2302 + $self->{path} = $path;
2303 + return;
2304 + }
2305 +
2306 + return $self->{path};
2307 }
2308
2309 # for read-only access of old .rev_db formats