@matheusbsbs / matheus-bagliano / commits / a5460eb7bb
Fork 0

git-svn: allow `info' command to work offline

Cache the repository root whenever we connect to the repository. This will allow us to notice URL changes if the user changes the URL in .git/config, too. If the repository is no longer accessible, or if `git svn info' is the first and only command run; then '(offline)' will be displayed for "Repository Root:" in the output. Signed-off-by: Eric Wong <normalperson@yhbt.net>

Eric Wong committed Nov 21, 2007 at 18:20 UTC a5460eb7bb3ccef599adce87a620a3b89c7eb5df
1 file changed +23 -3
git-svn.perl
+23 -3
@@ -782,9 +782,14 @@ sub cmd_info {
782 $result .= "Name: " . basename($path) . "\n" if $file_type ne "dir";
783 $result .= "URL: " . $full_url . "\n";
784
785 - my $repos_root = $gs->ra->{repos_root};
786 - Git::SVN::remove_username($repos_root);
787 - $result .= "Repository Root: $repos_root\n";
785 + eval {
786 + my $repos_root = $gs->repos_root;
787 + Git::SVN::remove_username($repos_root);
788 + $result .= "Repository Root: $repos_root\n";
789 + };
790 + if ($@) {
791 + $result .= "Repository Root: (offline)\n";
792 + }
793 $result .= "Repository UUID: $uuid\n" unless $diff_status eq "A";
794 $result .= "Revision: " . ($diff_status eq "A" ? 0 : $rev) . "\n";
795
@@ -1773,9 +1778,24 @@ sub ra_uuid {
1778 $self->{ra_uuid};
1779 }
1780
1781 +sub _set_repos_root {
1782 + my ($self, $repos_root) = @_;
1783 + my $k = "svn-remote.$self->{repo_id}.reposRoot";
1784 + $repos_root ||= $self->ra->{repos_root};
1785 + tmp_config($k, $repos_root);
1786 + $repos_root;
1787 +}
1788 +
1789 +sub repos_root {
1790 + my ($self) = @_;
1791 + my $k = "svn-remote.$self->{repo_id}.reposRoot";
1792 + eval { tmp_config('--get', $k) } || $self->_set_repos_root;
1793 +}
1794 +
1795 sub ra {
1796 my ($self) = shift;
1797 my $ra = Git::SVN::Ra->new($self->{url});
1798 + $self->_set_repos_root($ra->{repos_root});
1799 if ($self->use_svm_props && !$self->{svm}) {
1800 if ($self->no_metadata) {
1801 die "Can't have both 'noMetadata' and ",