git/list[1] front-page[2] threads[3] people[4] search[5] about
 

problem with git clone on cygwin

From
SHStefan-W. Hahn <stefan.hahn@s-hahn.de>
Date
Jan 6, 2007, 17:03 UTC
Message-ID
<20070106170330.GA8041@scotty.home>
Hi,

running git on Cygwin I have a problem with git clone on local disk, while packing data.

The problem comes with v1.5.0-rc0. I bisected the problem down to commit 6d2fa7 as the first bad commit.

It seems to be a problem with cygwin.dll prior v1.5.22 and pread(), if using an offset!=0. (I'm running cygwin.dll v1.5.21 build date 2006-07-27 and I can't update because of other compatibility problems).

So I tried:
- not to set NO_MMAP to use real mmap
- changing get_data_from_pack() from index-pack.c to used mmap() as
  in 042aea8. (I did this because it directly uses pread().)
This solved the problem for my testcase.

The added testcase also succeeds on Linux but just with v1.4.4 or my patch on Cygwin.

Is there anybody else having the same problem in git universe?
-- 
Stefan-W. Hahn                          It is easy to make things.
/ mailto:stefan.hahn@s-hahn.de /        It is hard to make things simple.			



diff --git a/Makefile b/Makefile
index 180e1e0..afa5d08 100644
--- a/Makefile
+++ b/Makefile
@@ -368,7 +368,7 @@ ifeq ($(uname_O),Cygwin)
 	# There are conflicting reports about this.
 	# On some boxes NO_MMAP is needed, and not so elsewhere.
 	# Try commenting this out if you suspect MMAP is more efficient
-	NO_MMAP = YesPlease
+	#NO_MMAP = YesPlease
 	NO_IPV6 = YesPlease
 	X = .exe
 endif
diff --git a/index-pack.c b/index-pack.c
index 5f6d128..f1d11a0 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -277,25 +277,27 @@ static void *get_data_from_pack(struct object_entry *obj)
 {
 	unsigned long from = obj[0].offset + obj[0].hdr_size;
 	unsigned long len = obj[1].offset - from;
-	unsigned char *src, *data;
+	unsigned pg_offset = from % getpagesize();
+	unsigned char *map, *data;
 	z_stream stream;
 	int st;
 
-	src = xmalloc(len);
-	if (pread(pack_fd, src, len, from) != len)
-		die("cannot pread pack file: %s", strerror(errno));
+	map = mmap(NULL, len + pg_offset, PROT_READ, MAP_PRIVATE,
+		   pack_fd, from - pg_offset);
+	if (map == MAP_FAILED)
+		die("cannot mmap pack file: %s", strerror(errno));
 	data = xmalloc(obj->size);
 	memset(&stream, 0, sizeof(stream));
 	stream.next_out = data;
 	stream.avail_out = obj->size;
-	stream.next_in = src;
+	stream.next_in = map + pg_offset;
 	stream.avail_in = len;
 	inflateInit(&stream);
 	while ((st = inflate(&stream, Z_FINISH)) == Z_OK);
 	inflateEnd(&stream);
 	if (st != Z_STREAM_END || stream.total_out != obj->size)
 		die("serious inflate inconsistency");
-	free(src);
+	munmap(map, len + pg_offset);
 	return data;
 }
 
diff --git a/t/t5610-clone-fail.sh b/t/t5610-clone-fail.sh
new file mode 100755
index 0000000..d46c255
--- /dev/null
+++ b/t/t5610-clone-fail.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+#
+
+test_description='test git-clone failure on cygwin using pread()
+'
+
+. ./test-lib.sh
+
+# Need a repo to clone
+test_create_repo foo2
+
+GIT_AUTHOR_EMAIL=xxxxxxxx@yyyyyyyy.yyyyy.yyyyyyy.yyy
+GIT_COMMITTER_EMAIL=xxxxxxxx@yyyyyyyy.yyyyy.yyyyyyy.yyy
+export GIT_AUTHOR_EMAIL
+export GIT_COMMITTER_EMAIL
+
+(cd foo2 && echo "Hello" > file && git add file && git commit -m 'add file' >/dev/null 2>&1)
+(cd foo2 && echo "Hello2" >> file && git commit -a -m 'test' >/dev/null 2>&1)
+
+test_expect_success \
+    'clone with resolving' \
+    'git-clone foo2 bar2'
+
+test_done
Next: Juergen Ruehle
Message 1 of 12 in “problem with git clone on cygwin”
  1. Stefan-W. HahnJan 6, 2007
  2. Juergen RuehleJan 6, 2007
  3. Shawn O. PearceJan 7, 2007
  4. Replacing the system call pread() with real mmap().Stefan-W. Hahn, Jan 7, 2007
  5. Shawn O. PearceJan 7, 2007
  6. Stefan-W. HahnJan 7, 2007
  7. Johannes SchindelinJan 7, 2007
  8. Stefan-W. HahnJan 7, 2007
  9. Test for failing pread() on cygwin.Stefan-W. Hahn, Jan 7, 2007
  10. Stefan-W. HahnJan 7, 2007
  11. Juergen RuehleJan 7, 2007
  12. Stefan-W. HahnJan 7, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.