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

Re: git on Cygwin: Not a valid object name HEAD

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Aug 7, 2007, 21:44 UTC
Message-ID
<alpine.LFD.0.999.0708071439021.5037@woody.linux-foundation.org>
In-Reply-To
<07BB2580-4406-496F-8ACE-F6A03D1687BE@zib.de>
On Tue, 7 Aug 2007, Steffen Prohaska wrote:
>
> Is there any chance that patches would be accepted that try to
> do so? Even if they add "b" to fopen and O_BINARY to open, which
> both are useless on Unix?

I certainly don't think it would be wrong to add O_BINARY to the open() parameters (and "b" to fopen() and friends), if it makes a difference.

Add a
	#ifndef O_BINARY
	#define O_BINARY 0
	#endif
and it should be harmless anywhere else.

So if you're willing to test, and extend on this, maybe something like this gets you started (I think the main issue will be the object files, no?)

		Linus
---
diff --git a/sha1_file.c b/sha1_file.c
index aca741b..0f613c0 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -23,6 +23,10 @@
 #endif
 #endif
 
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
 #ifdef NO_C99_FORMAT
 #define SZ_FMT "lu"
 #else
@@ -444,7 +448,7 @@ static int check_packed_git_idx(const char *path,  struct packed_git *p)
 	struct pack_idx_header *hdr;
 	size_t idx_size;
 	uint32_t version, nr, i, *index;
-	int fd = open(path, O_RDONLY);
+	int fd = open(path, O_BINARY | O_RDONLY);
 	struct stat st;
 
 	if (fd < 0)
@@ -631,7 +635,7 @@ static int open_packed_git_1(struct packed_git *p)
 	if (!p->index_data && open_pack_index(p))
 		return error("packfile %s index unavailable", p->pack_name);
 
-	p->pack_fd = open(p->pack_name, O_RDONLY);
+	p->pack_fd = open(p->pack_name, O_BINARY | O_RDONLY);
 	if (p->pack_fd < 0 || fstat(p->pack_fd, &st))
 		return -1;
 
@@ -983,12 +987,12 @@ static void *map_sha1_file(const unsigned char *sha1, unsigned long *size)
 		return NULL;
 	}
 
