From: "Michael G. Schwern" <schwern@pobox.com>
To: git@vger.kernel.org, gitster@pobox.com
Cc: robbat2@gentoo.org, bwalton@artsci.utoronto.ca,
normalperson@yhbt.net, jrnieder@gmail.com, schwern@pobox.com
Subject: [PATCH 1/5] Make Git::SVN use accessors internally for path.
Date: Fri, 27 Jul 2012 13:00:48 -0700 [thread overview]
Message-ID: <1343419252-9447-2-git-send-email-schwern@pobox.com> (raw)
In-Reply-To: <1343419252-9447-1-git-send-email-schwern@pobox.com>
From: "Michael G. Schwern" <schwern@pobox.com>
Then later it can be canonicalized automatically rather than everywhere
its used.
Later patch will make other things use it.
---
perl/Git/SVN.pm | 87 +++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 56 insertions(+), 31 deletions(-)
diff --git a/perl/Git/SVN.pm b/perl/Git/SVN.pm
index b8b3474..0aff9d0 100644
--- a/perl/Git/SVN.pm
+++ b/perl/Git/SVN.pm
@@ -314,12 +314,12 @@ sub init_remote_config {
print STDERR "Using higher level of URL: ",
"$url => $min_url\n";
}
- my $old_path = $self->{path};
- $self->{path} = $url;
- $self->{path} =~ s!^\Q$min_url\E(/|$)!!;
+ my $old_path = $self->path;
+ $url =~ s!^\Q$min_url\E(/|$)!!;
if (length $old_path) {
- $self->{path} .= "/$old_path";
+ $url .= "/$old_path";
}
+ $self->path($url);
$url = $min_url;
}
}
@@ -343,11 +343,13 @@ sub init_remote_config {
unless ($no_write) {
command_noisy('config',
"svn-remote.$self->{repo_id}.url", $url);
- $self->{path} =~ s{^/}{};
- $self->{path} =~ s{%([0-9A-F]{2})}{chr hex($1)}ieg;
+ my $path = $self->path;
+ $path =~ s{^/}{};
+ $path =~ s{%([0-9A-F]{2})}{chr hex($1)}ieg;
+ $self->path($path);
command_noisy('config', '--add',
"svn-remote.$self->{repo_id}.fetch",
- "$self->{path}:".$self->refname);
+ $self->path.":".$self->refname);
}
$self->{url} = $url;
}
@@ -435,17 +437,22 @@ sub new {
}
}
my $self = _new($class, $repo_id, $ref_id, $path);
- if (!defined $self->{path} || !length $self->{path}) {
+ if (!defined $self->path || !length $self->path) {
my $fetch = command_oneline('config', '--get',
"svn-remote.$repo_id.fetch",
":$ref_id\$") or
die "Failed to read \"svn-remote.$repo_id.fetch\" ",
"\":$ref_id\$\" in config\n";
- ($self->{path}, undef) = split(/\s*:\s*/, $fetch);
+ my($path) = split(/\s*:\s*/, $fetch);
+ $self->path($path);
+ }
+ {
+ my $path = $self->path;
+ $path =~ s{/+}{/}g;
+ $path =~ s{\A/}{};
+ $path =~ s{/\z}{};
+ $self->path($path);
}
- $self->{path} =~ s{/+}{/}g;
- $self->{path} =~ s{\A/}{};
- $self->{path} =~ s{/\z}{};
$self->{url} = command_oneline('config', '--get',
"svn-remote.$repo_id.url") or
die "Failed to read \"svn-remote.$repo_id.url\" in config\n";
@@ -567,7 +574,7 @@ sub _set_svm_vars {
}
my $r = $ra->get_latest_revnum;
- my $path = $self->{path};
+ my $path = $self->path;
my %tried;
while (length $path) {
unless ($tried{"$self->{url}/$path"}) {
@@ -728,7 +735,7 @@ sub prop_walk {
$path =~ s#^/*#/#g;
my $p = $path;
# Strip the irrelevant part of the path.
- $p =~ s#^/+\Q$self->{path}\E(/|$)#/#;
+ $p =~ s#^/+\Q@{[$self->path]}\E(/|$)#/#;
# Ensure the path is terminated by a `/'.
$p =~ s#/*$#/#;
@@ -749,7 +756,7 @@ sub prop_walk {
foreach (sort keys %$dirent) {
next if $dirent->{$_}->{kind} != $SVN::Node::dir;
- $self->prop_walk($self->{path} . $p . $_, $rev, $sub);
+ $self->prop_walk($self->path . $p . $_, $rev, $sub);
}
}
@@ -920,19 +927,19 @@ sub rewrite_uuid {
sub metadata_url {
my ($self) = @_;
($self->rewrite_root || $self->{url}) .
- (length $self->{path} ? '/' . $self->{path} : '');
+ (length $self->path ? '/' . $self->path : '');
}
sub full_url {
my ($self) = @_;
- $self->{url} . (length $self->{path} ? '/' . $self->{path} : '');
+ $self->{url} . (length $self->path ? '/' . $self->path : '');
}
sub full_pushurl {
my ($self) = @_;
if ($self->{pushurl}) {
- return $self->{pushurl} . (length $self->{path} ? '/' .
- $self->{path} : '');
+ return $self->{pushurl} . (length $self->path ? '/' .
+ $self->path : '');
} else {
return $self->full_url;
}
@@ -1048,20 +1055,20 @@ sub do_git_commit {
sub match_paths {
my ($self, $paths, $r) = @_;
- return 1 if $self->{path} eq '';
- if (my $path = $paths->{"/$self->{path}"}) {
+ return 1 if $self->path eq '';
+ if (my $path = $paths->{"/".$self->path}) {
return ($path->{action} eq 'D') ? 0 : 1;
}
- $self->{path_regex} ||= qr/^\/\Q$self->{path}\E\//;
+ $self->{path_regex} ||= qr{^/\Q@{[$self->path]}\E/};
if (grep /$self->{path_regex}/, keys %$paths) {
return 1;
}
my $c = '';
- foreach (split m#/#, $self->{path}) {
+ foreach (split m#/#, $self->path) {
$c .= "/$_";
next unless ($paths->{$c} &&
($paths->{$c}->{action} =~ /^[AR]$/));
- if ($self->ra->check_path($self->{path}, $r) ==
+ if ($self->ra->check_path($self->path, $r) ==
$SVN::Node::dir) {
return 1;
}
@@ -1075,14 +1082,14 @@ sub find_parent_branch {
unless (defined $paths) {
my $err_handler = $SVN::Error::handler;
$SVN::Error::handler = \&Git::SVN::Ra::skip_unknown_revs;
- $self->ra->get_log([$self->{path}], $rev, $rev, 0, 1, 1,
+ $self->ra->get_log([$self->path], $rev, $rev, 0, 1, 1,
sub { $paths = $_[0] });
$SVN::Error::handler = $err_handler;
}
return undef unless defined $paths;
# look for a parent from another branch:
- my @b_path_components = split m#/#, $self->{path};
+ my @b_path_components = split m#/#, $self->path;
my @a_path_components;
my $i;
while (@b_path_components) {
@@ -1235,7 +1242,7 @@ sub mkemptydirs {
close $fh;
}
- my $strip = qr/\A\Q$self->{path}\E(?:\/|$)/;
+ my $strip = qr/\A\Q@{[$self->path]}\E(?:\/|$)/;
foreach my $d (sort keys %empty_dirs) {
$d = uri_decode($d);
$d =~ s/$strip//;
@@ -1858,7 +1865,7 @@ sub make_log_entry {
$commit_email ||= "$author\@$uuid";
} elsif ($self->use_svnsync_props) {
my $full_url = $self->svnsync->{url};
- $full_url .= "/$self->{path}" if length $self->{path};
+ $full_url .= "/".$self->path if length $self->path;
remove_username($full_url);
my $uuid = $self->svnsync->{uuid};
$log_entry{metadata} = "$full_url\@$rev $uuid";
@@ -1905,7 +1912,7 @@ sub set_tree {
tree_b => $tree,
editor_cb => sub {
$self->set_tree_cb($log_entry, $tree, @_) },
- svn_path => $self->{path} );
+ svn_path => $self->path );
if (!Git::SVN::Editor->new(\%ed_opts)->apply_diff) {
print "No changes\nr$self->{last_rev} = $tree\n";
}
@@ -2276,10 +2283,28 @@ sub _new {
$_[3] = $path = '' unless (defined $path);
mkpath([$dir]);
- bless {
+ my $obj = bless {
ref_id => $ref_id, dir => $dir, index => "$dir/index",
- path => $path, config => "$ENV{GIT_DIR}/svn/config",
+ config => "$ENV{GIT_DIR}/svn/config",
map_root => "$dir/.rev_map", repo_id => $repo_id }, $class;
+
+ # Ensure it gets canonicalized
+ $obj->path($path);
+
+ return $obj;
+}
+
+
+sub path {
+ my $self = shift;
+
+ if( @_ ) {
+ my $path = shift;
+ $self->{path} = $path;
+ return;
+ }
+
+ return $self->{path};
}
# for read-only access of old .rev_db formats
--
1.7.11.3
next prev parent reply other threads:[~2012-07-27 20:01 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-27 20:00 Make git-svn Use accessors for paths and urls Michael G. Schwern
2012-07-27 20:00 ` Michael G. Schwern [this message]
2012-09-17 9:04 ` [PATCH 1/5] Make Git::SVN use accessors internally for path Jonathan Nieder
2012-09-17 9:08 ` [FYI/PATCH 1/5] Git::SVN: introduce path accessor Jonathan Nieder
2012-09-17 9:09 ` [FYI/PATCH 2/5] Git::SVN: use accessor to read path Jonathan Nieder
2012-09-17 9:10 ` [FYI/PATCH 3/5] Git::SVN: use accessor to write path Jonathan Nieder
2012-09-17 9:12 ` [FYI/PATCH 4/5] Git::SVN::_new: use accessor to write path field Jonathan Nieder
2012-09-17 9:13 ` [PATCH/RFC 5/5] Git::SVN: rename private " Jonathan Nieder
2012-09-18 0:00 ` Junio C Hamano
2012-09-18 0:07 ` Eric Wong
2012-07-27 20:00 ` [PATCH 2/5] Make Git::SVN use an accessor for URLs internally Michael G. Schwern
2012-07-27 20:00 ` [PATCH 3/5] Make Git::SVN::Ra use an accessor for URLs Michael G. Schwern
2012-07-27 20:00 ` [PATCH 4/5] Change the rest of the code to use Git::SVN->path instead of the hash directly Michael G. Schwern
2012-07-27 20:00 ` [PATCH 5/5] Change the rest of the code to use the Git::SVN and Git::SVN::Ra url accessors Michael G. Schwern
2012-07-28 2:59 ` Eric Wong
2012-07-28 3:10 ` Make git-svn Use accessors for paths and urls Jonathan Nieder
2012-07-28 7:40 ` Michael G Schwern
2012-07-28 7:54 ` Jonathan Nieder
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1343419252-9447-2-git-send-email-schwern@pobox.com \
--to=schwern@pobox.com \
--cc=bwalton@artsci.utoronto.ca \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=normalperson@yhbt.net \
--cc=robbat2@gentoo.org \
/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.
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 NNTP newsgroup(s).