{"thread":{"id":"1325","subject":"[PATCH 3/6] git-ls-remote: show and optionally store remote refs.","startedAt":"2005-07-24T00:54:26Z","lastAt":"2005-07-24T00:54:26Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"6399","messageId":"7v7jfhkoql.fsf@assigned-by-dhcp.cox.net","threadId":"1325","inReplyTo":null,"subject":"[PATCH 3/6] git-ls-remote: show and optionally store remote refs.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-07-24T00:54:26Z","receivedAt":"2005-07-24T00:54:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Retrieve and list the remote refs from git, http, and rsync\nrepositories, and optionally stores the retrieved refs in the\nlocal repository under the same name.\n\nTo access a git URL, git-peek-remote command is used.  An http\nURL needs to have an up-to-date info/refs file for discovery,\nwhich will be introduced by a later update-server-info patch.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n Makefile             |    3 +\n git-ls-remote-script |  104 ++++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 106 insertions(+), 1 deletions(-)\n create mode 100755 git-ls-remote-script\n\ncb508fd7eb23a40432231977a9e7f12eb8d3e9de\ndiff --git a/Makefile b/Makefile\n--- a/Makefile\n+++ b/Makefile\n@@ -36,7 +36,8 @@ SCRIPTS=git git-apply-patch-script git-m\n \tgit-reset-script git-add-script git-checkout-script git-clone-script \\\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-branch-script git-parse-remote git-verify-tag-script \\\n+\tgit-ls-remote-script\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-ls-remote-script b/git-ls-remote-script\nnew file mode 100755\n--- /dev/null\n+++ b/git-ls-remote-script\n@@ -0,0 +1,104 @@\n+#!/bin/sh\n+#\n+. git-sh-setup-script || die \"Not a git archive\"\n+\n+usage () {\n+    echo >&2 \"usage: $0 [--heads] [--tags] [--overwrite | --store] repo\"\n+    exit 1;\n+}\n+\n+while case \"$#\" in 0) break;; esac\n+do\n+  case \"$1\" in\n+  -h|--h|--he|--hea|--head|--heads)\n+  heads=heads; shift ;;\n+  -o|--o|--ov|--ove|--over|--overw|--overwr|--overwri|--overwrit|--overwrite)\n+  overwrite=overwrite; shift ;;\n+  -s|--s|--st|--sto|--stor|--store)\n+  store=store; shift ;;\n+  -t|--t|--ta|--tag|--tags)\n+  tags=tags; shift ;;\n+  --)\n+  shift; break ;;\n+  -*)\n+  usage ;;\n+  *)\n+  break ;;\n+  esac\n+done\n+\n+case \"$#\" in 1) ;; *) usage ;; esac\n+case \",$store,$overwrite,\" in *,,*) ;; *) usage ;; esac\n+\n+case \",$heads,$tags,\" in\n+,,,) heads=heads tags=tags other=other ;;\n+esac\n+\n+. git-parse-remote \"$@\"\n+peek_repo=\"$_remote_repo\"\n+\n+tmp=.ls-remote-$$\n+trap \"rm -fr $tmp-*\" 0 1 2 3 15\n+tmpdir=$tmp-d\n+\n+case \"$peek_repo\" in\n+http://* | https://* )\n+        if [ -n \"$GIT_SSL_NO_VERIFY\" ]; then\n+            curl_extra_args=\"-k\"\n+        fi\n+\tcurl -ns $curl_extra_args \"$peek_repo/info/refs\" || exit 1\n+\t;;\n+\n+rsync://* )\n+\tmkdir $tmpdir\n+\trsync -rq \"$peek_repo/refs\" $tmpdir || exit 1\n+\t(cd $tmpdir && find refs -type f) |\n+\twhile read path\n+\tdo\n+\t\tcat \"$tmpdir/$path\" | tr -d '\\012'\n+\t\techo \"\t$path\"\n+\tdone &&\n+\trm -fr $tmpdir\n+\t;;\n+\n+* )\n+\tgit-peek-remote \"$peek_repo\"\n+\t;;\n+esac |\n+\n+while read sha1 path\n+do\n+\tcase \"$path\" in\n+\trefs/heads/*)\n+\t\tgroup=heads ;;\n+\trefs/tags/*)\n+\t\tgroup=tags ;;\n+\t*)\n+\t\tgroup=other ;;\n+\tesac\n+\tcase \",$heads,$tags,$other,\" in\n+\t*,$group,*)\n+\t\t;;\n+\t*)\n+\t\tcontinue;;\n+\tesac\n+\n+\techo \"$sha1\t$path\"\n+\n+\tcase \"$path,$store,$overwrite,\" in\n+\t*,,, | HEAD,*) continue ;;\n+\tesac\n+\n+\tif test -f \"$GIT_DIR/$path\" && test \"$overwrite\" == \"\"\n+\tthen\n+\t\tcontinue\n+\tfi\n+\n+\t# Be careful.  We may not have that object yet!\n+\tif git-cat-file -t \"$sha1\" >/dev/null 2>&1\n+\tthen\n+\t\techo \"$sha1\" >\"$GIT_DIR/$path\"\n+\telse\n+\t\techo >&2 \"* You have not fetched updated $path ($sha1).\"\n+\tfi\n+done\n"}]}