{"thread":{"id":"10516","subject":"[PATCH 2/4] Build-in peek-remote, using transport infrastructure.","startedAt":"2007-10-30T01:05:43Z","lastAt":"2007-10-30T01:05:43Z","messageCount":1,"participants":["Daniel Barkalow"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"57505","messageId":"Pine.LNX.4.64.0710292049310.7357@iabervon.org","threadId":"10516","inReplyTo":null,"subject":"[PATCH 2/4] Build-in peek-remote, using transport infrastructure.","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2007-10-30T01:05:43Z","receivedAt":"2007-10-30T01:05:43Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\n Makefile                               |    3 +-\n peek-remote.c => builtin-peek-remote.c |   55 ++++++++++++++-----------------\n builtin.h                              |    1 +\n git.c                                  |    1 +\n 4 files changed, 29 insertions(+), 31 deletions(-)\n rename peek-remote.c => builtin-peek-remote.c (59%)\n\ndiff --git a/Makefile b/Makefile\nindex 72f5ef4..64ad297 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -240,7 +240,7 @@ PROGRAMS = \\\n \tgit-fast-import$X \\\n \tgit-daemon$X \\\n \tgit-merge-index$X git-mktag$X git-mktree$X git-patch-id$X \\\n-\tgit-peek-remote$X git-receive-pack$X \\\n+\tgit-receive-pack$X \\\n \tgit-send-pack$X git-shell$X \\\n \tgit-show-index$X \\\n \tgit-unpack-file$X \\\n@@ -353,6 +353,7 @@ BUILTIN_OBJS = \\\n \tbuiltin-mv.o \\\n \tbuiltin-name-rev.o \\\n \tbuiltin-pack-objects.o \\\n+\tbuiltin-peek-remote.o \\\n \tbuiltin-prune.o \\\n \tbuiltin-prune-packed.o \\\n \tbuiltin-push.o \\\ndiff --git a/peek-remote.c b/builtin-peek-remote.c\nsimilarity index 59%\nrename from peek-remote.c\nrename to builtin-peek-remote.c\nindex ceb7871..b4106f5 100644\n--- a/peek-remote.c\n+++ b/builtin-peek-remote.c\n@@ -1,38 +1,26 @@\n+#include \"builtin.h\"\n #include \"cache.h\"\n-#include \"refs.h\"\n-#include \"pkt-line.h\"\n+#include \"transport.h\"\n+#include \"remote.h\"\n \n static const char peek_remote_usage[] =\n \"git-peek-remote [--upload-pack=<git-upload-pack>] [<host>:]<directory>\";\n-static const char *uploadpack = \"git-upload-pack\";\n \n-static int peek_remote(int fd[2], unsigned flags)\n+int cmd_peek_remote(int argc, const char **argv, const char *prefix)\n {\n-\tstruct ref *ref;\n-\n-\tget_remote_heads(fd[0], &ref, 0, NULL, flags);\n-\tpacket_flush(fd[1]);\n-\n-\twhile (ref) {\n-\t\tprintf(\"%s\t%s\\n\", sha1_to_hex(ref->old_sha1), ref->name);\n-\t\tref = ref->next;\n-\t}\n-\treturn 0;\n-}\n-\n-int main(int argc, char **argv)\n-{\n-\tint i, ret;\n-\tchar *dest = NULL;\n-\tint fd[2];\n-\tpid_t pid;\n+\tint i;\n+\tconst char *dest = NULL;\n \tint nongit = 0;\n \tunsigned flags = 0;\n+\tconst char *uploadpack = NULL;\n+\n+\tstruct transport *transport;\n+\tconst struct ref *ref;\n \n \tsetup_git_directory_gently(&nongit);\n \n \tfor (i = 1; i < argc; i++) {\n-\t\tchar *arg = argv[i];\n+\t\tconst char *arg = argv[i];\n \n \t\tif (*arg == '-') {\n \t\t\tif (!prefixcmp(arg, \"--upload-pack=\")) {\n@@ -64,12 +52,19 @@ int main(int argc, char **argv)\n \tif (!dest || i != argc - 1)\n \t\tusage(peek_remote_usage);\n \n-\tpid = git_connect(fd, dest, uploadpack, 0);\n-\tif (pid < 0)\n+\ttransport = transport_get(NULL, dest);\n+\tif (uploadpack != NULL)\n+\t\ttransport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);\n+\n+\tref = transport_get_remote_refs(transport);\n+\n+\tif (!ref)\n \t\treturn 1;\n-\tret = peek_remote(fd, flags);\n-\tclose(fd[0]);\n-\tclose(fd[1]);\n-\tret |= finish_connect(pid);\n-\treturn !!ret;\n+\n+\twhile (ref) {\n+\t\tif (check_ref_type(ref, flags))\n+\t\t\tprintf(\"%s\t%s\\n\", sha1_to_hex(ref->old_sha1), ref->name);\n+\t\tref = ref->next;\n+\t}\n+\treturn 0;\n }\ndiff --git a/builtin.h b/builtin.h\nindex 65cc0fb..ff84835 100644\n--- a/builtin.h\n+++ b/builtin.h\n@@ -54,6 +54,7 @@ extern int cmd_merge_file(int argc, const char **argv, const char *prefix);\n extern int cmd_mv(int argc, const char **argv, const char *prefix);\n extern int cmd_name_rev(int argc, const char **argv, const char *prefix);\n extern int cmd_pack_objects(int argc, const char **argv, const char *prefix);\n+extern int cmd_peek_remote(int argc, const char **argv, const char *prefix);\n extern int cmd_pickaxe(int argc, const char **argv, const char *prefix);\n extern int cmd_prune(int argc, const char **argv, const char *prefix);\n extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);\ndiff --git a/git.c b/git.c\nindex 23a430c..1b182e2 100644\n--- a/git.c\n+++ b/git.c\n@@ -355,6 +355,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"mv\", cmd_mv, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"name-rev\", cmd_name_rev, RUN_SETUP },\n \t\t{ \"pack-objects\", cmd_pack_objects, RUN_SETUP },\n+\t\t{ \"peek-remote\", cmd_peek_remote },\n \t\t{ \"pickaxe\", cmd_blame, RUN_SETUP },\n \t\t{ \"prune\", cmd_prune, RUN_SETUP },\n \t\t{ \"prune-packed\", cmd_prune_packed, RUN_SETUP },\n-- \n1.5.3.4.1206.g5f96\n"}]}