{"thread":{"id":"426","subject":"[PATCH] Add git-local-pull.","startedAt":"2005-05-02T00:11:26Z","lastAt":"2005-05-02T00:11:26Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"2340","messageId":"7vis22qyfl.fsf@assigned-by-dhcp.cox.net","threadId":"426","inReplyTo":null,"subject":"[PATCH] Add git-local-pull.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-02T00:11:26Z","receivedAt":"2005-05-02T00:11:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This adds the git-local-pull command as a smaller brother of\nhttp-pull and rpull.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\nMakefile     |    3 +\nlocal-pull.c |  110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n2 files changed, 112 insertions(+), 1 deletion(-)\n\n# - [PATCH] Do not pollute work tree in git-merge-one-file-script\n# + [PATCH] Add local pull.\n--- k/Makefile\n+++ l/Makefile\n@@ -21,7 +21,7 @@ PROG=   git-update-cache git-diff-files \n \tgit-check-files git-ls-tree git-merge-base git-merge-cache \\\n \tgit-unpack-file git-export git-diff-cache git-convert-cache \\\n \tgit-http-pull git-rpush git-rpull git-rev-list git-mktag \\\n-\tgit-diff-tree-helper git-tar-tree git-write-blob\n+\tgit-diff-tree-helper git-tar-tree git-write-blob git-local-pull\n \n all: $(PROG)\n \n@@ -87,6 +87,7 @@ git-export: export.c\n git-diff-cache: diff-cache.c\n git-convert-cache: convert-cache.c\n git-http-pull: http-pull.c pull.c\n+git-local-pull: local-pull.c pull.c\n git-rpush: rsh.c\n git-rpull: rsh.c pull.c\n git-rev-list: rev-list.c\n# - date handling: handle \"AM\"/\"PM\" on time\n# + [PATCH] Add local pull.\nCreated: local-pull.c (mode:100644)\n--- /dev/null\n+++ l/local-pull.c\n@@ -0,0 +1,110 @@\n+#include <fcntl.h>\n+#include <unistd.h>\n+#include <string.h>\n+#include <stdlib.h>\n+#include \"cache.h\"\n+#include \"commit.h\"\n+#include <errno.h>\n+#include <stdio.h>\n+#include \"pull.h\"\n+\n+static int use_link = 0;\n+static int use_symlink = 0;\n+static int verbose = 0;\n+\n+static char *path;\n+\n+static void say(const char *fmt, const char *hex) {\n+\tif (verbose)\n+\t\tfprintf(stderr, fmt, hex);\n+}\n+\n+int fetch(unsigned char *sha1)\n+{\n+\tstatic int object_name_start = -1;\n+\tstatic char filename[PATH_MAX];\n+\tchar *hex = sha1_to_hex(sha1);\n+\tconst char *dest_filename = sha1_file_name(sha1);\n+\tint ifd, ofd, status;\n+\tstruct stat st;\n+\tvoid *map;\n+\n+\tif (object_name_start < 0) {\n+\t\tstrcpy(filename, path); /* e.g. git.git */\n+\t\tstrcat(filename, \"/objects/\");\n+\t\tobject_name_start = strlen(filename);\n+\t}\n+\tfilename[object_name_start+0] = hex[0];\n+\tfilename[object_name_start+1] = hex[1];\n+\tfilename[object_name_start+2] = '/';\n+\tstrcpy(filename + object_name_start + 3, hex + 2);\n+\tif (use_link && !link(filename, dest_filename)) {\n+\t\tsay(\"Hardlinked %s.\\n\", hex);\n+\t\treturn 0;\n+\t}\n+\tif (use_symlink && !symlink(filename, dest_filename)) {\n+\t\tsay(\"Symlinked %s.\\n\", hex);\n+\t\treturn 0;\n+\t}\n+\tifd = open(filename, O_RDONLY);\n+\tif (ifd < 0 || fstat(ifd, &st) < 0) {\n+\t\tclose(ifd);\n+\t\tfprintf(stderr, \"Cannot open %s\\n\", filename);\n+\t\treturn -1;\n+\t}\n+\tmap = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, ifd, 0);\n+\tclose(ifd);\n+\tif (-1 == (int)(long)map) {\n+\t\tfprintf(stderr, \"Cannot mmap %s\\n\", filename);\n+\t\treturn -1;\n+\t}\n+\tofd = open(dest_filename, O_WRONLY | O_CREAT | O_EXCL, 0666);\n+\tstatus = ((ofd < 0) || (write(ofd, map, st.st_size) != st.st_size));\n+\tmunmap(map, st.st_size);\n+\tclose(ofd);\n+\tif (status)\n+\t\tfprintf(stderr, \"Cannot write %s (%ld bytes)\\n\",\n+\t\t\tdest_filename, st.st_size);\n+\telse\n+\t\tsay(\"Copied %s.\\n\", hex);\n+\treturn status;\n+}\n+\n+static const char *local_pull_usage = \n+\"git-local-pull [-c] [-t] [-a] [-l] [-s] [-v] commit-id path\";\n+\n+int main(int argc, char **argv)\n+{\n+\tchar *commit_id;\n+\tint arg = 1;\n+\n+\twhile (arg < argc && argv[arg][0] == '-') {\n+\t\tif (argv[arg][1] == 't')\n+\t\t\tget_tree = 1;\n+\t\telse if (argv[arg][1] == 'c')\n+\t\t\tget_history = 1;\n+\t\telse if (argv[arg][1] == 'a') {\n+\t\t\tget_all = 1;\n+\t\t\tget_tree = 1;\n+\t\t\tget_history = 1;\n+\t\t}\n+\t\telse if (argv[arg][1] == 'l')\n+\t\t\tuse_link = 1;\n+\t\telse if (argv[arg][1] == 's')\n+\t\t\tuse_symlink = 1;\n+\t\telse if (argv[arg][1] == 'v')\n+\t\t\tverbose = 1;\n+\t\telse\n+\t\t\tusage(local_pull_usage);\n+\t\targ++;\n+\t}\n+\tif (argc < arg + 2)\n+\t\tusage(local_pull_usage);\n+\tcommit_id = argv[arg];\n+\tpath = argv[arg + 1];\n+\n+\tif (pull(commit_id))\n+\t\treturn 1;\n+\n+\treturn 0;\n+}\n\n"}]}