Merge pull request #1363 from schu/hash-initialization hash: remove git_hash_init from internal api
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
diff --git a/src/hash.h b/src/hash.h
index 5b84898..dc9a79e 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -31,7 +31,6 @@ typedef struct {
size_t len;
} git_buf_vec;
-int git_hash_init(git_hash_ctx *c);
int git_hash_update(git_hash_ctx *c, const void *data, size_t len);
int git_hash_final(git_oid *out, git_hash_ctx *c);
diff --git a/src/hash/hash_generic.c b/src/hash/hash_generic.c
index 0723bfa..e496d1f 100644
--- a/src/hash/hash_generic.c
+++ b/src/hash/hash_generic.c
@@ -221,7 +221,7 @@ static void hash__block(git_hash_ctx *ctx, const unsigned int *data)
ctx->H[4] += E;
}
-int git_hash_init(git_hash_ctx *ctx)
+int git_hash_ctx_init(git_hash_ctx *ctx)
{
ctx->size = 0;
@@ -232,7 +232,7 @@ int git_hash_init(git_hash_ctx *ctx)
ctx->H[3] = 0x10325476;
ctx->H[4] = 0xc3d2e1f0;
- return 0;
+ return 0;
}
int git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
diff --git a/src/hash/hash_generic.h b/src/hash/hash_generic.h
index b731de8..bebf2c2 100644
--- a/src/hash/hash_generic.h
+++ b/src/hash/hash_generic.h
@@ -18,7 +18,6 @@ struct git_hash_ctx {
#define git_hash_global_init() 0
#define git_hash_global_shutdown() /* noop */
-#define git_hash_ctx_init(ctx) git_hash_init(ctx)
#define git_hash_ctx_cleanup(ctx)
#endif /* INCLUDE_hash_generic_h__ */
diff --git a/src/hash/hash_win32.c b/src/hash/hash_win32.c
index 43d54ca..3be3ba8 100644
--- a/src/hash/hash_win32.c
+++ b/src/hash/hash_win32.c
@@ -134,7 +134,7 @@ GIT_INLINE(int) hash_ctx_cryptoapi_init(git_hash_ctx *ctx)
ctx->type = CRYPTOAPI;
ctx->prov = &hash_prov;
- return git_hash_init(ctx);
+ return git_hash_ctx_init(ctx);
}
GIT_INLINE(int) hash_cryptoapi_init(git_hash_ctx *ctx)
@@ -262,7 +262,7 @@ int git_hash_ctx_init(git_hash_ctx *ctx)
return (hash_prov.type == CNG) ? hash_ctx_cng_init(ctx) : hash_ctx_cryptoapi_init(ctx);
}
-int git_hash_init(git_hash_ctx *ctx)
+int git_hash_ctx_init(git_hash_ctx *ctx)
{
assert(ctx && ctx->type);
return (ctx->type == CNG) ? hash_cng_init(ctx) : hash_cryptoapi_init(ctx);
diff --git a/tests-clar/object/raw/hash.c b/tests-clar/object/raw/hash.c
index f26035e..6e31cfa 100644
--- a/tests-clar/object/raw/hash.c
+++ b/tests-clar/object/raw/hash.c
@@ -8,11 +8,11 @@
static void hash_object_pass(git_oid *oid, git_rawobj *obj)
{
- cl_git_pass(git_odb_hash(oid, obj->data, obj->len, obj->type));
+ cl_git_pass(git_odb_hash(oid, obj->data, obj->len, obj->type));
}
static void hash_object_fail(git_oid *oid, git_rawobj *obj)
{
- cl_git_fail(git_odb_hash(oid, obj->data, obj->len, obj->type));
+ cl_git_fail(git_odb_hash(oid, obj->data, obj->len, obj->type));
}
static char *hello_id = "22596363b3de40b06f981fb85d82312e8c0ed511";
@@ -23,144 +23,144 @@ static char *bye_text = "bye world\n";
void test_object_raw_hash__hash_by_blocks(void)
{
- git_hash_ctx ctx;
- git_oid id1, id2;
+ git_hash_ctx ctx;
+ git_oid id1, id2;
cl_git_pass(git_hash_ctx_init(&ctx));
/* should already be init'd */
- cl_git_pass(git_hash_update(&ctx, hello_text, strlen(hello_text)));
- cl_git_pass(git_hash_final(&id2, &ctx));
- cl_git_pass(git_oid_fromstr(&id1, hello_id));
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_hash_update(&ctx, hello_text, strlen(hello_text)));
+ cl_git_pass(git_hash_final(&id2, &ctx));
+ cl_git_pass(git_oid_fromstr(&id1, hello_id));
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
/* reinit should permit reuse */
- cl_git_pass(git_hash_init(&ctx));
- cl_git_pass(git_hash_update(&ctx, bye_text, strlen(bye_text)));
- cl_git_pass(git_hash_final(&id2, &ctx));
- cl_git_pass(git_oid_fromstr(&id1, bye_id));
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_hash_ctx_init(&ctx));
+ cl_git_pass(git_hash_update(&ctx, bye_text, strlen(bye_text)));
+ cl_git_pass(git_hash_final(&id2, &ctx));
+ cl_git_pass(git_oid_fromstr(&id1, bye_id));
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
- git_hash_ctx_cleanup(&ctx);
+ git_hash_ctx_cleanup(&ctx);
}
void test_object_raw_hash__hash_buffer_in_single_call(void)
{
- git_oid id1, id2;
+ git_oid id1, id2;
- cl_git_pass(git_oid_fromstr(&id1, hello_id));
- git_hash_buf(&id2, hello_text, strlen(hello_text));
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_oid_fromstr(&id1, hello_id));
+ git_hash_buf(&id2, hello_text, strlen(hello_text));
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_vector(void)
{
- git_oid id1, id2;
- git_buf_vec vec[2];
+ git_oid id1, id2;
+ git_buf_vec vec[2];
- cl_git_pass(git_oid_fromstr(&id1, hello_id));
+ cl_git_pass(git_oid_fromstr(&id1, hello_id));
- vec[0].data = hello_text;
- vec[0].len = 4;
- vec[1].data = hello_text+4;
- vec[1].len = strlen(hello_text)-4;
+ vec[0].data = hello_text;
+ vec[0].len = 4;
+ vec[1].data = hello_text+4;
+ vec[1].len = strlen(hello_text)-4;
- git_hash_vec(&id2, vec, 2);
+ git_hash_vec(&id2, vec, 2);
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_junk_data(void)
{
- git_oid id, id_zero;
+ git_oid id, id_zero;
- cl_git_pass(git_oid_fromstr(&id_zero, zero_id));
+ cl_git_pass(git_oid_fromstr(&id_zero, zero_id));
- /* invalid types: */
- junk_obj.data = some_data;
- hash_object_fail(&id, &junk_obj);
+ /* invalid types: */
+ junk_obj.data = some_data;
+ hash_object_fail(&id, &junk_obj);
- junk_obj.type = GIT_OBJ__EXT1;
- hash_object_fail(&id, &junk_obj);
+ junk_obj.type = GIT_OBJ__EXT1;
+ hash_object_fail(&id, &junk_obj);
- junk_obj.type = GIT_OBJ__EXT2;
- hash_object_fail(&id, &junk_obj);
+ junk_obj.type = GIT_OBJ__EXT2;
+ hash_object_fail(&id, &junk_obj);
- junk_obj.type = GIT_OBJ_OFS_DELTA;
- hash_object_fail(&id, &junk_obj);
+ junk_obj.type = GIT_OBJ_OFS_DELTA;
+ hash_object_fail(&id, &junk_obj);
- junk_obj.type = GIT_OBJ_REF_DELTA;
- hash_object_fail(&id, &junk_obj);
+ junk_obj.type = GIT_OBJ_REF_DELTA;
+ hash_object_fail(&id, &junk_obj);
- /* data can be NULL only if len is zero: */
- junk_obj.type = GIT_OBJ_BLOB;
- junk_obj.data = NULL;
- hash_object_pass(&id, &junk_obj);
- cl_assert(git_oid_cmp(&id, &id_zero) == 0);
+ /* data can be NULL only if len is zero: */
+ junk_obj.type = GIT_OBJ_BLOB;
+ junk_obj.data = NULL;
+ hash_object_pass(&id, &junk_obj);
+ cl_assert(git_oid_cmp(&id, &id_zero) == 0);
- junk_obj.len = 1;
- hash_object_fail(&id, &junk_obj);
+ junk_obj.len = 1;
+ hash_object_fail(&id, &junk_obj);
}
void test_object_raw_hash__hash_commit_object(void)
{
- git_oid id1, id2;
+ git_oid id1, id2;
- cl_git_pass(git_oid_fromstr(&id1, commit_id));
- hash_object_pass(&id2, &commit_obj);
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_oid_fromstr(&id1, commit_id));
+ hash_object_pass(&id2, &commit_obj);
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_tree_object(void)
{
- git_oid id1, id2;
+ git_oid id1, id2;
- cl_git_pass(git_oid_fromstr(&id1, tree_id));
- hash_object_pass(&id2, &tree_obj);
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_oid_fromstr(&id1, tree_id));
+ hash_object_pass(&id2, &tree_obj);
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_tag_object(void)
{
- git_oid id1, id2;
+ git_oid id1, id2;
- cl_git_pass(git_oid_fromstr(&id1, tag_id));
- hash_object_pass(&id2, &tag_obj);
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_oid_fromstr(&id1, tag_id));
+ hash_object_pass(&id2, &tag_obj);
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_zero_length_object(void)
{
- git_oid id1, id2;
+ git_oid id1, id2;
- cl_git_pass(git_oid_fromstr(&id1, zero_id));
- hash_object_pass(&id2, &zero_obj);
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_oid_fromstr(&id1, zero_id));
+ hash_object_pass(&id2, &zero_obj);
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_one_byte_object(void)
{
- git_oid id1, id2;
+ git_oid id1, id2;
- cl_git_pass(git_oid_fromstr(&id1, one_id));
- hash_object_pass(&id2, &one_obj);
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_oid_fromstr(&id1, one_id));
+ hash_object_pass(&id2, &one_obj);
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_two_byte_object(void)
{
- git_oid id1, id2;
+ git_oid id1, id2;
- cl_git_pass(git_oid_fromstr(&id1, two_id));
- hash_object_pass(&id2, &two_obj);
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_oid_fromstr(&id1, two_id));
+ hash_object_pass(&id2, &two_obj);
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_multi_byte_object(void)
{
- git_oid id1, id2;
+ git_oid id1, id2;
- cl_git_pass(git_oid_fromstr(&id1, some_id));
- hash_object_pass(&id2, &some_obj);
- cl_assert(git_oid_cmp(&id1, &id2) == 0);
+ cl_git_pass(git_oid_fromstr(&id1, some_id));
+ hash_object_pass(&id2, &some_obj);
+ cl_assert(git_oid_cmp(&id1, &id2) == 0);
}