{"thread":{"id":"12917","subject":"[PATCH/RFC] git-cvsimport: When fetching a file and an error occurs, disconnect and retry","startedAt":"2008-03-30T01:50:07Z","lastAt":"2008-03-30T01:50:07Z","messageCount":1,"participants":["Michal Sojka"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"73348","messageId":"1206841808-24605-1-git-send-email-sojkam1@fel.cvut.cz","threadId":"12917","inReplyTo":null,"subject":"[PATCH/RFC] git-cvsimport: When fetching a file and an error occurs, disconnect and retry","fromName":"Michal Sojka","fromEmail":"sojkam1@fel.cvut.cz","sentAt":"2008-03-30T01:50:07Z","receivedAt":"2008-03-30T01:50:07Z","isPatch":true,"sender":{"key":"sojkam1@fel.cvut.cz","avatar":"https://avatars.githubusercontent.com/u/140542?v=4"},"body":"I imported my repositories from CVSNT server 1.11.1.3 and on some of\nthem import died with error like this:\n\nFetching libvideo\\libvideo/libvideo.dsp   v 1.1.1.1\nUnknown: error\n\nAfter some searching I have found that the reason is probably wrong\nnaming of my directories (i.e. directories with the same name at\ndifferent locations). I'm not CVS guru but guess that CVS server tracks\nwhat we are downloading and assumes that we are downloading all\nsubdirectories (at all levels) to one common directory. If more\nsubdirectories have the same name, it refuses to send the latter ones to\navoid overwriting the first one.\n\nThe dump of TCP communication was like this:\n\nC: Argument -N\nC: Argument -P\nC: Argument -r\nC: Argument 1.1\nC: Argument --\nC: Argument video/libvideo\\libvideo/libvideo.dsp\nC: Directory .\nC: /d//cvs\nC: co\nS: E cvs server: existing repository d:/cvs/video/libvideo does not match d:/cvs/video/libvideo\\libvideo\nS: E cvs server: ignoring module video/libvideo\\libvideo/libvideo.dsp\nS: error\n\nThis patch solved the problem for me. When the error is received,\ninstead of dying immediately, the connection is closed, then opened again\nand the second fetch attempt is executed.\n---\n git-cvsimport.perl |   11 +++++++----\n 1 files changed, 7 insertions(+), 4 deletions(-)\n\ndiff --git a/git-cvsimport.perl b/git-cvsimport.perl\nindex 95c5eec..b33ed53 100755\n--- a/git-cvsimport.perl\n+++ b/git-cvsimport.perl\n@@ -438,7 +438,10 @@ sub _line {\n \t\t\t\tdie \"Unknown: $line\" if $line ne \"ok\";\n \t\t\t\treturn -1;\n \t\t\t} else {\n-\t\t\t\tdie \"Unknown: $line\\n\";\n+\t\t\t\tSTDOUT->flush(); # To see which file cannot be fetched\n+\t\t\t\tprint STDERR \"Unexpected response: $line\\nDisconnecting and retrying...\\n\";\n+\t\t\t\t$self->{\"socketo\"}->close();\n+\t\t\t\treturn -2;\n \t\t\t}\n \t\t}\n \t}\n@@ -453,13 +456,13 @@ sub file {\n \n \t$self->_file($fn,$rev) and $res = $self->_line($fh);\n \n-\tif (!defined $res) {\n-\t    print STDERR \"Server has gone away while fetching $fn $rev, retrying...\\n\";\n+\tif (!defined $res || $res == -2) {\n+\t    print STDERR \"Server has gone away while fetching $fn $rev, retrying...\\n\" if !defined $res;\n \t    truncate $fh, 0;\n \t    $self->conn();\n \t    $self->_file($fn,$rev) or die \"No file command send\";\n \t    $res = $self->_line($fh);\n-\t    die \"Retry failed\" unless defined $res;\n+\t    die \"Retry failed\" unless (defined $res && $res != -2);\n \t}\n \tclose ($fh);\n \n-- \n1.5.4.5\n"}]}