On 09/19/2017 08:22 AM, Michael Haggerty wrote: > Keep a copy of the `packed-refs` file contents in memory for as long > as a `packed_ref_cache` object is in use: > > * If the system allows it, keep the `packed-refs` file mmapped. > > * If not (either because the system doesn't support `mmap()` at all, > or because a file that is currently mmapped cannot be replaced via > `rename()`), then make a copy of the file's contents in > heap-allocated space, and keep that around instead. > > We base the choice of behavior on a new build-time switch, > `MMAP_PREVENTS_DELETE`. By default, this switch is set for Windows > variants. > > This whole change is still pointless, because we only read the > `packed-refs` file contents immediately after instantiating the > `packed_ref_cache`. But that will soon change. > > Signed-off-by: Michael Haggerty <mhagger@xxxxxxxxxxxx> > --- > Makefile | 10 +++ > config.mak.uname | 3 + > refs/packed-backend.c | 184 ++++++++++++++++++++++++++++++++++++++------------ > 3 files changed, 155 insertions(+), 42 deletions(-) > > diff --git a/Makefile b/Makefile > index f2bb7f2f63..7a49f99c4f 100644 > [...] > diff --git a/refs/packed-backend.c b/refs/packed-backend.c > index 0fe41a7203..4981516f1e 100644 > --- a/refs/packed-backend.c > +++ b/refs/packed-backend.c > [...] > @@ -304,6 +371,61 @@ struct ref_iterator *mmapped_ref_iterator_begin( > return ref_iterator; > } > > +/* > + * Depending on `mmap_strategy`, either mmap or read the contents of > + * the `packed-refs` file into the `packed_refs` instance. Return 1 if > + * the file existed and was read, or 0 if the file was absent. Die on > + * errors. > + */ > +static int load_contents(struct packed_ref_cache *packed_refs) > +{ > + int fd; > + struct stat st; > + size_t size, bytes_read; Coverity helpfully pointed out that `bytes_read` has to be signed: `ssize_t`. I'll fix that in the next round after waiting for other comments. > [...] Michael