git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 3/5] Make Git::SVN::Ra use an accessor for URLs
Date: Fri, 27 Jul 2012 13:00:50 -0700	[thread overview]
Message-ID: <1343419252-9447-4-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>

Later it can canonicalize automatically.

A later change will make other things use the accessor.

No functional change.
---
 perl/Git/SVN/Ra.pm | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)

diff --git a/perl/Git/SVN/Ra.pm b/perl/Git/SVN/Ra.pm
index 23ff43e..329f855 100644
--- a/perl/Git/SVN/Ra.pm
+++ b/perl/Git/SVN/Ra.pm
@@ -84,7 +84,7 @@ sub escape_url {
 sub new {
 	my ($class, $url) = @_;
 	$url =~ s!/+$!!;
-	return $RA if ($RA && $RA->{url} eq $url);
+	return $RA if ($RA && $RA->url eq $url);
 
 	::_req_svn();
 
@@ -119,15 +119,33 @@ sub new {
 	                      config => $config,
 			      pool => SVN::Pool->new,
 	                      auth_provider_callbacks => $callbacks);
-	$self->{url} = $url;
+	$RA = bless $self, $class;
+
+	# Make sure its canonicalized
+	$self->url($url);
 	$self->{svn_path} = $url;
 	$self->{repos_root} = $self->get_repos_root;
 	$self->{svn_path} =~ s#^\Q$self->{repos_root}\E(/|$)##;
 	$self->{cache} = { check_path => { r => 0, data => {} },
 	                   get_dir => { r => 0, data => {} } };
-	$RA = bless $self, $class;
+
+	return $RA;
+}
+
+
+sub url {
+    my $self = shift;
+
+    if( @_ ) {
+        my $url = shift;
+        $self->{url} = $url;
+        return;
+    }
+
+    return $self->{url};
 }
 
+
 sub check_path {
 	my ($self, $path, $r) = @_;
 	my $cache = $self->{cache}->{check_path};
@@ -285,7 +303,7 @@ sub gs_do_switch {
 	my $path = $gs->{path};
 	my $pool = SVN::Pool->new;
 
-	my $full_url = $self->{url};
+	my $full_url = $self->url;
 	my $old_url = $full_url;
 	$full_url .= '/' . $path if length $path;
 	my ($ra, $reparented);
@@ -300,7 +318,7 @@ sub gs_do_switch {
 		$ra_invalid = 1;
 	} elsif ($old_url ne $full_url) {
 		SVN::_Ra::svn_ra_reparent($self->{session}, $full_url, $pool);
-		$self->{url} = $full_url;
+		$self->url($full_url);
 		$reparented = 1;
 	}
 
@@ -313,7 +331,7 @@ sub gs_do_switch {
 
 	if ($reparented) {
 		SVN::_Ra::svn_ra_reparent($self->{session}, $old_url, $pool);
-		$self->{url} = $old_url;
+		$self->url($old_url);
 	}
 
 	$pool->clear;
@@ -362,7 +380,7 @@ sub gs_fetch_loop_common {
 	my $inc = $_log_window_size;
 	my ($min, $max) = ($base, $head < $base + $inc ? $head : $base + $inc);
 	my $longest_path = longest_common_path($gsv, $globs);
-	my $ra_url = $self->{url};
+	my $ra_url = $self->url;
 	my $find_trailing_edge;
 	while (1) {
 		my %revs;
@@ -508,7 +526,7 @@ sub match_globs {
 				 ($self->check_path($p, $r) !=
 				  $SVN::Node::dir));
 			next unless $p =~ /$g->{path}->{regex}/;
-			$exists->{$p} = Git::SVN->init($self->{url}, $p, undef,
+			$exists->{$p} = Git::SVN->init($self->url, $p, undef,
 					 $g->{ref}->full_path($de), 1);
 		}
 	}
@@ -532,7 +550,7 @@ sub match_globs {
 			next if ($self->check_path($pathname, $r) !=
 			         $SVN::Node::dir);
 			$exists->{$pathname} = Git::SVN->init(
-			                      $self->{url}, $pathname, undef,
+			                      $self->url, $pathname, undef,
 			                      $g->{ref}->full_path($p), 1);
 		}
 		my $c = '';
@@ -548,7 +566,7 @@ sub match_globs {
 
 sub minimize_url {
 	my ($self) = @_;
-	return $self->{url} if ($self->{url} eq $self->{repos_root});
+	return $self->url if ($self->url eq $self->{repos_root});
 	my $url = $self->{repos_root};
 	my @components = split(m!/!, $self->{svn_path});
 	my $c = '';
@@ -568,7 +586,7 @@ sub can_do_switch {
 	unless (defined $can_do_switch) {
 		my $pool = SVN::Pool->new;
 		my $rep = eval {
-			$self->do_switch(1, '', 0, $self->{url},
+			$self->do_switch(1, '', 0, $self->url,
 			                 SVN::Delta::Editor->new, $pool);
 		};
 		if ($@) {
-- 
1.7.11.3

  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 ` [PATCH 1/5] Make Git::SVN use accessors internally for path Michael G. Schwern
2012-09-17  9:04   ` 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 ` Michael G. Schwern [this message]
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-4-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).