Re: First cut at git port to Cygwin

From: Alex Riesen <raa.lkml@gmail.com>
Date: 2005-10-08 06:54:50
Linus Torvalds, Fri, Oct 07, 2005 17:34:19 +0200:
> > it suddenly get worse: now I'm stuck on git-pull.
> > 
> > git-merge-index (called at some point by git-pull) maps the index
> > in, and starts git-merge-one-file for each (or the given) entry in
> > the index.  git-merge-one-file calls git-update-index, which wants
> > to update the index. Which doesn't work, because it's locked by
> > that piece of s$%^.
> 
> NOTE! git doesn't use mmap() because it _needs_ to use mmap(), but because 
> it was simple to do that way, and it's a total idiosyncracy of mine that I 
> often try to mmap the data. I often also tend to do my own allocators 
> instead of using malloc() (see my "sparse" project in case you're 
> interested in other idiosyncracies of mine - macros to do list traversal 
> etc).
> 
> The fact is, "mmap()" isn't really any better than "read()": it has some 
> advantages wrt memory management for the kernel, which is probably one big 
> reason why I do it, but quite frankly, if you were to change every single 
> mmap() to be a "map_file()" instead, and made it optional whether it used 
> mmap() or "malloc + read()", I personally don't think it would be 
> horrible.
> 
> And it might make things much simpler for portability. The "use mmap" 
> approach is very much a unixism, particularly the way unix people do it 
> (mmap followed by close, making the file descriptor "go away"). Sure, 
> other OS's have mmap too, but I think on them it tends to be less commonly 
> used.

"Sounds like a thinly veiled threat or a very effective prodding" 8)

---

Make read_cache copy the index into memory, to improve portability on
other OS's which have mmap too, tend to use it less commonly.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>

diff --git a/read-cache.c b/read-cache.c
--- a/read-cache.c
+++ b/read-cache.c
@@ -497,9 +497,11 @@ int read_cache(void)
 	offset = sizeof(*hdr);
 	for (i = 0; i < active_nr; i++) {
 		struct cache_entry *ce = map + offset;
-		offset = offset + ce_size(ce);
-		active_cache[i] = ce;
+		size_t size = ce_size(ce);
+		offset = offset + size;
+		active_cache[i] = malloc(ce, size);
 	}
+	munmap(map, size);
 	return active_nr;
 
 unmap:
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Sat Oct 08 06:56:16 2005

This archive was generated by hypermail 2.1.8 : 2005-10-08 06:56:20 EST