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>

brian m. carlson committed Mar 11, 2017 at 22:28 UTC f18f816cb1586e9aab3e30a7144768e0d282d305
3 files changed +20 -8
Makefile
+5 -7
@@ -1387,19 +1387,19 @@ ifdef APPLE_COMMON_CRYPTO
1387 endif
1388
1389 ifdef BLK_SHA1
1390 - SHA1_HEADER = "block-sha1/sha1.h"
1390 LIB_OBJS += block-sha1/sha1.o
1391 + BASIC_CFLAGS += -DSHA1_BLK
1392 else
1393 ifdef PPC_SHA1
1394 - SHA1_HEADER = "ppc/sha1.h"
1394 LIB_OBJS += ppc/sha1.o ppc/sha1ppc.o
1395 + BASIC_CFLAGS += -DSHA1_PPC
1396 else
1397 ifdef APPLE_COMMON_CRYPTO
1398 COMPAT_CFLAGS += -DCOMMON_DIGEST_FOR_OPENSSL
1399 - SHA1_HEADER = <CommonCrypto/CommonDigest.h>
1399 + BASIC_CFLAGS += -DSHA1_APPLE
1400 else
1401 - SHA1_HEADER = <openssl/sha.h>
1401 EXTLIBS += $(LIB_4_CRYPTO)
1402 + BASIC_CFLAGS += -DSHA1_OPENSSL
1403 endif
1404 endif
1405 endif
@@ -1591,7 +1591,6 @@ endif
1591
1592 # Shell quote (do not use $(call) to accommodate ancient setups);
1593
1594 -SHA1_HEADER_SQ = $(subst ','\'',$(SHA1_HEADER))
1594 ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG))
1595 ETC_GITATTRIBUTES_SQ = $(subst ','\'',$(ETC_GITATTRIBUTES))
1596
@@ -1624,8 +1623,7 @@ PERLLIB_EXTRA_SQ = $(subst ','\'',$(PERLLIB_EXTRA))
1623 # from the dependency list, that would make each entry appear twice.
1624 LIBS = $(filter-out %.o, $(GITLIBS)) $(EXTLIBS)
1625
1627 -BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \
1628 - $(COMPAT_CFLAGS)
1626 +BASIC_CFLAGS += $(COMPAT_CFLAGS)
1627 LIB_OBJS += $(COMPAT_OBJS)
1628
1629 # Quote for C
cache.h
+1 -1
@@ -10,8 +10,8 @@
10 #include "trace.h"
11 #include "string-list.h"
12 #include "pack-revindex.h"
13 +#include "hash.h"
14
14 -#include SHA1_HEADER
15 #ifndef platform_SHA_CTX
16 /*
17 * platform's underlying implementation of SHA-1; could be OpenSSL,
hash.h new
+14
@@ -0,0 +1,14 @@
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