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

Re: First cut at git port to Cygwin

From
Alex Riesen <raa.lkml@gmail.com>
Date
Oct 7, 2005, 20:54 UTC
Message-ID
<20051007205450.GA14827@steel.home>
In-Reply-To
<Pine.LNX.4.64.0510070828270.31407@g5.osdl.org>
Linus Torvalds, Fri, Oct 07, 2005 17:34:19 +0200:
Show 27 quoted lines
> > 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:
Previous: Linus TorvaldsNext: Alex Riesen
Message 34 of 62 in “First cut at git port to Cygwin”
  1. H. Peter AnvinSep 29, 2005
  2. Junio C HamanoSep 29, 2005
  3. H. Peter AnvinSep 29, 2005
  4. Martin LanghoffSep 29, 2005
  5. Junio C HamanoSep 29, 2005
  6. H. Peter AnvinSep 29, 2005
  7. Johannes SchindelinSep 29, 2005
  8. H. Peter AnvinSep 29, 2005
  9. H. Peter AnvinSep 29, 2005
  10. Junio C HamanoSep 30, 2005
  11. H. Peter AnvinSep 30, 2005
  12. H. Peter AnvinSep 30, 2005
  13. Alex RiesenOct 4, 2005
  14. Alex RiesenOct 4, 2005
  15. H. Peter AnvinOct 4, 2005
  16. Christopher FaylorOct 5, 2005
  17. H. Peter AnvinOct 4, 2005
  18. Christopher FaylorOct 5, 2005
  19. H. Peter AnvinOct 5, 2005
  20. Alex RiesenOct 5, 2005
  21. Alex RiesenOct 5, 2005
  22. Christopher FaylorOct 5, 2005
  23. Davide LibenziOct 5, 2005
  24. Christopher FaylorOct 5, 2005
  25. H. Peter AnvinOct 5, 2005
  26. Christopher FaylorOct 5, 2005
  27. Davide LibenziOct 5, 2005
  28. Alex RiesenOct 5, 2005
  29. Christopher FaylorOct 5, 2005
  30. Alex RiesenOct 6, 2005
  31. Alex RiesenOct 6, 2005
  32. Alex RiesenOct 7, 2005
  33. Linus TorvaldsOct 7, 2005
  34. Alex RiesenOct 7, 2005
  35. Alex RiesenOct 7, 2005
  36. Chuck LeverOct 7, 2005
  37. Alex RiesenOct 7, 2005
  38. Linus TorvaldsOct 8, 2005
  39. Elfyn McBratneyOct 8, 2005
  40. Elfyn McBratneyOct 8, 2005
  41. Johannes SchindelinOct 8, 2005
  42. Junio C HamanoOct 8, 2005
  43. Johannes SchindelinOct 8, 2005
  44. Junio C HamanoOct 8, 2005
  45. Johannes SchindelinOct 8, 2005
  46. H. Peter AnvinOct 10, 2005
  47. Johannes SchindelinOct 10, 2005
  48. H. Peter AnvinOct 10, 2005
  49. Johannes SchindelinOct 10, 2005
  50. Junio C HamanoOct 10, 2005
  51. Junio C HamanoOct 10, 2005
  52. H. Peter AnvinOct 10, 2005
  53. Daniel BarkalowOct 10, 2005
  54. Alex RiesenOct 8, 2005
  55. Commit text BEFORE the dashes (Re: First cut at git port to Cygwin)Matthias Urlichs, Oct 9, 2005
  56. Jonas FonsecaOct 5, 2005
  57. Johannes SchindelinOct 5, 2005
  58. Fix symbolic ref validationJonas Fonseca, Oct 5, 2005
  59. Junio C HamanoOct 5, 2005
  60. Alex RiesenOct 7, 2005
  61. Elfyn McBratneyOct 8, 2005
  62. H. Peter AnvinOct 10, 2005

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.