-	fd = open(filename, O_RDONLY | sha1_file_open_flag);
+	fd = open(filename, O_BINARY | O_RDONLY | sha1_file_open_flag);
 	if (fd < 0) {
 		/* See if it works without O_NOATIME */
 		switch (sha1_file_open_flag) {
 		default:
-			fd = open(filename, O_RDONLY);
+			fd = open(filename, O_BINARY | O_RDONLY);
 			if (fd >= 0)
 				break;
 		/* Fallthrough */
@@ -2023,6 +2027,12 @@ int move_temp_to_file(const char *tmpfile, const char *filename)
 	return 0;
 }
 
+static void close_or_die(int fd, const char *file)
+{
+	if (close(fd))
+		die("unable to close %s (%s)", file, strerror(errno));
+}
+
 static int write_buffer(int fd, const void *buf, size_t len)
 {
 	if (write_in_full(fd, buf, len) < 0)
@@ -2059,7 +2069,7 @@ int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned cha
 		hashcpy(returnsha1, sha1);
 	if (has_sha1_file(sha1))
 		return 0;
-	fd = open(filename, O_RDONLY);
+	fd = open(filename, O_BINARY | O_RDONLY);
 	if (fd >= 0) {
 		/*
 		 * FIXME!!! We might do collision checking here, but we'd
@@ -2112,11 +2122,9 @@ int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned cha
 
 	size = stream.total_out;
 
-	if (write_buffer(fd, compressed, size) < 0)
-		die("unable to write sha1 file");
+	write_or_die(fd, compressed, size);
 	fchmod(fd, 0444);
-	if (close(fd))
-		die("unable to write sha1 file");
+	close_or_die(fd, "sha1 file");
 	free(compressed);
 
 	return move_temp_to_file(tmpfile, filename);
@@ -2229,8 +2237,7 @@ int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer,
 				SHA1_Update(&c, discard, sizeof(discard) -
 					    stream.avail_out);
 			} while (stream.avail_in && ret == Z_OK);
-			if (write_buffer(local, buffer, *bufposn - stream.avail_in) < 0)
-				die("unable to write sha1 file");
+			write_or_die(local, buffer, *bufposn - stream.avail_in);
 			memmove(buffer, buffer + *bufposn - stream.avail_in,
 				stream.avail_in);
 			*bufposn = stream.avail_in;
@@ -2251,8 +2258,7 @@ int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer,
 	inflateEnd(&stream);
 
 	fchmod(local, 0444);
-	if (close(local) != 0)
-		die("unable to write sha1 file");
+	close_or_die(local, "sha1 file");
 	SHA1_Final(real_sha1, &c);
 	if (ret != Z_STREAM_END) {
 		unlink(tmpfile);
@@ -2412,7 +2418,7 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, int write
 
 	switch (st->st_mode & S_IFMT) {
 	case S_IFREG:
-		fd = open(path, O_RDONLY);
+		fd = open(path, O_BINARY | O_RDONLY);
 		if (fd < 0)
 			return error("open(\"%s\"): %s", path,
 				     strerror(errno));
Previous: Steffen ProhaskaNext: Junio C Hamano
Message 11 of 60 in “git on Cygwin: Not a valid object name HEAD”
  1. Sebastian SchuberthAug 7, 2007
  2. Johannes SchindelinAug 7, 2007
  3. Sebastian SchuberthAug 7, 2007
  4. Sebastian SchuberthAug 7, 2007
  5. Shawn O. PearceAug 7, 2007
  6. Brian DowningAug 7, 2007
  7. Sebastian SchuberthAug 7, 2007
  8. Steffen ProhaskaAug 7, 2007
  9. Mark LevedahlAug 7, 2007
  10. Steffen ProhaskaAug 7, 2007
  11. Linus TorvaldsAug 7, 2007
  12. Junio C HamanoAug 7, 2007
  13. Linus TorvaldsAug 8, 2007
  14. Steffen ProhaskaAug 7, 2007
  15. cygwin: added fopen "b" and open O_BINARY to support cygwin's textmodeSteffen Prohaska, Aug 7, 2007
  16. tests: added d2u to have unix style testfiles even in textmodeSteffen Prohaska, Aug 7, 2007
  17. Linus TorvaldsAug 8, 2007
  18. Steffen ProhaskaAug 8, 2007
  19. Steffen ProhaskaAug 7, 2007
  20. Brian DowningAug 8, 2007
  21. Steffen ProhaskaAug 8, 2007
  22. Junio C HamanoAug 7, 2007
  23. Sebastian SchuberthAug 8, 2007
  24. Mark LevedahlAug 8, 2007
  25. Steffen ProhaskaAug 8, 2007
  26. Mark LevedahlAug 8, 2007
  27. Johannes SchindelinAug 8, 2007
  28. Steffen ProhaskaAug 8, 2007
  29. Steffen ProhaskaAug 8, 2007
  30. Steffen ProhaskaAug 8, 2007
  31. Mark LevedahlAug 8, 2007
  32. Steffen ProhaskaAug 9, 2007
  33. Marius Storm-OlsenAug 9, 2007
  34. Steffen ProhaskaAug 9, 2007
  35. Marius Storm-OlsenAug 9, 2007
  36. Johannes SchindelinAug 9, 2007
  37. Marius Storm-OlsenAug 9, 2007
  38. Steffen ProhaskaAug 9, 2007
  39. Johannes SchindelinAug 8, 2007
  40. Steffen ProhaskaAug 9, 2007
  41. Torgil SvenssonAug 10, 2007
  42. Steffen ProhaskaAug 10, 2007
  43. Johannes SchindelinAug 10, 2007
  44. Steffen ProhaskaAug 10, 2007
  45. Torgil SvenssonAug 10, 2007
  46. Steffen ProhaskaAug 11, 2007
  47. Johannes SchindelinAug 13, 2007
  48. Torgil SvenssonAug 15, 2007
  49. Steffen ProhaskaAug 15, 2007
  50. David KastrupAug 15, 2007
  51. Steffen ProhaskaAug 15, 2007
  52. David KastrupAug 15, 2007
  53. Mark LevedahlAug 7, 2007
  54. Shawn O. PearceAug 15, 2007
  55. Mark LevedahlAug 15, 2007
  56. Mark LevedahlAug 15, 2007
  57. Steffen ProhaskaAug 15, 2007
  58. Mark LevedahlAug 16, 2007
  59. Steffen ProhaskaAug 16, 2007
  60. Mark LevedahlAug 16, 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.