{"thread":{"id":"6311","subject":"[PATCH] Test for failing pread() on cygwin.","startedAt":"2007-01-09T18:51:55Z","lastAt":"2007-01-09T20:21:55Z","messageCount":3,"participants":["Stefan-W. Hahn","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"31269","messageId":"48882.0957871669$1168368739@news.gmane.org","threadId":"6311","inReplyTo":"11683687161816-git-send-email-","subject":"[PATCH] Test for failing pread() on cygwin.","fromName":"Stefan-W. Hahn","fromEmail":"stefan.hahn@s-hahn.de","sentAt":"2007-01-09T18:51:55Z","receivedAt":"2007-01-09T18:51:55Z","isPatch":true,"sender":{"key":"stefan.hahn@s-hahn.de","avatar":null},"body":"From: Stefan-W. Hahn <stefan.hahn@s-hahn.de>\n\n\nSigned-off-by: Stefan-W. Hahn <stefan.hahn@s-hahn.de>\n---\n t/t5610-clone-fail.sh |   29 +++++++++++++++++++++++++++++\n 1 files changed, 29 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t5610-clone-fail.sh b/t/t5610-clone-fail.sh\nnew file mode 100755\nindex 0000000..d30b25e\n--- /dev/null\n+++ b/t/t5610-clone-fail.sh\n@@ -0,0 +1,29 @@\n+#!/bin/sh\n+#\n+# Copyright (C) 2007 Stefan-W. Hahn <stefan.hahn@s-hahn.de>\n+#\n+\n+test_description='test git-clone failure on cygwin using pread()\n+\n+This test covers the fact that git-clone fails, if pread() does not\n+work properly, because the size of objects makes it neccessary to\n+read data from a not zero offset.'\n+\n+. ./test-lib.sh\n+\n+# Need a repo to clone\n+test_create_repo foo2\n+\n+GIT_AUTHOR_EMAIL=xxxxxxxx@yyyyyyyy.yyyyy.yyyyyyy.yyy\n+GIT_COMMITTER_EMAIL=xxxxxxxx@yyyyyyyy.yyyyy.yyyyyyy.yyy\n+export GIT_AUTHOR_EMAIL\n+export GIT_COMMITTER_EMAIL\n+\n+(cd foo2 && echo \"Hello\" > file && git add file && git commit -m 'add file' >/dev/null 2>&1)\n+(cd foo2 && echo \"Hello2\" >> file && git commit -a -m 'test' >/dev/null 2>&1)\n+\n+test_expect_success \\\n+    'clone with resolving' \\\n+    'git-clone foo2 bar2'\n+\n+test_done\n-- \n1.4.4.4.g46aa\n"},{"id":"31270","messageId":"41319.3372231492$1168368741@news.gmane.org","threadId":"6311","inReplyTo":"11683687162492-git-send-email-","subject":"[PATCH] Replacing the system call pread() with lseek()/xread()/lseek() sequence.","fromName":"Stefan-W. Hahn","fromEmail":"stefan.hahn@s-hahn.de","sentAt":"2007-01-09T18:51:56Z","receivedAt":"2007-01-09T18:51:56Z","isPatch":true,"sender":{"key":"stefan.hahn@s-hahn.de","avatar":null},"body":"From: Stefan-W. Hahn <stefan.hahn@s-hahn.de>\n\nUsing cygwin with cygwin.dll before 1.5.22 the system call pread() is buggy.\nThis patch introduces NO_PREAD. If NO_PREAD is set git uses a sequence of\nlseek()/xread()/lseek() to emulate pread.\n\nSigned-off-by: Stefan-W. Hahn <stefan.hahn@s-hahn.de>\n---\n Makefile          |    7 +++++++\n compat/pread.c    |   15 +++++++++++++++\n git-compat-util.h |    5 +++++\n 3 files changed, 27 insertions(+), 0 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 6c12bc6..47af0de 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -69,6 +69,9 @@ all:\n #\n # Define NO_MMAP if you want to avoid mmap.\n #\n+# Define NO_PREAD if you have a problem with pread() system call (i.e.\n+# cygwin.dll before v1.5.22).\n+#\n # Define NO_FAST_WORKING_DIRECTORY if accessing objects in pack files is\n # generally faster on your platform than accessing the working directory.\n #\n@@ -523,6 +526,10 @@ ifdef NO_MMAP\n \tCOMPAT_CFLAGS += -DNO_MMAP\n \tCOMPAT_OBJS += compat/mmap.o\n endif\n+ifdef NO_PREAD\n+\tCOMPAT_CFLAGS += -DNO_PREAD\n+\tCOMPAT_OBJS += compat/pread.o\n+endif\n ifdef NO_FAST_WORKING_DIRECTORY\n \tBASIC_CFLAGS += -DNO_FAST_WORKING_DIRECTORY\n endif\ndiff --git a/compat/pread.c b/compat/pread.c\nnew file mode 100644\nindex 0000000..cd1da87\n--- /dev/null\n+++ b/compat/pread.c\n@@ -0,0 +1,15 @@\n+#include \"../git-compat-util.h\"\n+\n+ssize_t git_pread(int fd,void *buf,size_t count,off_t offset)\n+{\n+        off_t current_offset = lseek(fd, 0, SEEK_CUR);\n+\n+        if (lseek(fd, offset, SEEK_SET) < 0)\n+                return EINVAL;\n+\n+        ssize_t rc=xread(fd, buf, count);\n+\n+        if (current_offset != lseek(fd, current_offset, SEEK_SET))\n+                return EINVAL;\n+        return rc;\n+}\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex e023bf1..00b14df 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -107,6 +107,11 @@ extern int git_munmap(void *start, size_t length);\n #define DEFAULT_PACKED_GIT_LIMIT \\\n \t((1024L * 1024L) * (sizeof(void*) >= 8 ? 8192 : 256))\n \n+#ifdef NO_PREAD\n+#define pread git_pread\n+extern ssize_t git_pread(int fd,void *buf,size_t count,off_t offset);\n+#endif\n+\n #ifdef NO_SETENV\n #define setenv gitsetenv\n extern int gitsetenv(const char *, const char *, int);\n-- \n1.4.4.4.g46aa\n"},{"id":"31273","messageId":"7v1wm4kl24.fsf@assigned-by-dhcp.cox.net","threadId":"6311","inReplyTo":"41319.3372231492$1168368741@news.gmane.org","subject":"Re: [PATCH] Replacing the system call pread() with lseek()/xread()/lseek() sequence.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-01-09T20:21:55Z","receivedAt":"2007-01-09T20:21:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Stefan-W. Hahn\" <stefan.hahn@s-hahn.de> writes:\n\n> Using cygwin with cygwin.dll before 1.5.22 the system call pread() is buggy.\n> This patch introduces NO_PREAD. If NO_PREAD is set git uses a sequence of\n> lseek()/xread()/lseek() to emulate pread.\n>\n> Signed-off-by: Stefan-W. Hahn <stefan.hahn@s-hahn.de>\n\nThanks.\n\n> +# Define NO_PREAD if you have a problem with pread() system call (i.e.\n> +# cygwin.dll before v1.5.22).\n> +#\n\nI would have preferred e.g. not i.e..\n\n> diff --git a/compat/pread.c b/compat/pread.c\n> new file mode 100644\n> index 0000000..cd1da87\n> --- /dev/null\n> +++ b/compat/pread.c\n> @@ -0,0 +1,15 @@\n> +#include \"../git-compat-util.h\"\n> +\n> +ssize_t git_pread(int fd,void *buf,size_t count,off_t offset)\n\nStyle: s/,/, /; applies to git-compat-util.h as well.\n\n> +{\n> +        off_t current_offset = lseek(fd, 0, SEEK_CUR);\n> +\n> +        if (lseek(fd, offset, SEEK_SET) < 0)\n> +                return EINVAL;\n> +\n> +        ssize_t rc=xread(fd, buf, count);\n\nStyle: please don't have declaration after statement.  Yes, it\nis in the more recent ANSI, but the rest of git has avoided it\nso far and having the decls upfront makes it easier to read.\n\nI do not think you would want to return EINVAL.\n\nAndy's read_in_full() is now on 'master' so please use it\ninstead to avoid short read.\n"}]}