{"thread":{"id":"847","subject":"[PATCH 1/4] Operations on refs","startedAt":"2005-06-06T20:27:36Z","lastAt":"2005-06-07T16:45:03Z","messageCount":11,"participants":["Daniel Barkalow","Linus Torvalds","Frank Sorenson","Thomas Glanzmann","McMullan, Jason"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"4656","messageId":"Pine.LNX.4.21.0506061616590.30848-100000@iabervon.org","threadId":"847","inReplyTo":null,"subject":"[PATCH 0/4] Writing refs in git-ssh-push","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-06-06T20:27:36Z","receivedAt":"2005-06-06T20:27:36Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"This series adds -w to git-ssh-push (and git-ssh-pull, which is the same).\n\n - Add code for reading and writing ref files\n - Fix the environment variable for the path in rsh.c\n - Add support for transferring references in pull.c\n - Add support for refs in ssh protocol and options to invoke it\n\nI'll send documentation updates in another patch this evening.\n\n\t-Daniel\n*This .sig left intentionally blank*\n\n\n"},{"id":"4652","messageId":"Pine.LNX.4.21.0506061627530.30848-100000@iabervon.org","threadId":"847","inReplyTo":"Pine.LNX.4.21.0506061616590.30848-100000@iabervon.org","subject":"[PATCH 1/4] Operations on refs","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-06-06T20:31:29Z","receivedAt":"2005-06-06T20:31:29Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"This patch adds code to read a hash out of a specified file under\n{GIT_DIR}/refs/, and to write such files atomically and optionally with an\ncompare and lock.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n\nIndex: Makefile\n===================================================================\n--- 2dde8ae2d3300fb95e35facac622b9b54990624e/Makefile  (mode:100644 sha1:a5e7552e10bf50888814d43b1ba1a7276d130ca6)\n+++ 9138b84eb683fc23a285445f7d7fc5a836ba01cb/Makefile  (mode:100644 sha1:c6e2eae2e68a47cdb88d2b1b7fec2c4cc230d506)\n@@ -40,7 +40,7 @@\n \t$(INSTALL) $(PROG) $(SCRIPTS) $(dest)$(bin)\n \n LIB_OBJS=read-cache.o sha1_file.o usage.o object.o commit.o tree.o blob.o \\\n-\t tag.o delta.o date.o index.o diff-delta.o patch-delta.o\n+\t tag.o delta.o date.o index.o diff-delta.o patch-delta.o refs.o\n LIB_FILE=libgit.a\n LIB_H=cache.h object.h blob.h tree.h commit.h tag.h delta.h\n \nIndex: cache.h\n===================================================================\n--- 2dde8ae2d3300fb95e35facac622b9b54990624e/cache.h  (mode:100644 sha1:481f7c787040aadbbea877adbb3b9a4fd5f9b9d0)\n+++ 9138b84eb683fc23a285445f7d7fc5a836ba01cb/cache.h  (mode:100644 sha1:d2dbb0088b2a540972cd3c896d76b6c8dc1844ab)\n@@ -110,6 +110,7 @@\n #define INDEX_ENVIRONMENT \"GIT_INDEX_FILE\"\n \n extern char *get_object_directory(void);\n+extern char *get_refs_directory(void);\n extern char *get_index_file(void);\n \n #define ALTERNATE_DB_ENVIRONMENT \"GIT_ALTERNATE_OBJECT_DIRECTORIES\"\nIndex: refs.c\n===================================================================\n--- /dev/null  (tree:2dde8ae2d3300fb95e35facac622b9b54990624e)\n+++ 9138b84eb683fc23a285445f7d7fc5a836ba01cb/refs.c  (mode:100644 sha1:9973d1fc21e9d14f4cf1d30cb59f55cdfd7fc1e7)\n@@ -0,0 +1,173 @@\n+#include \"refs.h\"\n+#include \"cache.h\"\n+\n+#include <errno.h>\n+\n+static char *ref_file_name(const char *ref)\n+{\n+\tchar *base = get_refs_directory();\n+\tint baselen = strlen(base);\n+\tint reflen = strlen(ref);\n+\tchar *ret = xmalloc(baselen + 2 + reflen);\n+\tsprintf(ret, \"%s/%s\", base, ref);\n+\treturn ret;\n+}\n+\n+static char *ref_lock_file_name(const char *ref)\n+{\n+\tchar *base = get_refs_directory();\n+\tint baselen = strlen(base);\n+\tint reflen = strlen(ref);\n+\tchar *ret = xmalloc(baselen + 7 + reflen);\n+\tsprintf(ret, \"%s/%s.lock\", base, ref);\n+\treturn ret;\n+}\n+\n+static int read_ref_file(const char *filename, unsigned char *sha1) {\n+\tint fd = open(filename, O_RDONLY);\n+\tchar hex[41];\n+\tif (fd < 0) {\n+\t\treturn error(\"Couldn't open %s\\n\", filename);\n+\t}\n+\tif ((read(fd, hex, 41) < 41) ||\n+\t    (hex[40] != '\\n') ||\n+\t    get_sha1_hex(hex, sha1)) {\n+\t\terror(\"Couldn't read a hash from %s\\n\", filename);\n+\t\tclose(fd);\n+\t\treturn -1;\n+\t}\n+\tclose(fd);\n+\treturn 0;\n+}\n+\n+int get_ref_sha1(const char *ref, unsigned char *sha1)\n+{\n+\tchar *filename;\n+\tint retval;\n+\tif (check_ref_format(ref))\n+\t\treturn -1;\n+\tfilename = ref_file_name(ref);\n+\tretval = read_ref_file(filename, sha1);\n+\tfree(filename);\n+\treturn retval;\n+}\n+\n+static int lock_ref_file(const char *filename, const char *lock_filename,\n+\t\t\t const unsigned char *old_sha1)\n+{\n+\tint fd = open(lock_filename, O_WRONLY | O_CREAT | O_EXCL, 0666);\n+\tunsigned char current_sha1[20];\n+\tint retval;\n+\tif (fd < 0) {\n+\t\treturn error(\"Couldn't open lock file for %s: %s\",\n+\t\t\t     filename, strerror(errno));\n+\t}\n+\tretval = read_ref_file(filename, current_sha1);\n+\tif (old_sha1) {\n+\t\tif (retval) {\n+\t\t\tclose(fd);\n+\t\t\tunlink(lock_filename);\n+\t\t\treturn error(\"Could not read the current value of %s\",\n+\t\t\t\t     filename);\n+\t\t}\n+\t\tif (memcmp(current_sha1, old_sha1, 20)) {\n+\t\t\tclose(fd);\n+\t\t\tunlink(lock_filename);\n+\t\t\terror(\"The current value of %s is %s\",\n+\t\t\t      filename, sha1_to_hex(current_sha1));\n+\t\t\treturn error(\"Expected %s\",\n+\t\t\t\t     sha1_to_hex(old_sha1));\n+\t\t}\n+\t} else {\n+\t\tif (!retval) {\n+\t\t\tclose(fd);\n+\t\t\tunlink(lock_filename);\n+\t\t\treturn error(\"Unexpectedly found a value of %s for %s\",\n+\t\t\t\t     sha1_to_hex(current_sha1), filename);\n+\t\t}\n+\t}\n+\treturn fd;\n+}\n+\n+int lock_ref_sha1(const char *ref, const unsigned char *old_sha1)\n+{\n+\tchar *filename;\n+\tchar *lock_filename;\n+\tint retval;\n+\tif (check_ref_format(ref))\n+\t\treturn -1;\n+\tfilename = ref_file_name(ref);\n+\tlock_filename = ref_lock_file_name(ref);\n+\tretval = lock_ref_file(filename, lock_filename, old_sha1);\n+\tfree(filename);\n+\tfree(lock_filename);\n+\treturn retval;\n+}\n+\n+static int write_ref_file(const char *filename,\n+\t\t\t  const char *lock_filename, int fd,\n+\t\t\t  const unsigned char *sha1)\n+{\n+\tchar *hex = sha1_to_hex(sha1);\n+\tchar term = '\\n';\n+\tif (write(fd, hex, 40) < 40 ||\n+\t    write(fd, &term, 1) < 1) {\n+\t\terror(\"Couldn't write %s\\n\", filename);\n+\t\tclose(fd);\n+\t\treturn -1;\n+\t}\n+\tclose(fd);\n+\trename(lock_filename, filename);\n+\treturn 0;\n+}\n+\n+int write_ref_sha1(const char *ref, int fd, const unsigned char *sha1)\n+{\n+\tchar *filename;\n+\tchar *lock_filename;\n+\tint retval;\n+\tif (fd < 0)\n+\t\treturn -1;\n+\tif (check_ref_format(ref))\n+\t\treturn -1;\n+\tfilename = ref_file_name(ref);\n+\tlock_filename = ref_lock_file_name(ref);\n+\tretval = write_ref_file(filename, lock_filename, fd, sha1);\n+\tfree(filename);\n+\tfree(lock_filename);\n+\treturn retval;\n+}\n+\n+int check_ref_format(const char *ref)\n+{\n+\tchar *middle;\n+\tif (ref[0] == '.' || ref[0] == '/')\n+\t\treturn -1;\n+\tmiddle = strchr(ref, '/');\n+\tif (!middle || !middle[1])\n+\t\treturn -1;\n+\tif (strchr(middle + 1, '/'))\n+\t\treturn -1;\n+\treturn 0;\n+}\n+\n+int write_ref_sha1_unlocked(const char *ref, const unsigned char *sha1)\n+{\n+\tchar *filename;\n+\tchar *lock_filename;\n+\tint fd;\n+\tint retval;\n+\tif (check_ref_format(ref))\n+\t\treturn -1;\n+\tfilename = ref_file_name(ref);\n+\tlock_filename = ref_lock_file_name(ref);\n+\tfd = open(lock_filename, O_WRONLY | O_CREAT | O_EXCL, 0666);\n+\tif (fd < 0) {\n+\t\terror(\"Writing %s\", lock_filename);\n+\t\tperror(\"Open\");\n+\t}\n+\tretval = write_ref_file(filename, lock_filename, fd, sha1);\n+\tfree(filename);\n+\tfree(lock_filename);\n+\treturn retval;\n+}\nIndex: refs.h\n===================================================================\n--- /dev/null  (tree:2dde8ae2d3300fb95e35facac622b9b54990624e)\n+++ 9138b84eb683fc23a285445f7d7fc5a836ba01cb/refs.h  (mode:100644 sha1:60cf48086f61c9206a343425ba9fdae3dce62937)\n@@ -0,0 +1,21 @@\n+#ifndef REFS_H\n+#define REFS_H\n+\n+/** Reads the refs file specified into sha1 **/\n+extern int get_ref_sha1(const char *ref, unsigned char *sha1);\n+\n+/** Locks ref and returns the fd to give to write_ref_sha1() if the ref\n+ * has the given value currently; otherwise, returns -1.\n+ **/\n+extern int lock_ref_sha1(const char *ref, const unsigned char *old_sha1);\n+\n+/** Writes sha1 into the refs file specified, locked with the given fd. **/\n+extern int write_ref_sha1(const char *ref, int fd, const unsigned char *sha1);\n+\n+/** Writes sha1 into the refs file specified. **/\n+extern int write_ref_sha1_unlocked(const char *ref, const unsigned char *sha1);\n+\n+/** Returns 0 if target has the right format for a ref. **/\n+extern int check_ref_format(const char *target);\n+\n+#endif /* REFS_H */\nIndex: sha1_file.c\n===================================================================\n--- 2dde8ae2d3300fb95e35facac622b9b54990624e/sha1_file.c  (mode:100644 sha1:a2ba4c81dba1b55b119d9ec3c42a7e4ce4ca1df5)\n+++ 9138b84eb683fc23a285445f7d7fc5a836ba01cb/sha1_file.c  (mode:100644 sha1:7cfd43c51ba20ee85fe6056c67bbc88cc90dad81)\n@@ -58,7 +58,7 @@\n \treturn get_sha1_hex(buffer, result);\n }\n \n-static char *git_dir, *git_object_dir, *git_index_file;\n+static char *git_dir, *git_object_dir, *git_index_file, *git_refs_dir;\n static void setup_git_env(void)\n {\n \tgit_dir = gitenv(GIT_DIR_ENVIRONMENT);\n@@ -69,6 +69,8 @@\n \t\tgit_object_dir = xmalloc(strlen(git_dir) + 9);\n \t\tsprintf(git_object_dir, \"%s/objects\", git_dir);\n \t}\n+\tgit_refs_dir = xmalloc(strlen(git_dir) + 6);\n+\tsprintf(git_refs_dir, \"%s/refs\", git_dir);\n \tgit_index_file = gitenv(INDEX_ENVIRONMENT);\n \tif (!git_index_file) {\n \t\tgit_index_file = xmalloc(strlen(git_dir) + 7);\n@@ -83,6 +85,13 @@\n \treturn git_object_dir;\n }\n \n+char *get_refs_directory(void)\n+{\n+\tif (!git_refs_dir)\n+\t\tsetup_git_env();\n+\treturn git_refs_dir;\n+}\n+\n char *get_index_file(void)\n {\n \tif (!git_index_file)\n\n"},{"id":"4653","messageId":"Pine.LNX.4.21.0506061631330.30848-100000@iabervon.org","threadId":"847","inReplyTo":"Pine.LNX.4.21.0506061616590.30848-100000@iabervon.org","subject":"[PATCH 2/4] rsh.c environment variable","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-06-06T20:35:02Z","receivedAt":"2005-06-06T20:35:02Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"rsh.c used to set the environment variable for the object database when\ninvoking the remote command. Now that there is a GIT_DIR variable, use\nthat instead.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n\nIndex: rsh.c\n===================================================================\n--- 5d261be8a54c55542223536a72c53fab564cc28a/rsh.c  (mode:100644 sha1:5d1cb9d578a8e679fc190a9d7d2c842ad811223f)\n+++ 2dde8ae2d3300fb95e35facac622b9b54990624e/rsh.c  (mode:100644 sha1:3eb9d9160531de91cbccfc1fdea2e9007a9cbfec)\n@@ -36,8 +36,8 @@\n \t*(path++) = '\\0';\n \t/* ssh <host> 'cd /<path>; stdio-pull <arg...> <commit-id>' */\n \tsnprintf(command, COMMAND_SIZE, \n-\t\t \"cd /%s; %s=objects %s\",\n-\t\t path, DB_ENVIRONMENT, remote_prog);\n+\t\t \"%s='/%s' %s\",\n+\t\t GIT_DIR_ENVIRONMENT, path, remote_prog);\n \tposn = command + strlen(command);\n \tfor (i = 0; i < rmt_argc; i++) {\n \t\t*(posn++) = ' ';\n\n"},{"id":"4655","messageId":"Pine.LNX.4.21.0506061635070.30848-100000@iabervon.org","threadId":"847","inReplyTo":"Pine.LNX.4.21.0506061616590.30848-100000@iabervon.org","subject":"[PATCH 3/4] Generic support for pulling refs","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-06-06T20:38:26Z","receivedAt":"2005-06-06T20:38:26Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"This adds support to pull.c for requesting a reference and writing it to a\nfile. All of the git-*-pull programs get stubs for now.\n\nIndex: http-pull.c\n===================================================================\n--- 9138b84eb683fc23a285445f7d7fc5a836ba01cb/http-pull.c  (mode:100644 sha1:551663e49234dc9b719ee4abb9f8dc8609d759aa)\n+++ 8deba080337c75a41cb456cc8b59000654278e59/http-pull.c  (mode:100644 sha1:4f097e0d0bbd5ae28babf8b685dc3b02747f9f15)\n@@ -92,6 +92,11 @@\n \treturn 0;\n }\n \n+int fetch_ref(char *ref, unsigned char *sha1)\n+{\n+\treturn -1;\n+}\n+\n int main(int argc, char **argv)\n {\n \tchar *commit_id;\nIndex: local-pull.c\n===================================================================\n--- 9138b84eb683fc23a285445f7d7fc5a836ba01cb/local-pull.c  (mode:100644 sha1:e5d834ff2f7d6949ca2c7dd2424c65f6431a839b)\n+++ 8deba080337c75a41cb456cc8b59000654278e59/local-pull.c  (mode:100644 sha1:867e78dbdd2fc5dacdad3c3e3ab5ef1bfde6ba51)\n@@ -73,6 +73,11 @@\n \treturn -1;\n }\n \n+int fetch_ref(char *ref, unsigned char *sha1)\n+{\n+\treturn -1;\n+}\n+\n static const char *local_pull_usage = \n \"git-local-pull [-c] [-t] [-a] [-l] [-s] [-n] [-v] [-d] commit-id path\";\n \nIndex: pull.c\n===================================================================\n--- 9138b84eb683fc23a285445f7d7fc5a836ba01cb/pull.c  (mode:100644 sha1:cd77738ac62be17e7382bc3b368e686f11f7098d)\n+++ 8deba080337c75a41cb456cc8b59000654278e59/pull.c  (mode:100644 sha1:a60f1e49bda1bf12e11e0abccfaf4201130f4303)\n@@ -3,6 +3,11 @@\n #include \"cache.h\"\n #include \"commit.h\"\n #include \"tree.h\"\n+#include \"refs.h\"\n+\n+const char *write_ref = NULL;\n+\n+const unsigned char *current_ref = NULL;\n \n int get_tree = 0;\n int get_history = 0;\n@@ -105,16 +110,42 @@\n \treturn 0;\n }\n \n+static int interpret_target(char *target, unsigned char *sha1)\n+{\n+\tif (!get_sha1_hex(target, sha1))\n+\t\treturn 0;\n+\tif (!check_ref_format(target)) {\n+\t\tif (!fetch_ref(target, sha1)) {\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\treturn -1;\n+}\n+\n+\n int pull(char *target)\n {\n-\tint retval;\n \tunsigned char sha1[20];\n-\tretval = get_sha1_hex(target, sha1);\n-\tif (retval)\n-\t\treturn retval;\n-\tretval = make_sure_we_have_it(commitS, sha1);\n-\tif (retval)\n-\t\treturn retval;\n-\tmemcpy(current_commit_sha1, sha1, 20);\n-\treturn process_commit(sha1);\n+\tint fd = -1;\n+\n+\tif (write_ref && current_ref) {\n+\t\tfd = lock_ref_sha1(write_ref, current_ref);\n+\t\tif (fd < 0)\n+\t\t\treturn -1;\n+\t}\n+\n+\tif (interpret_target(target, sha1))\n+\t\treturn error(\"Could not interpret %s as something to pull\",\n+\t\t\t     target);\n+\tif (process_commit(sha1))\n+\t\treturn -1;\n+\t\n+\tif (write_ref) {\n+\t\tif (current_ref) {\n+\t\t\twrite_ref_sha1(write_ref, fd, sha1);\n+\t\t} else {\n+\t\t\twrite_ref_sha1_unlocked(write_ref, sha1);\n+\t\t}\n+\t}\n+\treturn 0;\n }\nIndex: pull.h\n===================================================================\n--- 9138b84eb683fc23a285445f7d7fc5a836ba01cb/pull.h  (mode:100644 sha1:3cd14cfb811a755a8770a0d01e8e2f96ba604058)\n+++ 8deba080337c75a41cb456cc8b59000654278e59/pull.h  (mode:100644 sha1:83295892d1e401e4719ae26f16de07d6eb61a8d2)\n@@ -4,6 +4,14 @@\n /** To be provided by the particular implementation. **/\n extern int fetch(unsigned char *sha1);\n \n+extern int fetch_ref(char *ref, unsigned char *sha1);\n+\n+/** If set, the ref filename to write the target value to. **/\n+extern const char *write_ref;\n+\n+/** If set, the hash that the current value of write_ref must be. **/\n+extern const unsigned char *current_ref;\n+\n /** Set to fetch the target tree. */\n extern int get_tree;\n \nIndex: ssh-pull.c\n===================================================================\n--- 9138b84eb683fc23a285445f7d7fc5a836ba01cb/ssh-pull.c  (mode:100644 sha1:f4ab89836455a40aaab3ff4114396185f6d5655a)\n+++ 8deba080337c75a41cb456cc8b59000654278e59/ssh-pull.c  (mode:100644 sha1:c0cee73facbbb3ced2e566789ba1dda57b245f47)\n@@ -39,6 +39,11 @@\n \treturn 0;\n }\n \n+int fetch_ref(char *ref, unsigned char *sha1)\n+{\n+\treturn -1;\n+}\n+\n int main(int argc, char **argv)\n {\n \tchar *commit_id;\n\n"},{"id":"4654","messageId":"Pine.LNX.4.21.0506061638300.30848-100000@iabervon.org","threadId":"847","inReplyTo":"Pine.LNX.4.21.0506061616590.30848-100000@iabervon.org","subject":"[PATCH 4/4] -w support for git-ssh-pull/push","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-06-06T20:43:27Z","receivedAt":"2005-06-06T20:43:27Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"This adds support for -w to git-ssh-pull and git-ssh-push to make\nreceiving side write the commit that was transferred to a reference file.\n\nIndex: ssh-pull.c\n===================================================================\n--- 8deba080337c75a41cb456cc8b59000654278e59/ssh-pull.c  (mode:100644 sha1:c0cee73facbbb3ced2e566789ba1dda57b245f47)\n+++ 8293f31cb78c1c7aaf6e521e99a9d2d2a05fabec/ssh-pull.c  (mode:100644 sha1:3d1ff5ef0107da9f56f5f7024af9e2d02f7eec57)\n@@ -2,6 +2,7 @@\n #include \"commit.h\"\n #include \"rsh.h\"\n #include \"pull.h\"\n+#include \"refs.h\"\n \n static int fd_in;\n static int fd_out;\n@@ -41,7 +42,15 @@\n \n int fetch_ref(char *ref, unsigned char *sha1)\n {\n-\treturn -1;\n+\tsigned char remote;\n+\tchar type = 'r';\n+\twrite(fd_out, &type, 1);\n+\twrite(fd_out, ref, strlen(ref) + 1);\n+\tread(fd_in, &remote, 1);\n+\tif (remote < 0)\n+\t\treturn remote;\n+\tread(fd_in, sha1, 20);\n+\treturn 0;\n }\n \n int main(int argc, char **argv)\n@@ -63,11 +72,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-ssh-pull [-c] [-t] [-a] [-v] [-d] commit-id url\");\n+\t\tusage(\"git-ssh-pull [-c] [-t] [-a] [-v] [-d] [-w ref] commit-id url\");\n \t\treturn 1;\n \t}\n \tcommit_id = argv[arg];\nIndex: ssh-push.c\n===================================================================\n--- 8deba080337c75a41cb456cc8b59000654278e59/ssh-push.c  (mode:100644 sha1:bd381ac9d1787dc979b1eba5bd72c1fd644a094b)\n+++ 8293f31cb78c1c7aaf6e521e99a9d2d2a05fabec/ssh-push.c  (mode:100644 sha1:79fb6fc05f859a9daa4597296bfe8c1440949833)\n@@ -1,7 +1,6 @@\n #include \"cache.h\"\n #include \"rsh.h\"\n-#include <sys/socket.h>\n-#include <errno.h>\n+#include \"refs.h\"\n \n unsigned char local_version = 1;\n unsigned char remote_version = 0;\n@@ -64,6 +63,27 @@\n \treturn 0;\n }\n \n+int serve_ref(int fd_in, int fd_out)\n+{\n+\tchar ref[PATH_MAX];\n+\tunsigned char sha1[20];\n+\tint posn = 0;\n+\tsigned char remote = 0;\n+\tdo {\n+\t\tif (read(fd_in, ref + posn, 1) < 1)\n+\t\t\treturn -1;\n+\t\tposn++;\n+\t} while (ref[posn - 1]);\n+\tif (get_ref_sha1(ref, sha1))\n+\t\tremote = -1;\n+\twrite(fd_out, &remote, 1);\n+\tif (remote)\n+\t\treturn 0;\n+\twrite(fd_out, sha1, 20);\n+        return 0;\n+}\n+\n+\n void service(int fd_in, int fd_out) {\n \tchar type;\n \tint retval;\n@@ -78,6 +98,8 @@\n \t\t\treturn;\n \t\tif (type == 'o' && serve_object(fd_in, fd_out))\n \t\t\treturn;\n+\t\tif (type == 'r' && serve_ref(fd_in, fd_out))\n+\t\t\treturn;\n \t} while (1);\n }\n \n@@ -88,10 +110,12 @@\n         char *url;\n \tint fd_in, fd_out;\n \twhile (arg < argc && argv[arg][0] == '-') {\n+\t\tif (argv[arg][1] == 'w')\n+\t\t\targ++;\n                 arg++;\n         }\n         if (argc < arg + 2) {\n-\t\tusage(\"git-ssh-push [-c] [-t] [-a] commit-id url\");\n+\t\tusage(\"git-ssh-push [-c] [-t] [-a] [-w ref] commit-id url\");\n                 return 1;\n         }\n \tcommit_id = argv[arg];\n\n"},{"id":"4663","messageId":"Pine.LNX.4.58.0506062008560.2286@ppc970.osdl.org","threadId":"847","inReplyTo":"Pine.LNX.4.21.0506061616590.30848-100000@iabervon.org","subject":"Re: [PATCH 0/4] Writing refs in git-ssh-push","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-06-07T03:17:21Z","receivedAt":"2005-06-07T03:17:21Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nTwo comments on git-ssh-push from a quick try-to-use-it-but-fail..\n\n - hardcoding the name of the command on the other side kind of sucks. \n   Especially when the user may end up having to install his own version\n   under his own subdirectory. You really want to have some way of saying \n   \"execute /home/user/bin/git-ssh-pull\", and since it will depend on the \n   site you're pushing to, it should probably be available as a cmd line \n   option.\n\n   I have a\n\n\tPATH=$PATH:~/bin\n\n   in my .bashrc, but sshd at the other end doesn't end up caring..\n\n - the host/path parsing is pretty simplistic and just silly. Nobody I \n   know uses that ssh://host/path format, people use the shorter host:path \n   format.\n\nBoth look pretty simple to fix, but now I'm going to put the kids to bed.\n\n\t\tLinus\n"},{"id":"4664","messageId":"Pine.LNX.4.21.0506070032410.30848-100000@iabervon.org","threadId":"847","inReplyTo":"Pine.LNX.4.58.0506062008560.2286@ppc970.osdl.org","subject":"Re: [PATCH 0/4] Writing refs in git-ssh-push","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-06-07T05:22:37Z","receivedAt":"2005-06-07T05:22:37Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Mon, 6 Jun 2005, Linus Torvalds wrote:\n\n> Two comments on git-ssh-push from a quick try-to-use-it-but-fail..\n> \n>  - hardcoding the name of the command on the other side kind of sucks. \n>    Especially when the user may end up having to install his own version\n>    under his own subdirectory. You really want to have some way of saying \n>    \"execute /home/user/bin/git-ssh-pull\", and since it will depend on the \n>    site you're pushing to, it should probably be available as a cmd line \n>    option.\n> \n>    I have a\n> \n> \tPATH=$PATH:~/bin\n> \n>    in my .bashrc, but sshd at the other end doesn't end up caring..\n\nsshd is pretty odd that way; I think ~/.ssh/environment might get you your\nlocal path. I thought it was just my sshd that was strange like that, but\nit's probably common if yours does it too. I'm not sure if there's a\nstandard way to pick up a per-user version of the remote program. It seems\nlike cvs doesn't do anything clever, and sftp makes it a compile-time\noption.\n\nI think an environment variable for the directory to find\ngit-ssh-(other) in would be easiest to script when needed and would also\nreduce the chances of specifying the wrong program on the remote side\n(which would generate really confusing errors).\n\n>  - the host/path parsing is pretty simplistic and just silly. Nobody I \n>    know uses that ssh://host/path format, people use the shorter host:path \n>    format.\n\nI was going for uniformity between git-http-pull and git-ssh-pull, and\nbetween git-ssh-pull and git-ssh-push. But user@host:path is probably the\nright thing, although Radoslaw (cc:ed) will want to propose something for\nSSH on a non-standard port.\n\n> Both look pretty simple to fix, but now I'm going to put the kids to bed.\n\nYeah, they're usability issues, and I'm too willing to put up with my own\nprograms being awkward.\n\n\t-Daniel\n*This .sig left intentionally blank*\n\n"},{"id":"4665","messageId":"42A536A2.3040809@tuxrocks.com","threadId":"847","inReplyTo":"Pine.LNX.4.21.0506070032410.30848-100000@iabervon.org","subject":"Re: [PATCH 0/4] Writing refs in git-ssh-push","fromName":"Frank Sorenson","fromEmail":"frank@tuxrocks.com","sentAt":"2005-06-07T05:54:42Z","receivedAt":"2005-06-07T05:54:42Z","isPatch":true,"sender":{"key":"frank@tuxrocks.com","avatar":null},"body":"-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\nDaniel Barkalow wrote:\n> On Mon, 6 Jun 2005, Linus Torvalds wrote:\n> \n> \n>>Two comments on git-ssh-push from a quick try-to-use-it-but-fail..\n>>\n>> - hardcoding the name of the command on the other side kind of sucks. \n>>   Especially when the user may end up having to install his own version\n>>   under his own subdirectory. You really want to have some way of saying \n>>   \"execute /home/user/bin/git-ssh-pull\", and since it will depend on the \n>>   site you're pushing to, it should probably be available as a cmd line \n>>   option.\n>>\n>>   I have a\n>>\n>>\tPATH=$PATH:~/bin\n>>\n>>   in my .bashrc, but sshd at the other end doesn't end up caring..\n> \n> \n> sshd is pretty odd that way; I think ~/.ssh/environment might get you your\n> local path. I thought it was just my sshd that was strange like that, but\n> it's probably common if yours does it too. I'm not sure if there's a\n> standard way to pick up a per-user version of the remote program. It seems\n> like cvs doesn't do anything clever, and sftp makes it a compile-time\n> option.\n> \n> I think an environment variable for the directory to find\n> git-ssh-(other) in would be easiest to script when needed and would also\n> reduce the chances of specifying the wrong program on the remote side\n> (which would generate really confusing errors).\n\n- From the ssh(1) manpage (openssh):\nAdditionally, ssh reads $HOME/.ssh/environment, and adds lines of the\nformat \"VARNAME=value\" to the environment if the file exists and if\nusers are allowed to change their environment.  For more information,\nsee the PermitUserEnvironment option in sshd_config(5).\n\nThe default given in sshd_config(5) is not to allow the user-specified\nenvironment, because \"Enabling environment processing may enable users\nto bypass access restrictions in some configurations using mechanisms\nsuch as LD_PRELOAD.\"\n\nIt looks like something we probably can't count on for sure.\n\nFrank\n- --\nFrank Sorenson - KD7TZK\nSystems Manager, Computer Science Department\nBrigham Young University\nfrank@tuxrocks.com\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.2.6 (GNU/Linux)\nComment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org\n\niD8DBQFCpTaiaI0dwg4A47wRAhoJAJ9h4MUqGZWsT7+22FHaavd2N4ETqQCfTYR3\n4qibBinO4TUgsdTNMrtgaxk=\n=Uutj\n-----END PGP SIGNATURE-----\n"},{"id":"4667","messageId":"20050607073045.GZ3669@cip.informatik.uni-erlangen.de","threadId":"847","inReplyTo":"Pine.LNX.4.58.0506062008560.2286@ppc970.osdl.org","subject":"Re: [PATCH 0/4] Writing refs in git-ssh-push","fromName":"Thomas Glanzmann","fromEmail":"sithglan@stud.uni-erlangen.de","sentAt":"2005-06-07T07:30:45Z","receivedAt":"2005-06-07T07:30:45Z","isPatch":true,"sender":{"key":"sithglan@stud.uni-erlangen.de","avatar":null},"body":"Hello,\n\n> \tPATH=$PATH:~/bin in my .bashrc,\n\nthis should work because ssh executes a *not* login shell when you execute a\nremote command. And bash reads .bashrc always and .bash_profile only for login\nshell. Is bash your login shell?\n\nFor me it works:\n\n(excalibur) [~] cat .bashrc\nexport PATH=$PATH:~/bin\n(excalibur) [~] ssh localhost env | grep PATH\nPATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/cip/adm/sithglan/bin\n\nIn university I had to put the following in my .cshrc (because I have tcsh as\nlogin shell and can't change it) to make bk push and stuff working:\n\n(faui00u) [~] cat .cshrc\nsetenv PATH /opt/csw/bin:/usr/X11R6/bin:/sbin:/usr/bin:/usr/sbin:/local/bin:/bin:/local/bitkeeper/bin\n\n\tThomas\n"},{"id":"4672","messageId":"1118150337.8970.49.camel@jmcmullan.timesys","threadId":"847","inReplyTo":"Pine.LNX.4.21.0506061635070.30848-100000@iabervon.org","subject":"Re: [PATCH 3/4] Generic support for pulling refs","fromName":"McMullan, Jason","fromEmail":"jason.mcmullan@timesys.com","sentAt":"2005-06-07T13:18:56Z","receivedAt":"2005-06-07T13:18:56Z","isPatch":true,"sender":{"key":"jason.mcmullan@timesys.com","avatar":null},"body":"On Mon, 2005-06-06 at 16:38 -0400, Daniel Barkalow wrote:\n> This adds support to pull.c for requesting a reference and writing it to a\n> file. All of the git-*-pull programs get stubs for now.\n>\n> [snip snip]\n\nWell, looks like you beat me to the punch, Daniel!\n\nI hereby concede the Deathmatch to git-ssh-pu{sh,ll}, and withdraw\ngit-sync from consideration.\n\nWay to go Daniel!\n\n\"Welcome to Git Thunderdome. Two codes enter, one code leaves.\"\n\n-- \nJason McMullan <jason.mcmullan@timesys.com>\nTimeSys Corporation\n\n"},{"id":"4678","messageId":"Pine.LNX.4.21.0506071134450.30848-100000@iabervon.org","threadId":"847","inReplyTo":"1118150337.8970.49.camel@jmcmullan.timesys","subject":"Re: [PATCH 3/4] Generic support for pulling refs","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-06-07T16:45:03Z","receivedAt":"2005-06-07T16:45:03Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Tue, 7 Jun 2005, McMullan, Jason wrote:\n\n> Well, looks like you beat me to the punch, Daniel!\n> \n> I hereby concede the Deathmatch to git-ssh-pu{sh,ll}, and withdraw\n> git-sync from consideration.\n> \n> Way to go Daniel!\n> \n> \"Welcome to Git Thunderdome. Two codes enter, one code leaves.\"\n\nOf course, my secret is that I actually wrote it all in advance, so I just\nhad to polish it up, rebase, and document the program that was already\nin...\n\nBack on topic, are there things you need that git-ssh-* doesn't do? It\nwould still be good to get the code to write objects to temporary files\nuntil they're determined to be valid.\n\n\t-Daniel\n*This .sig left intentionally blank*\n\n"}]}