{"thread":{"id":"1328","subject":"[PATCH 6/6] Support cloning packed repo from dumb http servers.","startedAt":"2005-07-24T00:55:07Z","lastAt":"2005-07-24T00:55:07Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"6402","messageId":"7vll3xja50.fsf@assigned-by-dhcp.cox.net","threadId":"1328","inReplyTo":null,"subject":"[PATCH 6/6] Support cloning packed repo from dumb http servers.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-07-24T00:55:07Z","receivedAt":"2005-07-24T00:55:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Using the information prepared with update-server-info, a truly\ndumb http server can allow cloning with this client side\nsupport.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n Makefile            |    2 +-\n git-clone-dumb-http |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++\n git-clone-script    |   13 +++++++++++--\n 3 files changed, 63 insertions(+), 3 deletions(-)\n create mode 100755 git-clone-dumb-http\n\n5dd66390cbe5fe0665681ad0d73368085c87b01d\ndiff --git a/Makefile b/Makefile\n--- a/Makefile\n+++ b/Makefile\n@@ -37,7 +37,7 @@ SCRIPTS=git git-apply-patch-script git-m\n \tgitk git-cherry git-rebase-script git-relink-script git-repack-script \\\n \tgit-format-patch-script git-sh-setup-script git-push-script \\\n \tgit-branch-script git-parse-remote git-verify-tag-script \\\n-\tgit-ls-remote-script\n+\tgit-ls-remote-script git-clone-dumb-http\n \n PROG=   git-update-cache git-diff-files git-init-db git-write-tree \\\n \tgit-read-tree git-commit-tree git-cat-file git-fsck-cache \\\ndiff --git a/git-clone-dumb-http b/git-clone-dumb-http\nnew file mode 100755\n--- /dev/null\n+++ b/git-clone-dumb-http\n@@ -0,0 +1,51 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2005, Junio C Hamano\n+#\n+# Called by git-clone-script\n+# Exits 2 when the remote site does not support dumb server protocol.\n+\n+# Usage: git-clone-dumb-http <remote-repo> <local-dir>\n+\n+R=${1?\"remote repository\"} D=${2?\"local directory\"}\n+\n+if [ -n \"$GIT_SSL_NO_VERIFY\" ]; then\n+    curl_extra_args=\"-k\"\n+fi\n+http_fetch () {\n+\t# $1 = Remote, $2 = Local\n+\tcurl -ns $curl_extra_args \"$1\" >\"$2\"\n+}\n+\n+cd \"$D\" && \n+clone_tmp=\".git/clone-tmp\" &&\n+mkdir -p \"$clone_tmp\" || exit 1\n+trap \"rm -rf .git/clone-tmp\" 0 1 2 3 15\n+\n+http_fetch \"$R/info/refs\" \"$clone_tmp/refs\" &&\n+http_fetch \"$R/objects/info/packs\" \"$clone_tmp/packs\" || exit 2\n+\n+# We do not have to worry about rev-cache when cloning.\n+# http_fetch \"$R/info/rev-cache\" \"$clone_tmp/rev-cache\" \n+\n+# Clone packs\n+while read type name\n+do\n+\tcase \"$type\" in\n+\tP) ;;\n+\t*) continue ;;\n+\tesac &&\n+\n+\tidx=`expr \"$name\" : '\\(.*\\)\\.pack'`.idx\n+\thttp_fetch \"$R/objects/pack/$name\" \".git/objects/pack/$name\" &&\n+\thttp_fetch \"$R/objects/pack/$idx\" \".git/objects/pack/$idx\" &&\n+\tgit-verify-pack \".git/objects/pack/$idx\" || exit 1\n+\n+done <\"$clone_tmp/packs\"\n+\n+# Then clone refs.\n+while read sha1 refname\n+do\n+\tname=`expr \"$refname\" : 'refs/\\(.*\\)'` &&\n+\tgit-http-pull -v -a -w \"$name\" \"$name\" \"$R/\" || exit 1\n+done <\"$clone_tmp/refs\"\ndiff --git a/git-clone-script b/git-clone-script\n--- a/git-clone-script\n+++ b/git-clone-script\n@@ -89,8 +89,17 @@ yes,yes)\n \t\trsync $quiet -avz --ignore-existing \"$repo/refs/\" \"$D/.git/refs/\"\n \t\t;;\n \thttp://*)\n-\t\techo \"Somebody should add http fetch\" >&2\n-\t\texit 1\n+\t\tgit-clone-dumb-http \"$repo\" \"$D\"\n+\t\tcase \"$?\" in\n+\t\t2)\n+\t\t\techo \"Somebody should define smarter http server protocol\" >&2\n+\t\t\texit 1\n+\t\t\t;;\n+\t\t0)\n+\t\t\t;;\n+\t\t*)\n+\t\t\texit\n+\t\tesac\n \t\t;;\n \t*)\n \t\tcd \"$D\" && case \"$upload_pack\" in\n"}]}