{"thread":{"id":"431","subject":"[PATCH] git-local-pull updates","startedAt":"2005-05-02T03:41:51Z","lastAt":"2005-05-02T03:41:51Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"2354","messageId":"7vfyx6pa4g.fsf@assigned-by-dhcp.cox.net","threadId":"431","inReplyTo":null,"subject":"[PATCH] git-local-pull updates","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-02T03:41:51Z","receivedAt":"2005-05-02T03:41:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This is to be applied on top of the previous patch to add\ngit-local-pull command.  In addition to the '-l' (attempt\nhardlink before anything else) and the '-s' (then attempt\nsymlink) flags, it adds '-n' (do not fall back to file copy)\nflag.  Also it updates the comments.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\nlocal-pull.c |   65 +++++++++++++++++++++++++++++++++++++----------------------\n1 files changed, 41 insertions(+), 24 deletions(-)\n\n# jit-diff -1:\n# - Roll-up patches missing from Linus tree.\n# + working-tree\n--- k/local-pull.c\n+++ l/local-pull.c\n@@ -1,3 +1,6 @@\n+/*\n+ * Copyright (C) 2005 Junio C Hamano\n+ */\n #include <fcntl.h>\n #include <unistd.h>\n #include <string.h>\n@@ -10,6 +13,7 @@\n \n static int use_link = 0;\n static int use_symlink = 0;\n+static int use_filecopy = 1;\n static int verbose = 0;\n \n static char *path;\n@@ -25,9 +29,6 @@ int fetch(unsigned char *sha1)\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@@ -46,33 +47,47 @@ int fetch(unsigned char *sha1)\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+\tif (use_filecopy) {\n+\t\tint ifd, ofd, status;\n+\t\tstruct stat st;\n+\t\tvoid *map;\n+\t\tifd = open(filename, O_RDONLY);\n+\t\tif (ifd < 0 || fstat(ifd, &st) < 0) {\n+\t\t\tclose(ifd);\n+\t\t\tfprintf(stderr, \"Cannot open %s\\n\", filename);\n+\t\t\treturn -1;\n+\t\t}\n+\t\tmap = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, ifd, 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\tif (-1 == (int)(long)map) {\n+\t\t\tfprintf(stderr, \"Cannot mmap %s\\n\", filename);\n+\t\t\treturn -1;\n+\t\t}\n+\t\tofd = open(dest_filename, O_WRONLY | O_CREAT | O_EXCL, 0666);\n+\t\tstatus = ((ofd < 0) ||\n+\t\t\t  (write(ofd, map, st.st_size) != st.st_size));\n+\t\tmunmap(map, st.st_size);\n+\t\tclose(ofd);\n+\t\tif (status)\n+\t\t\tfprintf(stderr, \"Cannot write %s (%ld bytes)\\n\",\n+\t\t\t\tdest_filename, st.st_size);\n+\t\telse\n+\t\t\tsay(\"Copied %s.\\n\", hex);\n+\t\treturn status;\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+\tfprintf(stderr, \"No copy method was provided to copy %s.\\n\", hex);\n+\treturn -1;\n }\n \n static const char *local_pull_usage = \n-\"git-local-pull [-c] [-t] [-a] [-l] [-s] [-v] commit-id path\";\n+\"git-local-pull [-c] [-t] [-a] [-l] [-s] [-n] [-v] commit-id path\";\n \n+/* \n+ * By default we only use file copy.\n+ * If -l is specified, a hard link is attempted.\n+ * If -s is specified, then a symlink is attempted.\n+ * If -n is _not_ specified, then a regular file-to-file copy is done.\n+ */\n int main(int argc, char **argv)\n {\n \tchar *commit_id;\n@@ -92,6 +107,8 @@ int main(int argc, char **argv)\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] == 'n')\n+\t\t\tuse_filecopy = 0;\n \t\telse if (argv[arg][1] == 'v')\n \t\t\tverbose = 1;\n \t\telse\n\n"}]}