{"thread":{"id":"1004","subject":"[PATCH] Pull refs by HTTP","startedAt":"2005-06-22T00:45:49Z","lastAt":"2005-06-22T08:52:06Z","messageCount":2,"participants":["Daniel Barkalow","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"5111","messageId":"Pine.LNX.4.21.0506212043540.30848-100000@iabervon.org","threadId":"1004","inReplyTo":null,"subject":"[PATCH] Pull refs by HTTP","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-06-22T00:45:49Z","receivedAt":"2005-06-22T00:45:49Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"This adds support for refs to http-pull, both the -w option and reading\nthe target from a served file.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\nIndex: http-pull.c\n===================================================================\n--- b6a510708036fe29a19c33472f5c0b746e2d26d7/http-pull.c  (mode:100644 sha1:f49525c00228b5db9dc2fbd4860883887bb7dbad)\n+++ bc8b6802c7004e93b812698bd699c3548906653b/http-pull.c  (mode:100644 sha1:ec53dad8efbe6e7734b75eaba8821ac290a5abbb)\n@@ -16,6 +16,23 @@\n static int local;\n static int zret;\n \n+struct buffer\n+{\n+        size_t posn;\n+        size_t size;\n+        void *buffer;\n+};\n+\n+static size_t fwrite_buffer(void *ptr, size_t eltsize, size_t nmemb,\n+                            struct buffer *buffer) {\n+        size_t size = eltsize * nmemb;\n+        if (size > buffer->size - buffer->posn)\n+                size = buffer->size - buffer->posn;\n+        memcpy(buffer->buffer + buffer->posn, ptr, size);\n+        buffer->posn += size;\n+        return size;\n+}\n+\n static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb, \n \t\t\t       void *data) {\n \tunsigned char expn[4096];\n@@ -94,7 +111,32 @@\n \n int fetch_ref(char *ref, unsigned char *sha1)\n {\n-\treturn -1;\n+        char *url, *posn;\n+        char hex[42];\n+        struct buffer buffer;\n+        buffer.size = 41;\n+        buffer.posn = 0;\n+        buffer.buffer = hex;\n+        hex[41] = '\\0';\n+        \n+        curl_easy_setopt(curl, CURLOPT_FILE, &buffer);\n+        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);\n+\n+        url = xmalloc(strlen(base) + 6 + strlen(ref));\n+        strcpy(url, base);\n+        posn = url + strlen(base);\n+        strcpy(posn, \"refs/\");\n+        posn += 5;\n+        strcpy(posn, ref);\n+\n+        curl_easy_setopt(curl, CURLOPT_URL, url);\n+\n+        if (curl_easy_perform(curl))\n+                return error(\"Couldn't get %s for %s\\n\", url, ref);\n+\n+        hex[40] = '\\0';\n+        get_sha1_hex(hex, sha1);\n+        return 0;\n }\n \n int main(int argc, char **argv)\n@@ -118,11 +160,14 @@\n \t\t\tget_history = 1;\n \t\t} else if (argv[arg][1] == 'v') {\n \t\t\tget_verbosely = 1;\n+\t\t} else if (argv[arg][1] == 'w') {\n+\t\t\twrite_ref = argv[arg + 1];\n+\t\t\targ++;\n \t\t}\n \t\targ++;\n \t}\n \tif (argc < arg + 2) {\n-\t\tusage(\"git-http-pull [-c] [-t] [-a] [-d] [-v] [--recover] commit-id url\");\n+\t\tusage(\"git-http-pull [-c] [-t] [-a] [-d] [-v] [--recover] [-w ref] commit-id url\");\n \t\treturn 1;\n \t}\n \tcommit_id = argv[arg];\n\n"},{"id":"5114","messageId":"7v8y12ixjd.fsf@assigned-by-dhcp.cox.net","threadId":"1004","inReplyTo":"Pine.LNX.4.21.0506212043540.30848-100000@iabervon.org","subject":"[PATCH] local-pull: implement fetch_ref()","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-06-22T08:52:06Z","receivedAt":"2005-06-22T08:52:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This makes \"-w ref\" usable for git-local-pull.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n Documentation/git-local-pull.txt |    7 +++++--\n local-pull.c                     |   31 ++++++++++++++++++++++++++++---\n 2 files changed, 33 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-local-pull.txt b/Documentation/git-local-pull.txt\n--- a/Documentation/git-local-pull.txt\n+++ b/Documentation/git-local-pull.txt\n@@ -9,7 +9,7 @@ git-local-pull - Duplicates another GIT \n \n SYNOPSIS\n --------\n-'git-local-pull' [-c] [-t] [-a] [-l] [-s] [-n] [-v] [-d] [--recover] commit-id path\n+'git-local-pull' [-c] [-t] [-a] [-d] [-v] [-w filename] [--recover] [-l] [-s] [-n] commit-id path\n \n DESCRIPTION\n -----------\n@@ -32,10 +32,13 @@ OPTIONS\n \tusual, to recover after earlier pull that was interrupted.\n -v::\n \tReport what is downloaded.\n+-w::\n+        Writes the commit-id into the filename under $GIT_DIR/refs/ on\n+        the local end after the transfer is complete.\n \n Author\n ------\n-Written by Linus Torvalds <torvalds@osdl.org>\n+Written by Junio C Hamano <junkio@cox.net>\n \n Documentation\n --------------\ndiff --git a/local-pull.c b/local-pull.c\n--- a/local-pull.c\n+++ b/local-pull.c\n@@ -9,7 +9,7 @@ static int use_link = 0;\n static int use_symlink = 0;\n static int use_filecopy = 1;\n \n-static char *path;\n+static char *path; /* \"Remote\" git repository */\n \n int fetch(unsigned char *sha1)\n {\n@@ -75,11 +75,34 @@ int fetch(unsigned char *sha1)\n \n int fetch_ref(char *ref, unsigned char *sha1)\n {\n-\treturn -1;\n+\tstatic int ref_name_start = -1;\n+\tstatic char filename[PATH_MAX];\n+\tstatic char hex[41];\n+\tint ifd;\n+\n+\tif (ref_name_start < 0) {\n+\t\tsprintf(filename, \"%s/refs/\", path);\n+\t\tref_name_start = strlen(filename);\n+\t}\n+\tstrcpy(filename + ref_name_start, ref);\n+\tifd = open(filename, O_RDONLY);\n+\tif (ifd < 0) {\n+\t\tclose(ifd);\n+\t\tfprintf(stderr, \"cannot open %s\\n\", filename);\n+\t\treturn -1;\n+\t}\n+\tif (read(ifd, hex, 40) != 40 || get_sha1_hex(hex, sha1)) {\n+\t\tclose(ifd);\n+\t\tfprintf(stderr, \"cannot read from %s\\n\", filename);\n+\t\treturn -1;\n+\t}\n+\tclose(ifd);\n+\tpull_say(\"ref %s\\n\", sha1_to_hex(sha1));\n+\treturn 0;\n }\n \n static const char *local_pull_usage = \n-\"git-local-pull [-c] [-t] [-a] [-l] [-s] [-n] [-v] [-d] [--recover] commit-id path\";\n+\"git-local-pull [-c] [-t] [-a] [-d] [-v] [-w filename] [--recover] [-l] [-s] [-n] commit-id path\";\n \n /* \n  * By default we only use file copy.\n@@ -114,6 +137,8 @@ int main(int argc, char **argv)\n \t\t\tuse_filecopy = 0;\n \t\telse if (argv[arg][1] == 'v')\n \t\t\tget_verbosely = 1;\n+\t\telse if (argv[arg][1] == 'w')\n+\t\t\twrite_ref = argv[++arg];\n \t\telse\n \t\t\tusage(local_pull_usage);\n \t\targ++;\n------------------------------------------------\n\n"}]}