Git fork

hash.h: move SHA-1 implementation selection into a header file

Many developers use functionality in their editors that allows for quick
syntax checks, including warning about questionable constructs. This
functionality allows rapid development with fewer errors. However, such
functionality generally does not allow the specification of
project-specific defines or command-line options.

Since the SHA1_HEADER include is not defined in such a case,
developers see spurious errors when using these tools. Furthermore,
there are known implementations of "cc" whose '#include' is unhappy
with this construct.

Instead of using SHA1_HEADER, create a hash.h header and use #if
and #elif to select the desired header. Have the Makefile pass an
appropriate option to help the header select the right implementation to
use.

[jc: make BLK_SHA1 the fallback default as discussed on list,
e.g. <20170314201424.vccij5z2ortq4a4o@sigill.intra.peff.net>; also
remove SHA1_HEADER and SHA1_HEADER_SQ that are no longer used].

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

brian m. carlson and committed by
Junio C Hamano
f18f816c e7e07d5a

+20 -8
+5 -7
Makefile
··· 1387 1387 endif 1388 1388 1389 1389 ifdef BLK_SHA1 1390 - SHA1_HEADER = "block-sha1/sha1.h" 1391 1390 LIB_OBJS += block-sha1/sha1.o 1391 + BASIC_CFLAGS += -DSHA1_BLK 1392 1392 else 1393 1393 ifdef PPC_SHA1 1394 - SHA1_HEADER = "ppc/sha1.h" 1395 1394 LIB_OBJS += ppc/sha1.o ppc/sha1ppc.o 1395 + BASIC_CFLAGS += -DSHA1_PPC 1396 1396 else 1397 1397 ifdef APPLE_COMMON_CRYPTO 1398 1398 COMPAT_CFLAGS += -DCOMMON_DIGEST_FOR_OPENSSL 1399 - SHA1_HEADER = <CommonCrypto/CommonDigest.h> 1399 + BASIC_CFLAGS += -DSHA1_APPLE 1400 1400 else 1401 - SHA1_HEADER = <openssl/sha.h> 1402 1401 EXTLIBS += $(LIB_4_CRYPTO) 1402 + BASIC_CFLAGS += -DSHA1_OPENSSL 1403 1403 endif 1404 1404 endif 1405 1405 endif ··· 1591 1591 1592 1592 # Shell quote (do not use $(call) to accommodate ancient setups); 1593 1593 1594 - SHA1_HEADER_SQ = $(subst ','\'',$(SHA1_HEADER)) 1595 1594 ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG)) 1596 1595 ETC_GITATTRIBUTES_SQ = $(subst ','\'',$(ETC_GITATTRIBUTES)) 1597 1596 ··· 1624 1623 # from the dependency list, that would make each entry appear twice. 1625 1624 LIBS = $(filter-out %.o, $(GITLIBS)) $(EXTLIBS) 1626 1625 1627 - BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \ 1628 - $(COMPAT_CFLAGS) 1626 + BASIC_CFLAGS += $(COMPAT_CFLAGS) 1629 1627 LIB_OBJS += $(COMPAT_OBJS) 1630 1628 1631 1629 # Quote for C
+1 -1
cache.h
··· 10 10 #include "trace.h" 11 11 #include "string-list.h" 12 12 #include "pack-revindex.h" 13 + #include "hash.h" 13 14 14 - #include SHA1_HEADER 15 15 #ifndef platform_SHA_CTX 16 16 /* 17 17 * platform's underlying implementation of SHA-1; could be OpenSSL,
+14
hash.h
··· 1 + #ifndef HASH_H 2 + #define HASH_H 3 + 4 + #if defined(SHA1_PPC) 5 + #include "ppc/sha1.h" 6 + #elif defined(SHA1_APPLE) 7 + #include <CommonCrypto/CommonDigest.h> 8 + #elif defined(SHA1_OPENSSL) 9 + #include <openssl/sha.h> 10 + #else /* SHA1_BLK */ 11 + #include "block-sha1/sha1.h" 12 + #endif 13 + 14 + #endif