Skip to content

Commit f18f816

Browse files
bk2204gitster
authored andcommitted
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. <[email protected]>; also remove SHA1_HEADER and SHA1_HEADER_SQ that are no longer used]. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e7e07d5 commit f18f816

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

Makefile

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,19 +1387,19 @@ ifdef APPLE_COMMON_CRYPTO
13871387
endif
13881388

13891389
ifdef BLK_SHA1
1390-
SHA1_HEADER = "block-sha1/sha1.h"
13911390
LIB_OBJS += block-sha1/sha1.o
1391+
BASIC_CFLAGS += -DSHA1_BLK
13921392
else
13931393
ifdef PPC_SHA1
1394-
SHA1_HEADER = "ppc/sha1.h"
13951394
LIB_OBJS += ppc/sha1.o ppc/sha1ppc.o
1395+
BASIC_CFLAGS += -DSHA1_PPC
13961396
else
13971397
ifdef APPLE_COMMON_CRYPTO
13981398
COMPAT_CFLAGS += -DCOMMON_DIGEST_FOR_OPENSSL
1399-
SHA1_HEADER = <CommonCrypto/CommonDigest.h>
1399+
BASIC_CFLAGS += -DSHA1_APPLE
14001400
else
1401-
SHA1_HEADER = <openssl/sha.h>
14021401
EXTLIBS += $(LIB_4_CRYPTO)
1402+
BASIC_CFLAGS += -DSHA1_OPENSSL
14031403
endif
14041404
endif
14051405
endif
@@ -1591,7 +1591,6 @@ endif
15911591

15921592
# Shell quote (do not use $(call) to accommodate ancient setups);
15931593

1594-
SHA1_HEADER_SQ = $(subst ','\'',$(SHA1_HEADER))
15951594
ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG))
15961595
ETC_GITATTRIBUTES_SQ = $(subst ','\'',$(ETC_GITATTRIBUTES))
15971596

@@ -1624,8 +1623,7 @@ PERLLIB_EXTRA_SQ = $(subst ','\'',$(PERLLIB_EXTRA))
16241623
# from the dependency list, that would make each entry appear twice.
16251624
LIBS = $(filter-out %.o, $(GITLIBS)) $(EXTLIBS)
16261625

1627-
BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \
1628-
$(COMPAT_CFLAGS)
1626+
BASIC_CFLAGS += $(COMPAT_CFLAGS)
16291627
LIB_OBJS += $(COMPAT_OBJS)
16301628

16311629
# Quote for C

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include "trace.h"
1111
#include "string-list.h"
1212
#include "pack-revindex.h"
13+
#include "hash.h"
1314

14-
#include SHA1_HEADER
1515
#ifndef platform_SHA_CTX
1616
/*
1717
* platform's underlying implementation of SHA-1; could be OpenSSL,

hash.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)