git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/3] git-svn: allow `info' command to work offline

From
EWEric Wong <normalperson@yhbt.net>
Date
Nov 22, 2007, 02:23 UTC
Message-ID
<20071122022343.GA9992@soma>
In-Reply-To
<1195675039-26746-1-git-send-email-ddkilzer@kilzer.net>

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>
---
 David:
 I'll apply this once you've verified my fix to 1/3 is correct behavior,
 too.
 git-svn.perl |   26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/git-svn.perl b/git-svn.perl
index 7d86870..43e1591 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -782,9 +782,14 @@ sub cmd_info {
 	$result .= "Name: " . basename($path) . "\n" if $file_type ne "dir";
 	$result .= "URL: " . $full_url . "\n";
 
-	my $repos_root = $gs->ra->{repos_root};
-	Git::SVN::remove_username($repos_root);
-	$result .= "Repository Root: $repos_root\n";
+	eval {
+		my $repos_root = $gs->repos_root;
+		Git::SVN::remove_username($repos_root);
+		$result .= "Repository Root: $repos_root\n";
+	};
+	if ($@) {
+		$result .= "Repository Root: (offline)\n";
+	}
 	$result .= "Repository UUID: $uuid\n" unless $diff_status eq "A";
 	$result .= "Revision: " . ($diff_status eq "A" ? 0 : $rev) . "\n";
 
@@ -1773,9 +1778,24 @@ sub ra_uuid {
 	$self->{ra_uuid};
 }
 
+sub _set_repos_root {
+	my ($self, $repos_root) = @_;
+	my $k = "svn-remote.$self->{repo_id}.reposRoot";
+	$repos_root ||= $self->ra->{repos_root};
+	tmp_config($k, $repos_root);
+	$repos_root;
+}
+
+sub repos_root {
+	my ($self) = @_;
+	my $k = "svn-remote.$self->{repo_id}.reposRoot";
+	eval { tmp_config('--get', $k) } || $self->_set_repos_root;
+}
+
 sub ra {
 	my ($self) = shift;
 	my $ra = Git::SVN::Ra->new($self->{url});
+	$self->_set_repos_root($ra->{repos_root});
 	if ($self->use_svm_props && !$self->{svm}) {
 		if ($self->no_metadata) {
 			die "Can't have both 'noMetadata' and ",
-- 
Eric Wong
Previous: Eric WongNext: Adam Roben
Message 9 of 11 in “Implement git-svn info”
  1. 0/3 Implement git-svn infoDavid D. Kilzer, Nov 21, 2007
  2. 1/3 git-svn: extract reusable code into utility functionsDavid D. Kilzer, Nov 21, 2007
  3. 2/3 git-svn info: implement info commandDavid D. Kilzer, Nov 21, 2007
  4. 3/3 git-svn: info --url [path]David D. Kilzer, Nov 21, 2007
  5. Eric WongNov 22, 2007
  6. David D. KilzerNov 22, 2007
  7. Eric WongNov 22, 2007
  8. Eric WongNov 22, 2007
  9. 4/3 git-svn: allow `info' command to work offlineEric Wong, Nov 22, 2007
  10. Adam RobenNov 22, 2007
  11. Eric WongNov 22, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.