Trivial support for cloning and fetching via ftp://.
PATCH 1/1 Trivial support for cloning and fetching via ftp://.
This adds trivial support for cloning and fetching via ftp://.
--- git-clone.sh | 2 +- git-fetch.sh | 4 ++-- git-ls-remote.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
git-clone.sh +1 -1
@@ -298,7 +298,7 @@ yes,yes) fi git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD" || exit 1 ;; - https://*|http://*) + https://*|http://*|ftp://*) if test -z "@@NO_CURL@@" then clone_dumb_http "$repo" "$D"
git-fetch.sh +2 -2
@@ -286,7 +286,7 @@ fetch_main () { # There are transports that can fetch only one head at a time... case "$remote" in - http://* | https://*) + http://* | https://* | ftp://*) if [ -n "$GIT_SSL_NO_VERIFY" ]; then curl_extra_args="-k" fi
@@ -350,7 +350,7 @@ fetch_main () { done case "$remote" in - http://* | https://* | rsync://* ) + http://* | https://* | ftp://* | rsync://* ) ;; # we are already done. *) ( : subshell because we muck with IFS
git-ls-remote.sh +1 -1
@@ -49,7 +49,7 @@ trap "rm -fr $tmp-*" 0 1 2 3 15 tmpdir=$tmp-d case "$peek_repo" in -http://* | https://* ) +http://* | https://* | ftp://* ) if [ -n "$GIT_SSL_NO_VERIFY" ]; then curl_extra_args="-k" fi
Signature · 1 line
1.4.2.gffe87-dirty
Quoted 1 line · Sasha Khapyorsky
This adds trivial support for cloning and fetching via ftp://.
Interesting.
I was wondering myself if our use of curl libraries in http-fetch allows us to do this when I was looking at the alternates breakage yesterday.
At a few places we do look at http error code that is returned from the curl library, and change our behaviour based on that. But it appears the difference between error code from ftp and http has no bad effect on us. In an empty repository, we can run this:
$ git-http-fetch -a -v heads/merge \ ftp://ftp.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git
(of course, this should normally be with http://www.kernel.org).
We notice that we get an error from a request for one object, and switch to pack & alternates transfer. The only difference between http://www and ftp://ftp is that for the former we know error code 404 and supress the error message but for the latter we do not treat error 550 from RETR response any specially and show an error message. We still fall back to retrieve packs, hoping that the missing object is in a pack.
I'd take this patch as is, but we might want to add some error message supression logic just like we do for http.
Quoted 28 lines · Junio C Hamano
Quoted 1 line · Sasha Khapyorsky
This adds trivial support for cloning and fetching via ftp://.
Interesting.
I was wondering myself if our use of curl libraries in http-fetch allows us to do this when I was looking at the alternates breakage yesterday.
At a few places we do look at http error code that is returned from the curl library, and change our behaviour based on that. But it appears the difference between error code from ftp and http has no bad effect on us. In an empty repository, we can run this:
$ git-http-fetch -a -v heads/merge \ ftp://ftp.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git(of course, this should normally be with http://www.kernel.org).
We notice that we get an error from a request for one object, and switch to pack & alternates transfer. The only difference between http://www and ftp://ftp is that for the former we know error code 404 and supress the error message but for the latter we do not treat error 550 from RETR response any specially and show an error message. We still fall back to retrieve packs, hoping that the missing object is in a pack.
Quoted 2 lines
I'd take this patch as is, but we might want to add some error message supression logic just like we do for http.
Something like this?
With this change I'm able to clone ftp://ftp.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git
http-fetch.c +12 -4
@@ -324,7 +324,9 @@ static void process_object_response(void/* Use alternates if necessary */ if (obj_req->http_code ==404 || - obj_req->curl_result ==CURLE_FILE_COULDNT_READ_FILE ) { + obj_req->curl_result ==CURLE_FILE_COULDNT_READ_FILE || + (obj_req->http_code ==550 && + obj_req->curl_result ==CURLE_FTP_COULDNT_RETR_FILE )) {fetch_alternates (alt->base);if (obj_req->repo->next !=NULL ) { obj_req->repo =
@@ -538,7 +540,9 @@ static void process_alternates_response( } }else if (slot->curl_result !=CURLE_OK ) {if (slot->http_code !=404 && - slot->curl_result !=CURLE_FILE_COULDNT_READ_FILE ) { + slot->curl_result !=CURLE_FILE_COULDNT_READ_FILE && + (slot->http_code !=550 && + slot->curl_result !=CURLE_FTP_COULDNT_RETR_FILE )) { got_alternates =-1 ;return ; }
@@ -942,7 +946,9 @@ #endifrun_active_slot (slot);if (results.curl_result !=CURLE_OK ) {if (results.http_code ==404 || - results.curl_result ==CURLE_FILE_COULDNT_READ_FILE ) { + results.curl_result ==CURLE_FILE_COULDNT_READ_FILE || + (results.http_code ==550 && + results.curl_result ==CURLE_FTP_COULDNT_RETR_FILE )) { repo->got_indices =1 ;free (buffer.buffer);return 0 ;
@@ -1124,7 +1130,9 @@ #endif }else if (obj_req->curl_result !=CURLE_OK && obj_req->http_code !=416 ) {if (obj_req->http_code ==404 || - obj_req->curl_result ==CURLE_FILE_COULDNT_READ_FILE ) + obj_req->curl_result ==CURLE_FILE_COULDNT_READ_FILE || + (obj_req->http_code ==550 && + obj_req->curl_result ==CURLE_FTP_COULDNT_RETR_FILE )) ret =-1 ;/* Be silent, it is probably in a pack. */ else ret = error("%s (curl_result = %d, http_code = %ld, sha1 = %s)",
Quoted 4 lines · Sasha Khapyorsky
Something like this?
With this change I'm able to clone ftp://ftp.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git
I think without you would have, just with extra error messages that http codepath filters out.
http-fetch.c static void process_object_response(void · line 329
Quoted 12 lines
http-fetch.c +3
-1@@ -324,7 +324,9 @@ static void process_object_response(void/* Use alternates if necessary */ if (obj_req->http_code ==404 || - obj_req->curl_result ==CURLE_FILE_COULDNT_READ_FILE ) { + obj_req->curl_result ==CURLE_FILE_COULDNT_READ_FILE || + (obj_req->http_code ==550 && + obj_req->curl_result ==CURLE_FTP_COULDNT_RETR_FILE )) {
Here you do the same as the code would for HTTP 404 when you get 550 _and_ RETR failure...
http-fetch.c static void process_alternates_response( · line 546
Quoted 9 lines
http-fetch.c +3
-1@@ -538,7 +540,9 @@ static void process_alternates_response( } }else if (slot->curl_result !=CURLE_OK ) {if (slot->http_code !=404 && - slot->curl_result !=CURLE_FILE_COULDNT_READ_FILE ) { + slot->curl_result !=CURLE_FILE_COULDNT_READ_FILE && + (slot->http_code !=550 && + slot->curl_result !=CURLE_FTP_COULDNT_RETR_FILE )) { got_alternates =-1 ;
... but you say, while the original code says "declare error if it is not HTTP 404", "oh by the way, if it is 550 _or_ if it is RETR failure then do not trigger this if()". I suspect you meant to say this?
(slot->http_code != 550 ||
slot->curl_result != CURLE_FTP_COULDNT_RETR_FILE)) {Quoted 9 lines · Junio C Hamano
Quoted 4 lines · Sasha Khapyorsky
Something like this?
With this change I'm able to clone ftp://ftp.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git
I think without you would have, just with extra error messages that http codepath filters out.
No, not really, without change it fails later:
$ git-clone ftp://ftp.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git error: RETR response: 550 (curl_result = 19, http_code = 550, sha1 = 63b98080daa35f0d682db04f4fb7ada010888752) Getting pack list for ftp://ftp.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git/ Getting alternates list for ftp://ftp.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git/ Also look at ftp://ftp.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git/ Getting pack list for ftp://ftp.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git/ Getting index for pack 477061883bee3d10bece6e3432355b61ba02e594 error: Unable to find 63b98080daa35f0d682db04f4fb7ada010888752 under ftp://ftp.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git/ Cannot obtain needed none 63b98080daa35f0d682db04f4fb7ada010888752 while processing commit 0000000000000000000000000000000000000000.
Quoted 32 lines
http-fetch.c static void process_object_response(void · line 329
Quoted 13 lines
http-fetch.c +3
-1@@ -324,7 +324,9 @@ static void process_object_response(void/* Use alternates if necessary */ if (obj_req->http_code ==404 || - obj_req->curl_result ==CURLE_FILE_COULDNT_READ_FILE ) { + obj_req->curl_result ==CURLE_FILE_COULDNT_READ_FILE || + (obj_req->http_code ==550 && + obj_req->curl_result ==CURLE_FTP_COULDNT_RETR_FILE )) {Here you do the same as the code would for HTTP 404 when you get 550 _and_ RETR failure...
http-fetch.c static void process_alternates_response( · line 546
Quoted 9 lines
http-fetch.c +3
-1@@ -538,7 +540,9 @@ static void process_alternates_response( } }else if (slot->curl_result !=CURLE_OK ) {if (slot->http_code !=404 && - slot->curl_result !=CURLE_FILE_COULDNT_READ_FILE ) { + slot->curl_result !=CURLE_FILE_COULDNT_READ_FILE && + (slot->http_code !=550 && + slot->curl_result !=CURLE_FTP_COULDNT_RETR_FILE )) { got_alternates =-1 ;... but you say, while the original code says "declare error if it is not HTTP 404", "oh by the way, if it is 550 _or_ if it is RETR failure then do not trigger this
if()". I suspect you meant to say this?
Quoted 2 lines
(slot->http_code != 550 ||
slot->curl_result != CURLE_FTP_COULDNT_RETR_FILE)) {I think with less strict checking this could be done so, but with _and_ this also ensures that we are really in FTP mode.
Sasha
Quoted 56 lines · Sasha Khapyorsky
Quoted 9 lines · Junio C Hamano
Quoted 4 lines · Sasha Khapyorsky
Something like this?
With this change I'm able to clone ftp://ftp.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git
I think without you would have, just with extra error messages that http codepath filters out.
No, not really, without change it fails later:
$ git-clone ftp://ftp.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git error: RETR response: 550 (curl_result = 19, http_code = 550, sha1 = 63b98080daa35f0d682db04f4fb7ada010888752) Getting pack list for ftp://ftp.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git/ Getting alternates list for ftp://ftp.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git/ Also look at ftp://ftp.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git/ Getting pack list for ftp://ftp.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git/ Getting index for pack 477061883bee3d10bece6e3432355b61ba02e594 error: Unable to find 63b98080daa35f0d682db04f4fb7ada010888752 under ftp://ftp.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git/ Cannot obtain needed none 63b98080daa35f0d682db04f4fb7ada010888752 while processing commit 0000000000000000000000000000000000000000.Quoted 32 lines
http-fetch.c static void process_object_response(void · line 329
Quoted 13 lines
http-fetch.c +3
-1@@ -324,7 +324,9 @@ static void process_object_response(void/* Use alternates if necessary */ if (obj_req->http_code ==404 || - obj_req->curl_result ==CURLE_FILE_COULDNT_READ_FILE ) { + obj_req->curl_result ==CURLE_FILE_COULDNT_READ_FILE || + (obj_req->http_code ==550 && + obj_req->curl_result ==CURLE_FTP_COULDNT_RETR_FILE )) {Here you do the same as the code would for HTTP 404 when you get 550 _and_ RETR failure...
http-fetch.c static void process_alternates_response( · line 546
Quoted 9 lines
http-fetch.c +3
-1@@ -538,7 +540,9 @@ static void process_alternates_response( } }else if (slot->curl_result !=CURLE_OK ) {if (slot->http_code !=404 && - slot->curl_result !=CURLE_FILE_COULDNT_READ_FILE ) { + slot->curl_result !=CURLE_FILE_COULDNT_READ_FILE && + (slot->http_code !=550 && + slot->curl_result !=CURLE_FTP_COULDNT_RETR_FILE )) { got_alternates =-1 ;... but you say, while the original code says "declare error if it is not HTTP 404", "oh by the way, if it is 550 _or_ if it is RETR failure then do not trigger this
if()". I suspect you meant to say this?
Quoted 5 lines
Quoted 2 lines
(slot->http_code != 550 || slot->curl_result != CURLE_FTP_COULDNT_RETR_FILE)) {I think with less strict checking this could be done so, but with _and_ this also ensures that we are really in FTP mode.
Hmm, saying this I see that original code doesn't do it for specific case. So for this case we could do:
!(slot->http_code == 550 &&
slot->curl_result == CURLE_FTP_COULDNT_RETR_FILE)) {
Sasha
Quoted 31 lines · Sasha Khapyorsky
Quoted 31 lines
http-fetch.c static void process_object_response(void · line 329
Quoted 12 lines
http-fetch.c +3
-1@@ -324,7 +324,9 @@ static void process_object_response(void/* Use alternates if necessary */ if (obj_req->http_code ==404 || - obj_req->curl_result ==CURLE_FILE_COULDNT_READ_FILE ) { + obj_req->curl_result ==CURLE_FILE_COULDNT_READ_FILE || + (obj_req->http_code ==550 && + obj_req->curl_result ==CURLE_FTP_COULDNT_RETR_FILE )) {Here you do the same as the code would for HTTP 404 when you get 550 _and_ RETR failure...
http-fetch.c static void process_alternates_response( · line 546
Quoted 9 lines
http-fetch.c +3
-1@@ -538,7 +540,9 @@ static void process_alternates_response( } }else if (slot->curl_result !=CURLE_OK ) {if (slot->http_code !=404 && - slot->curl_result !=CURLE_FILE_COULDNT_READ_FILE ) { + slot->curl_result !=CURLE_FILE_COULDNT_READ_FILE && + (slot->http_code !=550 && + slot->curl_result !=CURLE_FTP_COULDNT_RETR_FILE )) { got_alternates =-1 ;... but you say, while the original code says "declare error if it is not HTTP 404", "oh by the way, if it is 550 _or_ if it is RETR failure then do not trigger this
if()". I suspect you meant to say this?
Quoted 5 lines
Quoted 2 lines
(slot->http_code != 550 || slot->curl_result != CURLE_FTP_COULDNT_RETR_FILE)) {I think with less strict checking this could be done so, but with _and_ this also ensures that we are really in FTP mode.
I was merely pointing out that in one place you have:
(http_code == 550 && result == ERETR)
and another place that tries to say the opposite you have:
(http_code != 550 && result != ERETR)
which is not the same thing as
!(http_code == 550 && result == ERETR)
I understood, from the former "Use alternates if necessary" part, that you wanted to make sure that 550 is really from FTP_RETR and not other random HTTP error message, and I think that is a reasonable thing to do.
Quoted 47 lines · Junio C Hamano
Quoted 31 lines · Sasha Khapyorsky
Quoted 31 lines
http-fetch.c static void process_object_response(void · line 329
Quoted 12 lines
http-fetch.c +3
-1@@ -324,7 +324,9 @@ static void process_object_response(void/* Use alternates if necessary */ if (obj_req->http_code ==404 || - obj_req->curl_result ==CURLE_FILE_COULDNT_READ_FILE ) { + obj_req->curl_result ==CURLE_FILE_COULDNT_READ_FILE || + (obj_req->http_code ==550 && + obj_req->curl_result ==CURLE_FTP_COULDNT_RETR_FILE )) {Here you do the same as the code would for HTTP 404 when you get 550 _and_ RETR failure...
http-fetch.c static void process_alternates_response( · line 546
Quoted 9 lines
http-fetch.c +3
-1@@ -538,7 +540,9 @@ static void process_alternates_response( } }else if (slot->curl_result !=CURLE_OK ) {if (slot->http_code !=404 && - slot->curl_result !=CURLE_FILE_COULDNT_READ_FILE ) { + slot->curl_result !=CURLE_FILE_COULDNT_READ_FILE && + (slot->http_code !=550 && + slot->curl_result !=CURLE_FTP_COULDNT_RETR_FILE )) { got_alternates =-1 ;... but you say, while the original code says "declare error if it is not HTTP 404", "oh by the way, if it is 550 _or_ if it is RETR failure then do not trigger this
if()". I suspect you meant to say this?Quoted 5 lines
Quoted 2 lines
(slot->http_code != 550 || slot->curl_result != CURLE_FTP_COULDNT_RETR_FILE)) {I think with less strict checking this could be done so, but with _and_ this also ensures that we are really in FTP mode.
I was merely pointing out that in one place you have:
(http_code == 550 && result == ERETR)and another place that tries to say the opposite you have:
(http_code != 550 && result != ERETR)
Quoted 8 lines
which is not the same thing as
!(http_code == 550 && result == ERETR)I understood, from the former "Use alternates if necessary" part, that you wanted to make sure that 550 is really from
FTP_RETRand not other random HTTP error message, and I think that is a reasonable thing to do.
Good. Am I need to send the patch or you will integrate it?
Sasha
Quoted 1 line · Sasha Khapyorsky
Good. Am I need to send the patch or you will integrate it?
Actually, I am thinking of doing this in two steps.
The attached is the first "clean-up" step, which should be obvious enough.
And you already know what the second one that would come on top of this should look like ;-).
-- >8 --http-fetch.c: consolidate code to detect missing fetch target
At a handful places we check two error codes from curl library to see if the file we asked was missing from the remote (e.g. we asked for a loose object when it is in a pack) to decide what to do next. This consolidates the check into a single function.
---
http-fetch.c +17 -8
@@ -144,6 +144,19 @@ static size_t fwrite_sha1_file(void *ptrreturn size; } +static int missing__target (int code,int result) +{ +return /* file:// URL -- do we ever use one??? */ + (result ==CURLE_FILE_COULDNT_READ_FILE ) || +/* http:// and https:// URL */ + (code ==404 && result ==CURLE_HTTP_RETURNED_ERROR ) || +/* ftp:// URL */ + (code ==550 && result ==CURLE_FTP_COULDNT_RETR_FILE ) + ; +} + +#define missing_target (a) missing__target((a)->http_code, (a)->curl_result) +static void fetch_alternates (const char *base);static void process_object_response (void *callback_data);
@@ -323,8 +336,7 @@ static void process_object_response(void obj_req->state =COMPLETE ;/* Use alternates if necessary */ -if (obj_req->http_code ==404 || - obj_req->curl_result ==CURLE_FILE_COULDNT_READ_FILE ) { +if (missing_target (obj_req)) {fetch_alternates (alt->base);if (obj_req->repo->next !=NULL ) { obj_req->repo =
@@ -537,8 +549,7 @@ static void process_alternates_response(return ; } }else if (slot->curl_result !=CURLE_OK ) { -if (slot->http_code !=404 && - slot->curl_result !=CURLE_FILE_COULDNT_READ_FILE ) { +if (!missing_target (slot)) { got_alternates =-1 ;return ; }
@@ -941,8 +952,7 @@ #endifif (start_active_slot (slot)) {run_active_slot (slot);if (results.curl_result !=CURLE_OK ) { -if (results.http_code ==404 || - results.curl_result ==CURLE_FILE_COULDNT_READ_FILE ) { +if (missing_target (&results)) { repo->got_indices =1 ;free (buffer.buffer);return 0 ;
@@ -1123,8 +1133,7 @@ #endif ret =error ("Request for %s aborted" , hex); }else if (obj_req->curl_result !=CURLE_OK && obj_req->http_code !=416 ) { -if (obj_req->http_code ==404 || - obj_req->curl_result ==CURLE_FILE_COULDNT_READ_FILE ) +if (missing_target (obj_req)) ret =-1 ;/* Be silent, it is probably in a pack. */ else ret = error("%s (curl_result = %d, http_code = %ld, sha1 = %s)",
Quoted 11 lines · Junio C Hamano
Quoted 1 line · Sasha Khapyorsky
Good. Am I need to send the patch or you will integrate it?
Actually, I am thinking of doing this in two steps.
The attached is the first "clean-up" step, which should be obvious enough.
And you already know what the second one that would come on top of this should look like ;-).
Oops, thinko. I sent a rolled-up one out.
Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Junio C Hamano
Quoted 1 line · Sasha Khapyorsky
Good. Am I need to send the patch or you will integrate it?
Actually, I am thinking of doing this in two steps.
Quoted 7 lines
Quoted 5 lines
The attached is the first "clean-up" step, which should be obvious enough.
And you already know what the second one that would come on top of this should look like ;-).
Oops, thinko. I sent a rolled-up one out.
Yes, and it looks good. Thanks :)
Sasha