{"thread":{"id":"10961","subject":"[PATCH RFC] Use \"git fetch\" when cloning","startedAt":"2007-11-21T15:40:13Z","lastAt":"2007-11-21T16:04:53Z","messageCount":2,"participants":["Santi Béjar","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"60532","messageId":"1195659613-5290-1-git-send-email-sbejar@gmail.com","threadId":"10961","inReplyTo":null,"subject":"[PATCH RFC] Use \"git fetch\" when cloning","fromName":"Santi Béjar","fromEmail":"sbejar@gmail.com","sentAt":"2007-11-21T15:40:13Z","receivedAt":"2007-11-21T15:40:13Z","isPatch":true,"sender":{"key":"santi@agolina.net","avatar":null},"body":"With this all the \"git fetch\" supported protocols are automatically\nsupported by \"git clone\", in particular bundle files.\n\nThere are two more changes:\n\n1) It always use \"git fetch\" even if local. So now it checks the validity\n   of the new repo, in particular it does not create a broken repository\n   when there are too many nested alternates.\n\n2) It connects with the remote repo when fetching the branches/tags\n   and the remote HEAD.\n\n3) The quiet mode of \"git fetch\" prints the changed branches/tags, so \"git clone\"\n   prints always the new branches/tags.\n---\n git-clone.sh              |  178 +++++++--------------------------------------\n t/t5710-info-alternate.sh |    2 +-\n 2 files changed, 27 insertions(+), 153 deletions(-)\n\ndiff --git a/git-clone.sh b/git-clone.sh\nindex 3f00693..ed8efc1 100755\n--- a/git-clone.sh\n+++ b/git-clone.sh\n@@ -28,68 +28,6 @@ get_repo_base() {\n \t) 2>/dev/null\n }\n \n-if [ -n \"$GIT_SSL_NO_VERIFY\" -o \\\n-\t\"`git config --bool http.sslVerify`\" = false ]; then\n-    curl_extra_args=\"-k\"\n-fi\n-\n-http_fetch () {\n-\t# $1 = Remote, $2 = Local\n-\tcurl -nsfL $curl_extra_args \"$1\" >\"$2\" ||\n-\t\tcase $? in\n-\t\t126|127) exit ;;\n-\t\t*)\t return $? ;;\n-\t\tesac\n-}\n-\n-clone_dumb_http () {\n-\t# $1 - remote, $2 - local\n-\tcd \"$2\" &&\n-\tclone_tmp=\"$GIT_DIR/clone-tmp\" &&\n-\tmkdir -p \"$clone_tmp\" || exit 1\n-\tif [ -n \"$GIT_CURL_FTP_NO_EPSV\" -o \\\n-\t\t\"`git config --bool http.noEPSV`\" = true ]; then\n-\t\tcurl_extra_args=\"${curl_extra_args} --disable-epsv\"\n-\tfi\n-\thttp_fetch \"$1/info/refs\" \"$clone_tmp/refs\" ||\n-\t\tdie \"Cannot get remote repository information.\n-Perhaps git-update-server-info needs to be run there?\"\n-\ttest \"z$quiet\" = z && v=-v || v=\n-\twhile read sha1 refname\n-\tdo\n-\t\tname=`expr \"z$refname\" : 'zrefs/\\(.*\\)'` &&\n-\t\tcase \"$name\" in\n-\t\t*^*)\tcontinue;;\n-\t\tesac\n-\t\tcase \"$bare,$name\" in\n-\t\tyes,* | ,heads/* | ,tags/*) ;;\n-\t\t*)\tcontinue ;;\n-\t\tesac\n-\t\tif test -n \"$use_separate_remote\" &&\n-\t\t   branch_name=`expr \"z$name\" : 'zheads/\\(.*\\)'`\n-\t\tthen\n-\t\t\ttname=\"remotes/$origin/$branch_name\"\n-\t\telse\n-\t\t\ttname=$name\n-\t\tfi\n-\t\tgit-http-fetch $v -a -w \"$tname\" \"$sha1\" \"$1\" || exit 1\n-\tdone <\"$clone_tmp/refs\"\n-\trm -fr \"$clone_tmp\"\n-\thttp_fetch \"$1/HEAD\" \"$GIT_DIR/REMOTE_HEAD\" ||\n-\trm -f \"$GIT_DIR/REMOTE_HEAD\"\n-\tif test -f \"$GIT_DIR/REMOTE_HEAD\"; then\n-\t\thead_sha1=`cat \"$GIT_DIR/REMOTE_HEAD\"`\n-\t\tcase \"$head_sha1\" in\n-\t\t'ref: refs/'*)\n-\t\t\t;;\n-\t\t*)\n-\t\t\tgit-http-fetch $v -a \"$head_sha1\" \"$1\" ||\n-\t\t\trm -f \"$GIT_DIR/REMOTE_HEAD\"\n-\t\t\t;;\n-\t\tesac\n-\tfi\n-}\n-\n quiet=\n local=no\n use_local_hardlink=yes\n@@ -197,6 +135,8 @@ if base=$(get_repo_base \"$repo\"); then\n \tlocal=yes\n fi\n \n+export GIT_REFLOG_ACTION=\"clone: from $repo\"\n+\n dir=\"$2\"\n # Try using \"humanish\" part of source repo if user didn't specify one\n [ -z \"$dir\" ] && dir=$(echo \"$repo\" | sed -e 's|/$||' -e 's|:*/*\\.git$||' -e 's|.*[/:]||g')\n@@ -265,8 +205,6 @@ then\n \tfi\n fi\n \n-rm -f \"$GIT_DIR/CLONE_HEAD\"\n-\n # We do local magic only when the user tells us to.\n case \"$local\" in\n yes)\n@@ -299,105 +237,41 @@ yes)\n \t\tcd \"$repo\" &&\n \t\tfind objects -depth -print | cpio -pumd$l \"$GIT_DIR/\" || exit 1\n \tfi\n-\tgit-ls-remote \"$repo\" >\"$GIT_DIR/CLONE_HEAD\" || exit 1\n-\t;;\n-*)\n-\tcase \"$repo\" in\n-\trsync://*)\n-\t\tcase \"$depth\" in\n-\t\t\"\") ;;\n-\t\t*) die \"shallow over rsync not supported\" ;;\n-\t\tesac\n-\t\trsync $quiet -av --ignore-existing  \\\n-\t\t\t--exclude info \"$repo/objects/\" \"$GIT_DIR/objects/\" ||\n-\t\texit\n-\t\t# Look at objects/info/alternates for rsync -- http will\n-\t\t# support it natively and git native ones will do it on the\n-\t\t# remote end.  Not having that file is not a crime.\n-\t\trsync -q \"$repo/objects/info/alternates\" \\\n-\t\t\t\"$GIT_DIR/TMP_ALT\" 2>/dev/null ||\n-\t\t\trm -f \"$GIT_DIR/TMP_ALT\"\n-\t\tif test -f \"$GIT_DIR/TMP_ALT\"\n-\t\tthen\n-\t\t    ( cd \"$D\" &&\n-\t\t      . git-parse-remote &&\n-\t\t      resolve_alternates \"$repo\" <\"$GIT_DIR/TMP_ALT\" ) |\n-\t\t    while read alt\n-\t\t    do\n-\t\t\tcase \"$alt\" in 'bad alternate: '*) die \"$alt\";; esac\n-\t\t\tcase \"$quiet\" in\n-\t\t\t'')\techo >&2 \"Getting alternate: $alt\" ;;\n-\t\t\tesac\n-\t\t\trsync $quiet -av --ignore-existing  \\\n-\t\t\t    --exclude info \"$alt\" \"$GIT_DIR/objects\" || exit\n-\t\t    done\n-\t\t    rm -f \"$GIT_DIR/TMP_ALT\"\n-\t\tfi\n-\t\tgit-ls-remote \"$repo\" >\"$GIT_DIR/CLONE_HEAD\" || exit 1\n-\t\t;;\n-\thttps://*|http://*|ftp://*)\n-\t\tcase \"$depth\" in\n-\t\t\"\") ;;\n-\t\t*) die \"shallow over http or ftp not supported\" ;;\n-\t\tesac\n-\t\tif test -z \"@@NO_CURL@@\"\n-\t\tthen\n-\t\t\tclone_dumb_http \"$repo\" \"$D\"\n-\t\telse\n-\t\t\tdie \"http transport not supported, rebuild Git with curl support\"\n-\t\tfi\n-\t\t;;\n-\t*)\n-\t\tcase \"$upload_pack\" in\n-\t\t'') git-fetch-pack --all -k $quiet $depth $no_progress \"$repo\";;\n-\t\t*) git-fetch-pack --all -k $quiet \"$upload_pack\" $depth $no_progress \"$repo\" ;;\n-\t\tesac >\"$GIT_DIR/CLONE_HEAD\" ||\n-\t\t\tdie \"fetch-pack from '$repo' failed.\"\n-\t\t;;\n-\tesac\n-\t;;\n esac\n-test -d \"$GIT_DIR/refs/reference-tmp\" && rm -fr \"$GIT_DIR/refs/reference-tmp\"\n \n-if test -f \"$GIT_DIR/CLONE_HEAD\"\n+if [ -n \"$use_separate_remote\" ]\n then\n-\t# Read git-fetch-pack -k output and store the remote branches.\n-\tif [ -n \"$use_separate_remote\" ]\n-\tthen\n-\t\tbranch_top=\"remotes/$origin\"\n-\telse\n-\t\tbranch_top=\"heads\"\n-\tfi\n-\ttag_top=\"tags\"\n-\twhile read sha1 name\n-\tdo\n-\t\tcase \"$name\" in\n-\t\t*'^{}')\n-\t\t\tcontinue ;;\n-\t\tHEAD)\n-\t\t\tdestname=\"REMOTE_HEAD\" ;;\n-\t\trefs/heads/*)\n-\t\t\tdestname=\"refs/$branch_top/${name#refs/heads/}\" ;;\n-\t\trefs/tags/*)\n-\t\t\tdestname=\"refs/$tag_top/${name#refs/tags/}\" ;;\n-\t\t*)\n-\t\t\tcontinue ;;\n-\t\tesac\n-\t\tgit update-ref -m \"clone: from $repo\" \"$destname\" \"$sha1\" \"\"\n-\tdone < \"$GIT_DIR/CLONE_HEAD\"\n+\tremote_top=\"refs/remotes/$origin\"\n+else\n+\tremote_top=\"refs/heads\"\n fi\n \n+case \"$repo\" in\n+https://*|http://*|ftp://*|rsync://*) keep=;;\n+*) keep=-k\n+esac\n+\n+case \"$upload_pack\" in\n+'') git fetch $keep --tags $quiet $depth \"$repo\" \"+refs/heads/*:$remote_top/*\";;\n+*) git fetch $keep --tags $quiet $depth \"$upload_pack\" \"$repo\" \"+refs/heads/*:$remote_top/*\"\n+esac || die \"fetch from '$repo' failed.\"\n+\n+test -d \"$GIT_DIR/refs/reference-tmp\" && rm -fr \"$GIT_DIR/refs/reference-tmp\"\n+\n if test -n \"$W\"; then\n \tcd \"$W\" || exit\n else\n \tcd \"$D\" || exit\n fi\n \n-if test -z \"$bare\" && test -f \"$GIT_DIR/REMOTE_HEAD\"\n+head_sha1=`\n+\tcase \"$upload_pack\" in\n+\t'') git ls-remote \"$repo\" ;;\n+\t*) git ls-remote \"$upload_pack\" \"$repo\"\n+\tesac  2>/dev/null | awk '{if ($2==\"HEAD\") print $1;}'`\n+\n+if test -z \"$bare\" && test -n \"$head_sha1\"\n then\n-\t# a non-bare repository is always in separate-remote layout\n-\tremote_top=\"refs/remotes/$origin\"\n-\thead_sha1=`cat \"$GIT_DIR/REMOTE_HEAD\"`\n \tcase \"$head_sha1\" in\n \t'ref: refs/'*)\n \t\t# Uh-oh, the remote told us (http transport done against\n@@ -466,6 +340,6 @@ then\n \t\tgit read-tree -m -u $v HEAD HEAD\n \tesac\n fi\n-rm -f \"$GIT_DIR/CLONE_HEAD\" \"$GIT_DIR/REMOTE_HEAD\"\n+rm -f \"$GIT_DIR/FETCH_HEAD\"\n \n trap - 0\ndiff --git a/t/t5710-info-alternate.sh b/t/t5710-info-alternate.sh\nindex 699df6e..9b7f638 100755\n--- a/t/t5710-info-alternate.sh\n+++ b/t/t5710-info-alternate.sh\n@@ -53,7 +53,7 @@ git prune'\n \n cd \"$base_dir\"\n \n-test_expect_failure 'creating too deep nesting' \\\n+test_expect_success 'creating too deep nesting' \\\n 'git clone -l -s C D &&\n git clone -l -s D E &&\n git clone -l -s E F &&\n-- \n1.5.3.5.next.428.g67f5d-dirty\n"},{"id":"60534","messageId":"Pine.LNX.4.64.0711211601540.27959@racer.site","threadId":"10961","inReplyTo":"1195659613-5290-1-git-send-email-sbejar@gmail.com","subject":"Re: [PATCH RFC] Use \"git fetch\" when cloning","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-11-21T16:04:53Z","receivedAt":"2007-11-21T16:04:53Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 21 Nov 2007, Santi Béjar wrote:\n\n> 1) It always use \"git fetch\" even if local. So now it checks the validity\n>    of the new repo, in particular it does not create a broken repository\n>    when there are too many nested alternates.\n\nI doubt that this is a good change.  It will make local clones much, much \nmore expensive now.\n\n> 2) It connects with the remote repo when fetching the branches/tags\n>    and the remote HEAD.\n> \n> 3) The quiet mode of \"git fetch\" prints the changed branches/tags, so \"git clone\"\n>    prints always the new branches/tags.\n\nThese changes would merit a split so that we could cherry-pick what we \nwant, and leave what we don't want.\n\n> diff --git a/t/t5710-info-alternate.sh b/t/t5710-info-alternate.sh\n> index 699df6e..9b7f638 100755\n> --- a/t/t5710-info-alternate.sh\n> +++ b/t/t5710-info-alternate.sh\n> @@ -53,7 +53,7 @@ git prune'\n>  \n>  cd \"$base_dir\"\n>  \n> -test_expect_failure 'creating too deep nesting' \\\n> +test_expect_success 'creating too deep nesting' \\\n>  'git clone -l -s C D &&\n>  git clone -l -s D E &&\n>  git clone -l -s E F &&\n> -- \n> 1.5.3.5.next.428.g67f5d-dirty\n\nWhat on _earth_?\n\nAfter thinking a bit harder about it, _and_ reading the commit message, I \nunderstand why it succeeds now.\n\nBut what would you _yourself_ think when reading this part of the code in \nhalf a year?  Exactly.\n\nCiao,\nDscho\n"}]}