threads / rfc / 12917

RFC patchgit-cvsimport: When fetching a file and an error occurs, disconnect and retry

Subject: [PATCH/RFC] git-cvsimport: When fetching a file and an error occurs, disconnect and retry

## tl;dr

One message between Mar 30, 2008 and Mar 30, 2008. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Michal Sojka· Mar 30, 2008, 01:50 UTC · lore

I imported my repositories from CVSNT server 1.11.1.3 and on some of them import died with error like this:

Fetching libvideo\libvideo/libvideo.dsp   v 1.1.1.1
Unknown: error

After some searching I have found that the reason is probably wrong naming of my directories (i.e. directories with the same name at different locations). I'm not CVS guru but guess that CVS server tracks what we are downloading and assumes that we are downloading all subdirectories (at all levels) to one common directory. If more subdirectories have the same name, it refuses to send the latter ones to avoid overwriting the first one.

The dump of TCP communication was like this:
C: Argument -N
C: Argument -P
C: Argument -r
C: Argument 1.1
C: Argument --
C: Argument video/libvideo\libvideo/libvideo.dsp
C: Directory .
C: /d//cvs
C: co
S: E cvs server: existing repository d:/cvs/video/libvideo does not match d:/cvs/video/libvideo\libvideo
S: E cvs server: ignoring module video/libvideo\libvideo/libvideo.dsp
S: error
This patch solved the problem for me. When the error is received,
instead of dying immediately, the connection is closed, then opened again
and the second fetch attempt is executed.
---
 git-cvsimport.perl |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
Show changes to git-cvsimport.perl +7 −4
diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index 95c5eec..b33ed53 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -438,7 +438,10 @@ sub _line {
 				die "Unknown: $line" if $line ne "ok";
 				return -1;
 			} else {
-				die "Unknown: $line\n";
+				STDOUT->flush(); # To see which file cannot be fetched
+				print STDERR "Unexpected response: $line\nDisconnecting and retrying...\n";
+				$self->{"socketo"}->close();
+				return -2;
 			}
 		}
 	}
@@ -453,13 +456,13 @@ sub file {
 
 	$self->_file($fn,$rev) and $res = $self->_line($fh);
 
-	if (!defined $res) {
-	    print STDERR "Server has gone away while fetching $fn $rev, retrying...\n";
+	if (!defined $res || $res == -2) {
+	    print STDERR "Server has gone away while fetching $fn $rev, retrying...\n" if !defined $res;
 	    truncate $fh, 0;
 	    $self->conn();
 	    $self->_file($fn,$rev) or die "No file command send";
 	    $res = $self->_line($fh);
-	    die "Retry failed" unless defined $res;
+	    die "Retry failed" unless (defined $res && $res != -2);
 	}
 	close ($fh);
 
-- 
1.5.4.5

← back to recent threads