Merge branch 'rs/discard-index-discard-array'
authorJunio C Hamano <gitster@pobox.com>
Thu, 20 Jun 2013 23:02:30 +0000 (16:02 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 20 Jun 2013 23:02:30 +0000 (16:02 -0700)
* rs/discard-index-discard-array:
read-cache: free cache in discard_index
read-cache: add simple performance test

1  2 
.gitignore
Makefile
read-cache.c
diff --combined .gitignore
index 1640c3ad005adbeecf4b90f92e5d3369c6490697,0a1f93b25a7b185a46bb235eb5a58e558aac24e1..c0e00eb37bb370ce9deee72468fb419bc25cfd62
  /git-remote-ftps
  /git-remote-fd
  /git-remote-ext
 +/git-remote-testgit
  /git-remote-testpy
  /git-remote-testsvn
  /git-repack
  /test-mktemp
  /test-parse-options
  /test-path-utils
+ /test-read-cache
  /test-regex
  /test-revision-walking
  /test-run-command
  /cscope*
  *.obj
  *.lib
 +*.res
  *.sln
  *.suo
  *.ncb
diff --combined Makefile
index 0d2d0cdd3e8b1304ee4348f6659c35ae2968aaeb,b0ee1649a44cee25e26da13491cb4398024171c1..79f961ee4bf85b488aaa1c3f3fb9b8b28b414872
+++ b/Makefile
@@@ -69,9 -69,6 +69,9 @@@ all:
  # Define NO_MSGFMT_EXTENDED_OPTIONS if your implementation of msgfmt
  # doesn't support GNU extensions like --check and --statistics
  #
 +# Define NEEDS_CLIPPED_WRITE if your write(2) cannot write more than
 +# INT_MAX bytes at once (e.g. MacOS X).
 +#
  # Define HAVE_PATHS_H if you have paths.h and want to use the default PATH
  # it specifies.
  #
  # Define NO_FNMATCH_CASEFOLD if your fnmatch function doesn't have the
  # FNM_CASEFOLD GNU extension.
  #
 -# Define USE_WILDMATCH if you want to use Git's wildmatch
 +# Define NO_WILDMATCH if you do not want to use Git's wildmatch
  # implementation as fnmatch
  #
  # Define NO_GECOS_IN_PWENT if you don't have pw_gecos in struct passwd
  # specify your own (or DarwinPort's) include directories and
  # library directories by defining CFLAGS and LDFLAGS appropriately.
  #
 +# Define NO_APPLE_COMMON_CRYPTO if you are building on Darwin/Mac OS X
 +# and do not want to use Apple's CommonCrypto library.  This allows you
 +# to provide your own OpenSSL library, for example from MacPorts.
 +#
  # Define BLK_SHA1 environment variable to make use of the bundled
  # optimized C SHA1 routine.
  #
  #
  # Define NO_REGEX if you have no or inferior regex support in your C library.
  #
 -# Define CYGWIN_V15_WIN32API if you are using Cygwin v1.7.x but are not
 -# using the current w32api packages. The recommended approach, however,
 -# is to update your installation if compilation errors occur.
 -#
  # Define HAVE_DEV_TTY if your system can open /dev/tty to interact with the
  # user.
  #
@@@ -463,7 -460,6 +463,7 @@@ SCRIPT_SH += git-mergetool.s
  SCRIPT_SH += git-pull.sh
  SCRIPT_SH += git-quiltimport.sh
  SCRIPT_SH += git-rebase.sh
 +SCRIPT_SH += git-remote-testgit.sh
  SCRIPT_SH += git-repack.sh
  SCRIPT_SH += git-request-pull.sh
  SCRIPT_SH += git-stash.sh
@@@ -491,18 -487,11 +491,18 @@@ SCRIPT_PERL += git-svn.per
  SCRIPT_PYTHON += git-remote-testpy.py
  SCRIPT_PYTHON += git-p4.py
  
 +NO_INSTALL += git-remote-testgit
 +NO_INSTALL += git-remote-testpy
 +
  # Generated files for scripts
  SCRIPT_SH_GEN = $(patsubst %.sh,%,$(SCRIPT_SH))
  SCRIPT_PERL_GEN = $(patsubst %.perl,%,$(SCRIPT_PERL))
  SCRIPT_PYTHON_GEN = $(patsubst %.py,%,$(SCRIPT_PYTHON))
  
 +SCRIPT_SH_INS = $(filter-out $(NO_INSTALL),$(SCRIPT_SH_GEN))
 +SCRIPT_PERL_INS = $(filter-out $(NO_INSTALL),$(SCRIPT_PERL_GEN))
 +SCRIPT_PYTHON_INS = $(filter-out $(NO_INSTALL),$(SCRIPT_PYTHON_GEN))
 +
  # Individual rules to allow e.g.
  # "make -C ../.. SCRIPT_PERL=contrib/foo/bar.perl build-perl-script"
  # from subdirectories like contrib/*/
@@@ -512,12 -501,12 +512,12 @@@ build-sh-script: $(SCRIPT_SH_GEN
  build-python-script: $(SCRIPT_PYTHON_GEN)
  
  .PHONY: install-perl-script install-sh-script install-python-script
 -install-sh-script: $(SCRIPT_SH_GEN)
 -      $(INSTALL) $(SCRIPT_SH_GEN) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 -install-perl-script: $(SCRIPT_PERL_GEN)
 -      $(INSTALL) $(SCRIPT_PERL_GEN) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 -install-python-script: $(SCRIPT_PYTHON_GEN)
 -      $(INSTALL) $(SCRIPT_PYTHON_GEN) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 +install-sh-script: $(SCRIPT_SH_INS)
 +      $(INSTALL) $^ '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 +install-perl-script: $(SCRIPT_PERL_INS)
 +      $(INSTALL) $^ '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 +install-python-script: $(SCRIPT_PYTHON_INS)
 +      $(INSTALL) $^ '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
  
  .PHONY: clean-perl-script clean-sh-script clean-python-script
  clean-sh-script:
@@@ -527,9 -516,9 +527,9 @@@ clean-perl-script
  clean-python-script:
        $(RM) $(SCRIPT_PYTHON_GEN)
  
 -SCRIPTS = $(SCRIPT_SH_GEN) \
 -        $(SCRIPT_PERL_GEN) \
 -        $(SCRIPT_PYTHON_GEN) \
 +SCRIPTS = $(SCRIPT_SH_INS) \
 +        $(SCRIPT_PERL_INS) \
 +        $(SCRIPT_PYTHON_INS) \
          git-instaweb
  
  ETAGS_TARGET = TAGS
@@@ -569,6 -558,7 +569,7 @@@ TEST_PROGRAMS_NEED_X += test-mergesor
  TEST_PROGRAMS_NEED_X += test-mktemp
  TEST_PROGRAMS_NEED_X += test-parse-options
  TEST_PROGRAMS_NEED_X += test-path-utils
+ TEST_PROGRAMS_NEED_X += test-read-cache
  TEST_PROGRAMS_NEED_X += test-regex
  TEST_PROGRAMS_NEED_X += test-revision-walking
  TEST_PROGRAMS_NEED_X += test-run-command
@@@ -684,8 -674,6 +685,8 @@@ LIB_H += help.
  LIB_H += http.h
  LIB_H += kwset.h
  LIB_H += levenshtein.h
 +LIB_H += line-log.h
 +LIB_H += line-range.h
  LIB_H += list-objects.h
  LIB_H += ll-merge.h
  LIB_H += log-tree.h
@@@ -697,6 -685,7 +698,6 @@@ LIB_H += notes-cache.
  LIB_H += notes-merge.h
  LIB_H += notes.h
  LIB_H += object.h
 -LIB_H += pack-refs.h
  LIB_H += pack-revindex.h
  LIB_H += pack.h
  LIB_H += parse-options.h
@@@ -813,8 -802,6 +814,8 @@@ LIB_OBJS += hex.
  LIB_OBJS += ident.o
  LIB_OBJS += kwset.o
  LIB_OBJS += levenshtein.o
 +LIB_OBJS += line-log.o
 +LIB_OBJS += line-range.o
  LIB_OBJS += list-objects.o
  LIB_OBJS += ll-merge.o
  LIB_OBJS += lockfile.o
@@@ -831,6 -818,7 +832,6 @@@ LIB_OBJS += notes-cache.
  LIB_OBJS += notes-merge.o
  LIB_OBJS += object.o
  LIB_OBJS += pack-check.o
 -LIB_OBJS += pack-refs.o
  LIB_OBJS += pack-revindex.o
  LIB_OBJS += pack-write.o
  LIB_OBJS += pager.o
@@@ -1067,11 -1055,6 +1068,11 @@@ ifeq ($(uname_S),Darwin
                        BASIC_LDFLAGS += -L/opt/local/lib
                endif
        endif
 +      ifndef NO_APPLE_COMMON_CRYPTO
 +              APPLE_COMMON_CRYPTO = YesPlease
 +              COMPAT_CFLAGS += -DAPPLE_COMMON_CRYPTO
 +      endif
 +      NO_REGEX = YesPlease
        PTHREAD_LIBS =
  endif
  
@@@ -1279,7 -1262,7 +1280,7 @@@ ifdef NO_FNMATCH_CASEFOL
        COMPAT_OBJS += compat/fnmatch/fnmatch.o
  endif
  endif
 -ifdef USE_WILDMATCH
 +ifndef NO_WILDMATCH
        COMPAT_CFLAGS += -DUSE_WILDMATCH
  endif
  ifdef NO_SETENV
@@@ -1405,17 -1388,11 +1406,17 @@@ ifdef PPC_SHA
        SHA1_HEADER = "ppc/sha1.h"
        LIB_OBJS += ppc/sha1.o ppc/sha1ppc.o
        LIB_H += ppc/sha1.h
 +else
 +ifdef APPLE_COMMON_CRYPTO
 +      COMPAT_CFLAGS += -DCOMMON_DIGEST_FOR_OPENSSL
 +      SHA1_HEADER = <CommonCrypto/CommonDigest.h>
  else
        SHA1_HEADER = <openssl/sha.h>
        EXTLIBS += $(LIB_4_CRYPTO)
  endif
  endif
 +endif
 +
  ifdef NO_PERL_MAKEMAKER
        export NO_PERL_MAKEMAKER
  endif
@@@ -1473,6 -1450,9 +1474,6 @@@ ifdef NO_REGE
        COMPAT_CFLAGS += -Icompat/regex
        COMPAT_OBJS += compat/regex/regex.o
  endif
 -ifdef CYGWIN_V15_WIN32API
 -      COMPAT_CFLAGS += -DCYGWIN_V15_WIN32API
 -endif
  
  ifdef USE_NED_ALLOCATOR
         COMPAT_CFLAGS += -Icompat/nedmalloc
@@@ -1487,11 -1467,6 +1488,11 @@@ ifndef NO_MSGFMT_EXTENDED_OPTION
        MSGFMT += --check --statistics
  endif
  
 +ifdef NEEDS_CLIPPED_WRITE
 +      BASIC_CFLAGS += -DNEEDS_CLIPPED_WRITE
 +      COMPAT_OBJS += compat/clipped-write.o
 +endif
 +
  ifneq (,$(XDL_FAST_HASH))
        BASIC_CFLAGS += -DXDL_FAST_HASH
  endif
@@@ -1529,7 -1504,6 +1530,7 @@@ ifndef 
        QUIET_MSGFMT   = @echo '   ' MSGFMT $@;
        QUIET_GCOV     = @echo '   ' GCOV $@;
        QUIET_SP       = @echo '   ' SP $<;
 +      QUIET_RC       = @echo '   ' RC $@;
        QUIET_SUBDIR0  = +@subdir=
        QUIET_SUBDIR1  = ;$(NO_SUBDIR) echo '   ' SUBDIR $$subdir; \
                         $(MAKE) $(PRINT_DIR) -C $$subdir
@@@ -1672,7 -1646,7 +1673,7 @@@ please_set_SHELL_PATH_to_a_more_modern_
  shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
  
  strip: $(PROGRAMS) git$X
 -      $(STRIP) $(STRIP_OPTS) $(PROGRAMS) git$X
 +      $(STRIP) $(STRIP_OPTS) $^
  
  ### Target-specific flags and dependencies
  
@@@ -1732,9 -1706,9 +1733,9 @@@ version.sp version.s version.o: EXTRA_C
  
  $(BUILT_INS): git$X
        $(QUIET_BUILT_IN)$(RM) $@ && \
 -      ln git$X $@ 2>/dev/null || \
 -      ln -s git$X $@ 2>/dev/null || \
 -      cp git$X $@
 +      ln $< $@ 2>/dev/null || \
 +      ln -s $< $@ 2>/dev/null || \
 +      cp $< $@
  
  common-cmds.h: ./generate-cmdlist.sh command-list.txt
  
@@@ -1775,11 -1749,6 +1776,11 @@@ $(SCRIPT_LIB) : % : %.sh GIT-SCRIPT-DEF
        $(QUIET_GEN)$(cmd_munge_script) && \
        mv $@+ $@
  
 +git.res: git.rc GIT-VERSION-FILE
 +      $(QUIET_RC)$(RC) \
 +        $(join -DMAJOR= -DMINOR= -DPATCH=, $(wordlist 1,3,$(subst -, ,$(subst ., ,$(GIT_VERSION))))) \
 +        -DGIT_VERSION="\\\"$(GIT_VERSION)\\\"" $< -o $@
 +
  ifndef NO_PERL
  $(patsubst %.perl,%,$(SCRIPT_PERL)): perl/perl.mak
  
@@@ -1804,7 -1773,7 +1805,7 @@@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % 
            -e '        x' \
            -e '}' \
            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
 -          $@.perl >$@+ && \
 +          $< >$@+ && \
        chmod +x $@+ && \
        mv $@+ $@
  
@@@ -1828,8 -1797,8 +1829,8 @@@ $(patsubst %.perl,%,$(SCRIPT_PERL)) git
  endif # NO_PERL
  
  ifndef NO_PYTHON
 -$(patsubst %.py,%,$(SCRIPT_PYTHON)): GIT-CFLAGS GIT-PREFIX GIT-PYTHON-VARS
 -$(patsubst %.py,%,$(SCRIPT_PYTHON)): % : %.py
 +$(SCRIPT_PYTHON_GEN): GIT-CFLAGS GIT-PREFIX GIT-PYTHON-VARS
 +$(SCRIPT_PYTHON_GEN): % : %.py
        $(QUIET_GEN)$(RM) $@ $@+ && \
        INSTLIBDIR=`MAKEFLAGS= $(MAKE) -C git_remote_helpers -s \
                --no-print-directory prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' \
        sed -e '1s|#!.*python|#!$(PYTHON_PATH_SQ)|' \
            -e 's|\(os\.getenv("GITPYTHONLIB"\)[^)]*)|\1,"@@INSTLIBDIR@@")|' \
            -e 's|@@INSTLIBDIR@@|'"$$INSTLIBDIR"'|g' \
 -          $@.py >$@+ && \
 +          $< >$@+ && \
        chmod +x $@+ && \
        mv $@+ $@
  else # NO_PYTHON
 -$(patsubst %.py,%,$(SCRIPT_PYTHON)): % : unimplemented.sh
 +$(SCRIPT_PYTHON_GEN): % : unimplemented.sh
        $(QUIET_GEN)$(RM) $@ $@+ && \
        sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
            -e 's|@@REASON@@|NO_PYTHON=$(NO_PYTHON)|g' \
@@@ -2036,7 -2005,6 +2037,7 @@@ endi
  ifdef USE_NED_ALLOCATOR
  compat/nedmalloc/nedmalloc.sp compat/nedmalloc/nedmalloc.o: EXTRA_CPPFLAGS = \
        -DNDEBUG -DOVERRIDE_STRDUP -DREPLACE_SYSTEM_ALLOCATOR
 +compat/nedmalloc/nedmalloc.sp: SPARSE_FLAGS += -Wno-non-pointer-null
  endif
  
  git-%$X: %.o GIT-LDFLAGS $(GITLIBS)
@@@ -2068,13 -2036,13 +2069,13 @@@ $(REMOTE_CURL_PRIMARY): remote-curl.o h
                $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
  
  $(LIB_FILE): $(LIB_OBJS)
 -      $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS)
 +      $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $^
  
  $(XDIFF_LIB): $(XDIFF_OBJS)
 -      $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(XDIFF_OBJS)
 +      $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $^
  
  $(VCSSVN_LIB): $(VCSSVN_OBJS)
 -      $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(VCSSVN_OBJS)
 +      $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $^
  
  export DEFAULT_EDITOR DEFAULT_PAGER
  
@@@ -2192,9 -2160,6 +2193,9 @@@ GIT-BUILD-OPTIONS: FORC
        @echo NO_PERL=\''$(subst ','\'',$(subst ','\'',$(NO_PERL)))'\' >>$@
        @echo NO_PYTHON=\''$(subst ','\'',$(subst ','\'',$(NO_PYTHON)))'\' >>$@
        @echo NO_UNIX_SOCKETS=\''$(subst ','\'',$(subst ','\'',$(NO_UNIX_SOCKETS)))'\' >>$@
 +ifdef TEST_OUTPUT_DIRECTORY
 +      @echo TEST_OUTPUT_DIRECTORY=\''$(subst ','\'',$(subst ','\'',$(TEST_OUTPUT_DIRECTORY)))'\' >>$@
 +endif
  ifdef GIT_TEST_OPTS
        @echo GIT_TEST_OPTS=\''$(subst ','\'',$(subst ','\'',$(GIT_TEST_OPTS)))'\' >>$@
  endif
@@@ -2234,7 -2199,6 +2235,7 @@@ endi
  test_bindir_programs := $(patsubst %,bin-wrappers/%,$(BINDIR_PROGRAMS_NEED_X) $(BINDIR_PROGRAMS_NO_X) $(TEST_PROGRAMS_NEED_X))
  
  all:: $(TEST_PROGRAMS) $(test_bindir_programs)
 +all:: $(NO_INSTALL)
  
  bin-wrappers/%: wrap-for-bin.sh
        @mkdir -p bin-wrappers
@@@ -2480,11 -2444,11 +2481,11 @@@ profile-clean
        $(RM) $(addsuffix *.gcda,$(addprefix $(PROFILE_DIR)/, $(object_dirs)))
        $(RM) $(addsuffix *.gcno,$(addprefix $(PROFILE_DIR)/, $(object_dirs)))
  
 -clean: profile-clean
 -      $(RM) *.o block-sha1/*.o ppc/*.o compat/*.o compat/*/*.o xdiff/*.o vcs-svn/*.o \
 +clean: profile-clean coverage-clean
 +      $(RM) *.o *.res block-sha1/*.o ppc/*.o compat/*.o compat/*/*.o xdiff/*.o vcs-svn/*.o \
                builtin/*.o $(LIB_FILE) $(XDIFF_LIB) $(VCSSVN_LIB)
        $(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git$X
 -      $(RM) $(TEST_PROGRAMS)
 +      $(RM) $(TEST_PROGRAMS) $(NO_INSTALL)
        $(RM) -r bin-wrappers $(dep_dirs)
        $(RM) -r po/build/
        $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h $(ETAGS_TARGET) tags cscope*
@@@ -2561,34 -2525,29 +2562,34 @@@ check-builtins:
  
  ### Test suite coverage testing
  #
 -.PHONY: coverage coverage-clean coverage-build coverage-report
 +.PHONY: coverage coverage-clean coverage-compile coverage-test coverage-report
 +.PHONY: coverage-clean-results
  
  coverage:
 -      $(MAKE) coverage-build
 -      $(MAKE) coverage-report
 +      $(MAKE) coverage-test
 +      $(MAKE) coverage-untested-functions
  
  object_dirs := $(sort $(dir $(OBJECTS)))
 -coverage-clean:
 +coverage-clean-results:
        $(RM) $(addsuffix *.gcov,$(object_dirs))
        $(RM) $(addsuffix *.gcda,$(object_dirs))
 -      $(RM) $(addsuffix *.gcno,$(object_dirs))
        $(RM) coverage-untested-functions
        $(RM) -r cover_db/
        $(RM) -r cover_db_html/
  
 +coverage-clean: coverage-clean-results
 +      $(RM) $(addsuffix *.gcno,$(object_dirs))
 +
  COVERAGE_CFLAGS = $(CFLAGS) -O0 -ftest-coverage -fprofile-arcs
  COVERAGE_LDFLAGS = $(CFLAGS)  -O0 -lgcov
  GCOVFLAGS = --preserve-paths --branch-probabilities --all-blocks
  
 -coverage-build: coverage-clean
 +coverage-compile:
        $(MAKE) CFLAGS="$(COVERAGE_CFLAGS)" LDFLAGS="$(COVERAGE_LDFLAGS)" all
 +
 +coverage-test: coverage-clean-results coverage-compile
        $(MAKE) CFLAGS="$(COVERAGE_CFLAGS)" LDFLAGS="$(COVERAGE_LDFLAGS)" \
 -              -j1 test
 +              DEFAULT_TEST_TARGET=test -j1 test
  
  coverage-report:
        $(QUIET_GCOV)for dir in $(object_dirs); do \
diff --combined read-cache.c
index 5e30746886d477a0dc69853efd42283f2ac8c712,4245f8ef30bc740f97c278abdb9cc15e7017aa47..b297addb576dec45fa9b82ef4a0ffb350f9cfc6c
@@@ -91,7 -91,7 +91,7 @@@ void fill_stat_cache_info(struct cache_
                ce_mark_uptodate(ce);
  }
  
 -static int ce_compare_data(struct cache_entry *ce, struct stat *st)
 +static int ce_compare_data(const struct cache_entry *ce, struct stat *st)
  {
        int match = -1;
        int fd = open(ce->name, O_RDONLY);
        return match;
  }
  
 -static int ce_compare_link(struct cache_entry *ce, size_t expected_size)
 +static int ce_compare_link(const struct cache_entry *ce, size_t expected_size)
  {
        int match = -1;
        void *buffer;
        return match;
  }
  
 -static int ce_compare_gitlink(struct cache_entry *ce)
 +static int ce_compare_gitlink(const struct cache_entry *ce)
  {
        unsigned char sha1[20];
  
        return hashcmp(sha1, ce->sha1);
  }
  
 -static int ce_modified_check_fs(struct cache_entry *ce, struct stat *st)
 +static int ce_modified_check_fs(const struct cache_entry *ce, struct stat *st)
  {
        switch (st->st_mode & S_IFMT) {
        case S_IFREG:
        return 0;
  }
  
 -static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
 +static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)
  {
        unsigned int changed = 0;
  
        return changed;
  }
  
 -static int is_racy_timestamp(const struct index_state *istate, struct cache_entry *ce)
 +static int is_racy_timestamp(const struct index_state *istate,
 +                           const struct cache_entry *ce)
  {
        return (!S_ISGITLINK(ce->ce_mode) &&
                istate->timestamp.sec &&
  }
  
  int ie_match_stat(const struct index_state *istate,
 -                struct cache_entry *ce, struct stat *st,
 +                const struct cache_entry *ce, struct stat *st,
                  unsigned int options)
  {
        unsigned int changed;
  }
  
  int ie_modified(const struct index_state *istate,
 -              struct cache_entry *ce, struct stat *st, unsigned int options)
 +              const struct cache_entry *ce,
 +              struct stat *st, unsigned int options)
  {
        int changed, changed_fs;
  
@@@ -628,7 -626,7 +628,7 @@@ int add_to_index(struct index_state *is
                        if (*ptr == '/') {
                                struct cache_entry *foundce;
                                ++ptr;
 -                              foundce = index_name_exists(&the_index, ce->name, ptr - ce->name, ignore_case);
 +                              foundce = index_name_exists(istate, ce->name, ptr - ce->name, ignore_case);
                                if (foundce) {
                                        memcpy((void *)startPtr, foundce->name + (startPtr - ce->name), ptr - startPtr);
                                        startPtr = ptr;
@@@ -981,7 -979,7 +981,7 @@@ int add_index_entry(struct index_state 
        if (istate->cache_nr == istate->cache_alloc) {
                istate->cache_alloc = alloc_nr(istate->cache_alloc);
                istate->cache = xrealloc(istate->cache,
 -                                      istate->cache_alloc * sizeof(struct cache_entry *));
 +                                      istate->cache_alloc * sizeof(*istate->cache));
        }
  
        /* Add it in.. */
@@@ -1451,7 -1449,7 +1451,7 @@@ int read_index_from(struct index_state 
        istate->version = ntohl(hdr->hdr_version);
        istate->cache_nr = ntohl(hdr->hdr_entries);
        istate->cache_alloc = alloc_nr(istate->cache_nr);
 -      istate->cache = xcalloc(istate->cache_alloc, sizeof(struct cache_entry *));
 +      istate->cache = xcalloc(istate->cache_alloc, sizeof(*istate->cache));
        istate->initialized = 1;
  
        if (istate->version == 4)
@@@ -1520,8 -1518,9 +1520,9 @@@ int discard_index(struct index_state *i
        free_name_hash(istate);
        cache_tree_free(&(istate->cache_tree));
        istate->initialized = 0;
-       /* no need to throw away allocated active_cache */
+       free(istate->cache);
+       istate->cache = NULL;
+       istate->cache_alloc = 0;
        return 0;
  }