Merge branch 'cc/test-oidmap'
authorJunio C Hamano <gitster@pobox.com>
Fri, 19 Jul 2019 18:30:19 +0000 (11:30 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 19 Jul 2019 18:30:19 +0000 (11:30 -0700)
Extend the test coverage a bit.

* cc/test-oidmap:
t0016: add 'remove' subcommand test
test-oidmap: remove 'add' subcommand
test-hashmap: remove 'hash' command
oidmap: use sha1hash() instead of static hash() function
t: add t0016-oidmap.sh
t/helper: add test-oidmap.c

1  2 
Makefile
oidmap.c
diff --combined Makefile
index 98a0588416c4f3f7a5b48ad72a6c2fd54ff94120,5efc7700edbb696a43861b85c29d552c71f628fb..11ccea40716d9bbcef731f093e530a9b1aee0013
+++ b/Makefile
@@@ -265,6 -265,10 +265,6 @@@ all:
  #
  # Define NO_DEFLATE_BOUND if your zlib does not have deflateBound.
  #
 -# Define NO_R_TO_GCC_LINKER if your gcc does not like "-R/path/lib"
 -# that tells runtime paths to dynamic libraries;
 -# "-Wl,-rpath=/path/lib" is used instead.
 -#
  # Define NO_NORETURN if using buggy versions of gcc 4.6+ and profile feedback,
  # as the compiler can crash (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49299)
  #
@@@ -620,6 -624,8 +620,6 @@@ SCRIPT_SH += git-web--browse.s
  
  SCRIPT_LIB += git-mergetool--lib
  SCRIPT_LIB += git-parse-remote
 -SCRIPT_LIB += git-rebase--am
 -SCRIPT_LIB += git-rebase--common
  SCRIPT_LIB += git-rebase--preserve-merges
  SCRIPT_LIB += git-sh-setup
  SCRIPT_LIB += git-sh-i18n
@@@ -721,6 -727,7 +721,7 @@@ TEST_BUILTINS_OBJS += test-lazy-init-na
  TEST_BUILTINS_OBJS += test-match-trees.o
  TEST_BUILTINS_OBJS += test-mergesort.o
  TEST_BUILTINS_OBJS += test-mktemp.o
+ TEST_BUILTINS_OBJS += test-oidmap.o
  TEST_BUILTINS_OBJS += test-online-cpus.o
  TEST_BUILTINS_OBJS += test-parse-options.o
  TEST_BUILTINS_OBJS += test-path-utils.o
@@@ -771,11 -778,9 +772,11 @@@ BUILT_INS += git-format-patch$
  BUILT_INS += git-fsck-objects$X
  BUILT_INS += git-init$X
  BUILT_INS += git-merge-subtree$X
 +BUILT_INS += git-restore$X
  BUILT_INS += git-show$X
  BUILT_INS += git-stage$X
  BUILT_INS += git-status$X
 +BUILT_INS += git-switch$X
  BUILT_INS += git-whatchanged$X
  
  # what 'all' will build and 'install' will install in gitexecdir,
@@@ -1156,7 -1161,6 +1157,7 @@@ endi
  # which'll override these defaults.
  CFLAGS = -g -O2 -Wall
  LDFLAGS =
 +CC_LD_DYNPATH = -Wl,-rpath,
  BASIC_CFLAGS = -I.
  BASIC_LDFLAGS =
  
@@@ -1237,7 -1241,7 +1238,7 @@@ endi
  
  ifdef SANE_TOOL_PATH
  SANE_TOOL_PATH_SQ = $(subst ','\'',$(SANE_TOOL_PATH))
 -BROKEN_PATH_FIX = 's|^\# @@BROKEN_PATH_FIX@@$$|git_broken_path_fix $(SANE_TOOL_PATH_SQ)|'
 +BROKEN_PATH_FIX = 's|^\# @@BROKEN_PATH_FIX@@$$|git_broken_path_fix "$(SANE_TOOL_PATH_SQ)"|'
  PATH := $(SANE_TOOL_PATH):${PATH}
  else
  BROKEN_PATH_FIX = '/^\# @@BROKEN_PATH_FIX@@$$/d'
@@@ -1287,6 -1291,16 +1288,6 @@@ ifeq ($(uname_S),Darwin
        PTHREAD_LIBS =
  endif
  
 -ifndef CC_LD_DYNPATH
 -      ifdef NO_R_TO_GCC_LINKER
 -              # Some gcc does not accept and pass -R to the linker to specify
 -              # the runtime dynamic library path.
 -              CC_LD_DYNPATH = -Wl,-rpath,
 -      else
 -              CC_LD_DYNPATH = -R
 -      endif
 -endif
 -
  ifdef NO_LIBGEN_H
        COMPAT_CFLAGS += -DNO_LIBGEN_H
        COMPAT_OBJS += compat/basename.o
@@@ -2860,33 -2874,6 +2861,33 @@@ install: al
        $(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
        $(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
        $(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'
 +ifdef MSVC
 +      # We DO NOT install the individual foo.o.pdb files because they
 +      # have already been rolled up into the exe's pdb file.
 +      # We DO NOT have pdb files for the builtin commands (like git-status.exe)
 +      # because it is just a copy/hardlink of git.exe, rather than a unique binary.
 +      $(INSTALL) git.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
 +      $(INSTALL) git-shell.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
 +      $(INSTALL) git-upload-pack.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
 +      $(INSTALL) git-credential-store.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 +      $(INSTALL) git-daemon.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 +      $(INSTALL) git-fast-import.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 +      $(INSTALL) git-http-backend.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 +      $(INSTALL) git-http-fetch.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 +      $(INSTALL) git-http-push.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 +      $(INSTALL) git-imap-send.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 +      $(INSTALL) git-remote-http.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 +      $(INSTALL) git-remote-testsvn.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 +      $(INSTALL) git-sh-i18n--envsubst.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 +      $(INSTALL) git-show-index.pdb '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 +ifndef DEBUG
 +      $(INSTALL) $(vcpkg_rel_bin)/*.dll '$(DESTDIR_SQ)$(bindir_SQ)'
 +      $(INSTALL) $(vcpkg_rel_bin)/*.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
 +else
 +      $(INSTALL) $(vcpkg_dbg_bin)/*.dll '$(DESTDIR_SQ)$(bindir_SQ)'
 +      $(INSTALL) $(vcpkg_dbg_bin)/*.pdb '$(DESTDIR_SQ)$(bindir_SQ)'
 +endif
 +endif
        $(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
        $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
        $(INSTALL) -m 644 mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
@@@ -3099,19 -3086,6 +3100,19 @@@ endi
        $(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-BUILD-OPTIONS
        $(RM) GIT-USER-AGENT GIT-PREFIX
        $(RM) GIT-SCRIPT-DEFINES GIT-PERL-DEFINES GIT-PERL-HEADER GIT-PYTHON-VARS
 +ifdef MSVC
 +      $(RM) $(patsubst %.o,%.o.pdb,$(OBJECTS))
 +      $(RM) $(patsubst %.exe,%.pdb,$(OTHER_PROGRAMS))
 +      $(RM) $(patsubst %.exe,%.iobj,$(OTHER_PROGRAMS))
 +      $(RM) $(patsubst %.exe,%.ipdb,$(OTHER_PROGRAMS))
 +      $(RM) $(patsubst %.exe,%.pdb,$(PROGRAMS))
 +      $(RM) $(patsubst %.exe,%.iobj,$(PROGRAMS))
 +      $(RM) $(patsubst %.exe,%.ipdb,$(PROGRAMS))
 +      $(RM) $(patsubst %.exe,%.pdb,$(TEST_PROGRAMS))
 +      $(RM) $(patsubst %.exe,%.iobj,$(TEST_PROGRAMS))
 +      $(RM) $(patsubst %.exe,%.ipdb,$(TEST_PROGRAMS))
 +      $(RM) compat/vcbuild/MSVC-DEFS-GEN
 +endif
  
  .PHONY: all install profile-clean cocciclean clean strip
  .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
diff --combined oidmap.c
index b0841a0f5870bafdcaf3482ed725e43ddaf5d461,01c206aaefe1daf29d3c8a3ac2862a93a95490af..6d6e840d037657721a5aa975e2567c8415547d93
+++ b/oidmap.c
@@@ -12,13 -12,6 +12,6 @@@ static int oidmap_neq(const void *hashm
                      &((const struct oidmap_entry *) entry_or_key)->oid);
  }
  
- static int hash(const struct object_id *oid)
- {
-       int hash;
-       memcpy(&hash, oid->hash, sizeof(hash));
-       return hash;
- }
  void oidmap_init(struct oidmap *map, size_t initial_size)
  {
        hashmap_init(&map->map, oidmap_neq, NULL, initial_size);
@@@ -36,7 -29,7 +29,7 @@@ void *oidmap_get(const struct oidmap *m
        if (!map->map.cmpfn)
                return NULL;
  
-       return hashmap_get_from_hash(&map->map, hash(key), key);
 -      return hashmap_get_from_hash(&map->map, sha1hash(key->hash), key);
++      return hashmap_get_from_hash(&map->map, oidhash(key), key);
  }
  
  void *oidmap_remove(struct oidmap *map, const struct object_id *key)
@@@ -46,7 -39,7 +39,7 @@@
        if (!map->map.cmpfn)
                oidmap_init(map, 0);
  
-       hashmap_entry_init(&entry, hash(key));
 -      hashmap_entry_init(&entry, sha1hash(key->hash));
++      hashmap_entry_init(&entry, oidhash(key));
        return hashmap_remove(&map->map, &entry, key);
  }
  
@@@ -57,6 -50,6 +50,6 @@@ void *oidmap_put(struct oidmap *map, vo
        if (!map->map.cmpfn)
                oidmap_init(map, 0);
  
-       hashmap_entry_init(&to_put->internal_entry, hash(&to_put->oid));
 -      hashmap_entry_init(&to_put->internal_entry, sha1hash(to_put->oid.hash));
++      hashmap_entry_init(&to_put->internal_entry, oidhash(&to_put->oid));
        return hashmap_put(&map->map, to_put);
  }