git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Steffen Prohaska <prohaska@zib.de>
Cc: Mark Levedahl <mlevedahl@gmail.com>,
	Junio C Hamano <gitster@pobox.com>,
	Git Mailing List <git@vger.kernel.org>,
	"Shawn O. Pearce" <spearce@spearce.org>,
	Sebastian Schuberth <sschuberth@gmail.com>
Subject: Re: git on Cygwin: Not a valid object name HEAD
Date: Tue, 7 Aug 2007 14:44:21 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LFD.0.999.0708071439021.5037@woody.linux-foundation.org> (raw)
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));

  reply	other threads:[~2007-08-07 21:47 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-07  9:02 git on Cygwin: Not a valid object name HEAD Sebastian Schuberth
2007-08-07 11:58 ` Johannes Schindelin
2007-08-07 12:13   ` Sebastian Schuberth
2007-08-07 13:18     ` Sebastian Schuberth
2007-08-07 14:36       ` Shawn O. Pearce
2007-08-07 14:58         ` Brian Downing
2007-08-07 15:27           ` Sebastian Schuberth
2007-08-07 17:11           ` Steffen Prohaska
2007-08-07 17:42             ` Mark Levedahl
2007-08-07 19:41               ` Steffen Prohaska
2007-08-07 21:44                 ` Linus Torvalds [this message]
2007-08-07 22:28                   ` Junio C Hamano
2007-08-08  3:47                     ` Linus Torvalds
2007-08-07 22:46                   ` Steffen Prohaska
2007-08-07 22:49                     ` [PATCH] cygwin: added fopen "b" and open O_BINARY to support cygwin's textmode Steffen Prohaska
2007-08-07 22:49                       ` [PATCH] tests: added d2u to have unix style testfiles even in textmode Steffen Prohaska
2007-08-08  3:03                         ` Linus Torvalds
2007-08-08  5:00                           ` Steffen Prohaska
2007-08-07 23:20                     ` git on Cygwin: Not a valid object name HEAD Steffen Prohaska
2007-08-08  4:25                     ` Brian Downing
2007-08-08  5:46                       ` Steffen Prohaska
2007-08-07 22:26                 ` Junio C Hamano
2007-08-08  7:55                   ` Sebastian Schuberth
2007-08-08 13:50                 ` Mark Levedahl
2007-08-08 15:51                   ` Steffen Prohaska
2007-08-08 16:41                     ` Mark Levedahl
2007-08-08 17:20                       ` Johannes Schindelin
2007-08-08 19:37                         ` Steffen Prohaska
2007-08-08 20:13                           ` Steffen Prohaska
2007-08-08 20:36                             ` Steffen Prohaska
2007-08-08 23:07                               ` Mark Levedahl
2007-08-09  4:59                                 ` Steffen Prohaska
2007-08-09  6:01                               ` Marius Storm-Olsen
2007-08-09  6:38                                 ` Steffen Prohaska
2007-08-09  6:47                                   ` Marius Storm-Olsen
2007-08-09  8:50                                 ` Johannes Schindelin
2007-08-09  9:00                                   ` Marius Storm-Olsen
2007-08-09 10:33                                     ` Steffen Prohaska
2007-08-08 21:30                           ` Johannes Schindelin
2007-08-09  6:20                             ` Steffen Prohaska
2007-08-10  6:07                               ` Torgil Svensson
2007-08-10  7:19                                 ` Steffen Prohaska
2007-08-10 10:30                                   ` Johannes Schindelin
2007-08-10 11:14                                     ` Steffen Prohaska
2007-08-10 22:31                                   ` Torgil Svensson
2007-08-11  0:43                                     ` Steffen Prohaska
2007-08-13 10:50                                       ` Johannes Schindelin
2007-08-15  0:04                                       ` Torgil Svensson
2007-08-15  5:22                                         ` Steffen Prohaska
2007-08-15  5:30                                           ` David Kastrup
2007-08-15  5:43                                             ` Steffen Prohaska
2007-08-15  6:59                                               ` David Kastrup
     [not found]                                               ` <86k5rx474o.fsf@lola.quinscape.zz>
2007-08-15  7:38                                                 ` Shawn O. Pearce
2007-08-15 12:42                                                   ` Mark Levedahl
2007-08-15 12:48                                                     ` Mark Levedahl
2007-08-15 13:06                                                       ` Steffen Prohaska
2007-08-16  0:27                                                         ` Mark Levedahl
2007-08-16  6:04                                                           ` Steffen Prohaska
2007-08-16 11:55                                                             ` Mark Levedahl
2007-08-07 15:29       ` Mark Levedahl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.0.999.0708071439021.5037@woody.linux-foundation.org \
    --to=torvalds@linux-foundation.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=mlevedahl@gmail.com \
    --cc=prohaska@zib.de \
    --cc=spearce@spearce.org \
    --cc=sschuberth@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).