99
1010#include "common.h"
1111#include "types.h"
12+ #include "experimental.h"
1213
1314/**
1415 * @file git2/oid.h
@@ -21,48 +22,91 @@ GIT_BEGIN_DECL
2122
2223/** The type of object id. */
2324typedef enum {
25+
26+ #ifdef GIT_EXPERIMENTAL_SHA256
2427 GIT_OID_SHA1 = 1 , /**< SHA1 */
2528 GIT_OID_SHA256 = 2 /**< SHA256 */
29+ #else
30+ GIT_OID_SHA1 = 1 /**< SHA1 */
31+ #endif
32+
2633} git_oid_t ;
2734
35+ /*
36+ * SHA1 is currently the only supported object ID type.
37+ */
38+
2839/** SHA1 is currently libgit2's default oid type. */
2940#define GIT_OID_DEFAULT GIT_OID_SHA1
3041
31- /** Size (in bytes) of a raw/binary oid */
42+ /** Size (in bytes) of a raw/binary sha1 oid */
3243#define GIT_OID_SHA1_SIZE 20
33- #define GIT_OID_SHA256_SIZE 32
34- #define GIT_OID_MAX_SIZE GIT_OID_SHA256_SIZE
35-
36- /** Size (in bytes) of a hex formatted oid */
44+ /** Size (in bytes) of a hex formatted sha1 oid */
3745#define GIT_OID_SHA1_HEXSIZE (GIT_OID_SHA1_SIZE * 2)
38- #define GIT_OID_SHA256_HEXSIZE (GIT_OID_SHA256_SIZE * 2)
39- #define GIT_OID_MAX_HEXSIZE GIT_OID_SHA256_HEXSIZE
46+
47+ /**
48+ * The binary representation of the null sha1 object ID.
49+ */
50+ #ifndef GIT_EXPERIMENTAL_SHA256
51+ # define GIT_OID_SHA1_ZERO { { 0 } }
52+ #else
53+ # define GIT_OID_SHA1_ZERO { GIT_OID_SHA1, { 0 } }
54+ #endif
55+
56+ /**
57+ * The string representation of the null sha1 object ID.
58+ */
59+ #define GIT_OID_SHA1_HEXZERO "0000000000000000000000000000000000000000"
60+
61+ /*
62+ * Experimental SHA256 support is a breaking change to the API.
63+ * This exists for application compatibility testing.
64+ */
65+
66+ #ifdef GIT_EXPERIMENTAL_SHA256
67+
68+ /** Size (in bytes) of a raw/binary sha256 oid */
69+ # define GIT_OID_SHA256_SIZE 32
70+ /** Size (in bytes) of a hex formatted sha256 oid */
71+ # define GIT_OID_SHA256_HEXSIZE (GIT_OID_SHA256_SIZE * 2)
72+
73+ /**
74+ * The binary representation of the null sha256 object ID.
75+ */
76+ # define GIT_OID_SHA256_ZERO { GIT_OID_SHA256, { 0 } }
77+
78+ /**
79+ * The string representation of the null sha256 object ID.
80+ */
81+ # define GIT_OID_SHA256_HEXZERO "0000000000000000000000000000000000000000000000000000000000000000"
82+
83+ #endif
84+
85+ /* Maximum possible object ID size in raw / hex string format. */
86+ #ifndef GIT_EXPERIMENTAL_SHA256
87+ # define GIT_OID_MAX_SIZE GIT_OID_SHA1_SIZE
88+ # define GIT_OID_MAX_HEXSIZE GIT_OID_SHA1_HEXSIZE
89+ #else
90+ # define GIT_OID_MAX_SIZE GIT_OID_SHA256_SIZE
91+ # define GIT_OID_MAX_HEXSIZE GIT_OID_SHA256_HEXSIZE
92+ #endif
4093
4194/** Minimum length (in number of hex characters,
4295 * i.e. packets of 4 bits) of an oid prefix */
4396#define GIT_OID_MINPREFIXLEN 4
4497
4598/** Unique identity of any object (commit, tree, blob, tag). */
4699typedef struct git_oid {
100+
101+ #ifdef GIT_EXPERIMENTAL_SHA256
47102 /** type of object id */
48103 unsigned char type ;
104+ #endif
49105
50106 /** raw binary formatted id */
51107 unsigned char id [GIT_OID_MAX_SIZE ];
52108} git_oid ;
53109
54- /**
55- * The binary representation of the null object ID.
56- */
57- #define GIT_OID_SHA1_ZERO { GIT_OID_SHA1, { 0 } }
58- #define GIT_OID_SHA256_ZERO { GIT_OID_SHA256, { 0 } }
59-
60- /**
61- * The string representation of the null object ID.
62- */
63- #define GIT_OID_SHA1_HEXZERO "0000000000000000000000000000000000000000"
64- #define GIT_OID_SHA256_HEXZERO "0000000000000000000000000000000000000000000000000000000000000000"
65-
66110/**
67111 * Parse a hex formatted object id into a git_oid.
68112 *
0 commit comments