Re: git-cvs-import retries

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: git-cvs-import retries

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:19

Martin Mares [off-list ref] writes:
But it did and I finally understand why: _line() can exit not only
by return, but also by falling over when readline() returns undef.
Ah, you are right and I feel stupid.  It's been a while since I
wrote real Perl code the last time, and forgot that "the last
evaluation" rule when I was reading the code.

It did not help that one of the languages I use in my day-job
(which I am too ashamed to even name) uses "if fell off at the
end return undef" rule X-<.

[PATCH] Fix retries in git-cvsimport

From: Martin Mares <mj@ucw.cz>
Date: 2016-06-15 22:42:19

Fixed a couple of bugs in recovering from broken connections:

The _line() method now returns undef correctly when the connection
is broken instead of falling off the function and returning garbage.

Retries are now reported to stderr and the eventual partially
downloaded file is discarded instead of being appended to.

The "Server gone away" test has been removed, because it was
reachable only if the garbage return bug bit.

Signed-Off-By: Martin Mares <mj@ucw.cz>
--- old/git-cvsimport	2006-02-17 13:02:24.000000000 +0100
+++ new/git-cvsimport	2006-02-18 14:16:33.000000000 +0100
@@ -361,6 +361,7 @@
 			}
 		}
 	}
+	return undef;
 }
 sub file {
 	my($self,$fn,$rev) = @_;
@@ -372,19 +373,15 @@
 	$self->_file($fn,$rev) and $res = $self->_line($fh);
 
 	if (!defined $res) {
-	    # retry
+	    print STDERR "Server has gone away while fetching $fn $rev, retrying...\n";
+	    truncate $fh, 0;
 	    $self->conn();
-	    $self->_file($fn,$rev)
-		    or die "No file command send\n";
+	    $self->_file($fn,$rev) or die "No file command send";
 	    $res = $self->_line($fh);
-	    die "No input: $fn $rev\n" unless defined $res;
+	    die "Retry failed" unless defined $res;
 	}
 	close ($fh);
 
-	if ($res eq '') {
-	    die "Looks like the server has gone away while fetching $fn $rev -- exiting!";
-	}
-
 	return ($name, $res);
 }
 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help