]> git.proxmox.com Git - libgit2.git/commitdiff
Remove git_hash_ctx_new - callers now _ctx_init()
authorEdward Thomson <ethomson@microsoft.com>
Tue, 13 Nov 2012 01:22:49 +0000 (19:22 -0600)
committerEdward Thomson <ethomson@edwardthomson.com>
Tue, 13 Nov 2012 16:23:05 +0000 (10:23 -0600)
15 files changed:
src/filebuf.c
src/hash.c
src/hash.h
src/hash/hash_generic.c
src/hash/hash_generic.h
src/hash/hash_openssl.h
src/hash/hash_ppc.c
src/hash/hash_ppc.h
src/hash/hash_win32.c
src/indexer.c
src/odb.c
src/pack-objects.c
src/pack-objects.h
src/sha1.h [deleted file]
tests-clar/object/raw/hash.c

index 6194fe5e3ed1272b4c36dd56f6963cd433e5c2a8..287446673d9ee0efec60902763650844cb365397 100644 (file)
@@ -108,8 +108,10 @@ void git_filebuf_cleanup(git_filebuf *file)
        if (file->fd_is_open && file->path_lock && git_path_exists(file->path_lock))
                p_unlink(file->path_lock);
 
-       if (file->digest)
-               git_hash_ctx_free(file->digest);
+       if (file->digest) {
+               git_hash_ctx_cleanup(file->digest);
+               git__free(file->digest);
+       }
 
        if (file->buffer)
                git__free(file->buffer);
@@ -221,8 +223,11 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags)
 
        /* If we are hashing on-write, allocate a new hash context */
        if (flags & GIT_FILEBUF_HASH_CONTENTS) {
-               file->digest = git_hash_ctx_new();
+               file->digest = git__calloc(1, sizeof(git_hash_ctx));
                GITERR_CHECK_ALLOC(file->digest);
+
+               if (git_hash_ctx_init(file->digest) < 0)
+                       goto cleanup;
        }
 
        compression = flags >> GIT_FILEBUF_DEFLATE_SHIFT;
@@ -299,7 +304,8 @@ int git_filebuf_hash(git_oid *oid, git_filebuf *file)
                return -1;
 
        git_hash_final(oid, file->digest);
-       git_hash_ctx_free(file->digest);
+       git_hash_ctx_cleanup(file->digest);
+       git__free(file->digest);
        file->digest = NULL;
 
        return 0;
index 336030d415e3312742841db22f2ba080a3f1f3b4..21db2e129d034fc19d001ff4a645473356ce295b 100644 (file)
 
 int git_hash_buf(git_oid *out, const void *data, size_t len)
 {
-       git_hash_ctx *ctx;
+       git_hash_ctx ctx;
        int error = 0;
 
-       if ((ctx = git_hash_ctx_new()) == NULL)
+       if (git_hash_ctx_init(&ctx) < 0)
                return -1;
 
-       if ((error = git_hash_update(ctx, data, len)) >= 0)
-               error = git_hash_final(out, ctx);
+       if ((error = git_hash_update(&ctx, data, len)) >= 0)
+               error = git_hash_final(out, &ctx);
 
-       git_hash_ctx_free(ctx);
+       git_hash_ctx_cleanup(&ctx);
        
        return error;
 }
 
 int git_hash_vec(git_oid *out, git_buf_vec *vec, size_t n)
 {
-       git_hash_ctx *ctx;
+       git_hash_ctx ctx;
        size_t i;
        int error = 0;
 
-       if ((ctx = git_hash_ctx_new()) == NULL)
+       if (git_hash_ctx_init(&ctx) < 0)
                return -1;
 
        for (i = 0; i < n; i++) {
-               if ((error = git_hash_update(ctx, vec[i].data, vec[i].len)) < 0)
+               if ((error = git_hash_update(&ctx, vec[i].data, vec[i].len)) < 0)
                        goto done;
        }
 
-       error = git_hash_final(out, ctx);
+       error = git_hash_final(out, &ctx);
 
 done:
-       git_hash_ctx_free(ctx);
+       git_hash_ctx_cleanup(&ctx);
 
        return error;
 }
index 2a9e19837c16bb09ee7b929288e854c88f77c502..e3f1f3f66658e3988f3f4d43dfc1c858185f324c 100644 (file)
@@ -12,6 +12,9 @@
 typedef struct git_hash_prov git_hash_prov;
 typedef struct git_hash_ctx git_hash_ctx;
 
+int git_hash_ctx_init(git_hash_ctx *ctx);
+void git_hash_ctx_cleanup(git_hash_ctx *ctx);
+
 #if defined(OPENSSL_SHA1)
 # include "hash/hash_openssl.h"
 #elif defined(WIN32_SHA1)
@@ -27,9 +30,6 @@ typedef struct {
        size_t len;
 } git_buf_vec;
 
-git_hash_ctx *git_hash_ctx_new(void);
-void git_hash_ctx_free(git_hash_ctx *ctx);
-
 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);
index cab5469d7c4137d0a1d2f5d2baf4cf8e6e0fb914..30d7a5d1e9dc20c70eeb0754deaf7af3b907060c 100644 (file)
@@ -221,18 +221,6 @@ static void hash__block(git_hash_ctx *ctx, const unsigned int *data)
        ctx->H[4] += E;
 }
 
-git_hash_ctx *git_hash_ctx_new(void)
-{
-       git_hash_ctx *ctx = git__malloc(sizeof(git_hash_ctx));
-
-       if (!ctx)
-               return NULL;
-
-       git_hash_init(ctx);
-
-       return ctx;
-}
-
 int git_hash_init(git_hash_ctx *ctx)
 {
        ctx->size = 0;
@@ -298,8 +286,3 @@ int git_hash_final(git_oid *out, git_hash_ctx *ctx)
        return 0;
 }
 
-void git_hash_ctx_free(git_hash_ctx *ctx)
-{
-       if (ctx)
-               git__free(ctx);
-}
index 400c7edccb490528590f80e78a320f8237287ca8..c5891c1649915f830e6d40064f3cede9d3f3b413 100644 (file)
@@ -16,4 +16,7 @@ struct git_hash_ctx {
     unsigned int W[16];
 };
 
+#define git_hash_ctx_init(ctx) git_hash_init(ctx)
+#define git_hash_ctx_cleanup(ctx)
+
 #endif /* INCLUDE_hash_generic_h__ */
index b416db50cb649cbab11207063848d9567298e649..0d37f135b971517bc856765a6592b2e83cb93269 100644 (file)
@@ -16,23 +16,8 @@ struct git_hash_ctx {
        SHA_CTX c;
 };
 
-GIT_INLINE(git_hash_ctx *) git_hash_ctx_new(void)
-{
-       git_hash_ctx *ctx = git__malloc(sizeof(git_hash_ctx));
-
-       if (!ctx)
-               return NULL;
-
-       SHA1_Init(&ctx->c);
-
-       return ctx;
-}
-
-GIT_INLINE(void) git_hash_ctx_free(git_hash_ctx *ctx)
-{
-       if (ctx)
-               git__free(ctx);
-}
+#define git_hash_ctx_init(ctx) git_hash_init(ctx)
+#define git_hash_ctx_cleanup(ctx)
 
 GIT_INLINE(int) git_hash_init(git_hash_ctx *ctx)
 {
index 95ad3b1a1870e05ac293a0e1d54914bc8d36e32b..de89e9f5e8066b36996ead3752b4d00512700d5a 100644 (file)
 extern void hash_ppc_core(uint32_t *hash, const unsigned char *p,
                         unsigned int nblocks);
 
-git_hash_ctx *git_hash_ctx_new(void)
-{
-    git_hash_ctx *ctx = git__malloc(sizeof(git_hash_ctx));
-
-    if (!ctx)
-        return NULL;
-
-    git_hash_init(ctx);
-
-    return ctx;
-}
-
 int git_hash_init(git_hash_ctx *c)
 {
        c->hash[0] = 0x67452301;
@@ -84,8 +72,3 @@ int git_hash_final(git_oid *oid, git_hash_ctx *c)
        return 0;
 }
 
-void git_hash_ctx_free(git_hash_ctx *ctx)
-{
-    if (ctx)
-        git__free(ctx);
-}
index 200d1931055eeaa2848f35310b809ec7250e1695..df78d9135ff3617f8f3619854c8ddd34560734da 100644 (file)
@@ -20,4 +20,7 @@ struct git_hash_ctx {
        } buf;
 };
 
+#define git_hash_ctx_init(ctx) git_hash_init(ctx)
+#define git_hash_ctx_cleanup(ctx)
+
 #endif /* INCLUDE_hash_generic_h__ */
index 26b3554b5d814ff92db7716dbf45c939388b7e6b..1fac452733197bf9fdb565298c2951fd936ce97e 100644 (file)
@@ -100,22 +100,12 @@ static int hash_win32_prov_init(git_hash_prov *prov)
 
 /* CryptoAPI: available in Windows XP and newer */
 
-GIT_INLINE(git_hash_ctx *) hash_ctx_cryptoapi_new(git_hash_prov *prov)
+GIT_INLINE(int) hash_ctx_cryptoapi_init(git_hash_ctx *ctx, git_hash_prov *prov)
 {
-       git_hash_ctx *ctx;
-
-       if ((ctx = git__calloc(1, sizeof(git_hash_ctx))) == NULL)
-               return NULL;
-
        ctx->type = CRYPTOAPI;
        ctx->prov = prov;
 
-       if (git_hash_init(ctx) < 0) {
-               git__free(ctx);
-               return NULL;
-       }
-
-       return ctx;
+       return git_hash_init(ctx);
 }
 
 GIT_INLINE(int) hash_cryptoapi_init(git_hash_ctx *ctx)
@@ -158,7 +148,7 @@ GIT_INLINE(int) hash_cryptoapi_final(git_oid *out, git_hash_ctx *ctx)
        return error;
 }
 
-GIT_INLINE(void) hash_cryptoapi_free(git_hash_ctx *ctx)
+GIT_INLINE(void) hash_ctx_cryptoapi_cleanup(git_hash_ctx *ctx)
 {
        if (ctx->ctx.cryptoapi.valid)
                CryptDestroyHash(ctx->ctx.cryptoapi.hash_handle);
@@ -166,24 +156,20 @@ GIT_INLINE(void) hash_cryptoapi_free(git_hash_ctx *ctx)
 
 /* CNG: Available in Windows Server 2008 and newer */
 
-GIT_INLINE(git_hash_ctx *) hash_ctx_cng_new(git_hash_prov *prov)
+GIT_INLINE(int) hash_ctx_cng_init(git_hash_ctx *ctx, git_hash_prov *prov)
 {
-       git_hash_ctx *ctx;
-
-       if ((ctx = git__calloc(1, sizeof(git_hash_ctx))) == NULL ||
-               (ctx->ctx.cng.hash_object = git__malloc(prov->prov.cng.hash_object_size)) == NULL)
-               return NULL;
+       if ((ctx->ctx.cng.hash_object = git__malloc(prov->prov.cng.hash_object_size)) == NULL)
+               return -1;
 
        if (prov->prov.cng.create_hash(prov->prov.cng.handle, &ctx->ctx.cng.hash_handle, ctx->ctx.cng.hash_object, prov->prov.cng.hash_object_size, NULL, 0, 0) < 0) {
                git__free(ctx->ctx.cng.hash_object);
-               git__free(ctx);
-               return NULL;
+               return -1;
        }
 
        ctx->type = CNG;
        ctx->prov = prov;
 
-       return ctx;
+       return 0;
 }
 
 GIT_INLINE(int) hash_cng_init(git_hash_ctx *ctx)
@@ -220,7 +206,7 @@ GIT_INLINE(int) hash_cng_final(git_oid *out, git_hash_ctx *ctx)
        return 0;
 }
 
-GIT_INLINE(void) hash_cng_free(git_hash_ctx *ctx)
+GIT_INLINE(void) hash_ctx_cng_cleanup(git_hash_ctx *ctx)
 {
        ctx->prov->prov.cng.destroy_hash(ctx->ctx.cng.hash_handle);
        git__free(ctx->ctx.cng.hash_object);
@@ -228,20 +214,24 @@ GIT_INLINE(void) hash_cng_free(git_hash_ctx *ctx)
 
 /* Indirection between CryptoAPI and CNG */
 
-git_hash_ctx *git_hash_ctx_new()
+int git_hash_ctx_init(git_hash_ctx *ctx)
 {
        git_global_st *global_state;
        git_hash_prov *hash_prov;
+       
+       assert(ctx);
+
+       memset(ctx, 0x0, sizeof(git_hash_ctx));
 
        if ((global_state = git__global_state()) == NULL)
-               return NULL;
+               return -1;
 
        hash_prov = &global_state->hash_prov;
 
        if (hash_prov->type == INVALID && hash_win32_prov_init(hash_prov) < 0)
-               return NULL;
+               return -1;
 
-       return (hash_prov->type == CNG) ? hash_ctx_cng_new(hash_prov) : hash_ctx_cryptoapi_new(hash_prov);
+       return (hash_prov->type == CNG) ? hash_ctx_cng_init(ctx, hash_prov) : hash_ctx_cryptoapi_init(ctx, hash_prov);
 }
 
 int git_hash_init(git_hash_ctx *ctx)
@@ -262,15 +252,12 @@ int git_hash_final(git_oid *out, git_hash_ctx *ctx)
        return (ctx->type == CNG) ? hash_cng_final(out, ctx) : hash_cryptoapi_final(out, ctx);
 }
 
-void git_hash_ctx_free(git_hash_ctx *ctx)
+void git_hash_ctx_cleanup(git_hash_ctx *ctx)
 {
-       if (ctx == NULL)
-               return;
+       assert(ctx);
 
        if (ctx->type == CNG)
-               hash_cng_free(ctx);
-       else
-               hash_cryptoapi_free(ctx);
-
-       git__free(ctx);
+               hash_ctx_cng_cleanup(ctx);
+       else if(ctx->type == CRYPTOAPI)
+               hash_ctx_cryptoapi_cleanup(ctx);
 }
index 20337d5528b98fbf486ec797a7fee09105eb84b4..4a4ed325a0c013336a6df01856d33ca82a7ad5ec 100644 (file)
@@ -461,10 +461,10 @@ int git_indexer_stream_finalize(git_indexer_stream *idx, git_transfer_progress *
        struct entry *entry;
        void *packfile_hash;
        git_oid file_hash;
-       git_hash_ctx *ctx;
+       git_hash_ctx ctx;
 
-       ctx = git_hash_ctx_new();
-       GITERR_CHECK_ALLOC(ctx);
+       if (git_hash_ctx_init(&ctx) < 0)
+               return -1;
 
        /* Test for this before resolve_deltas(), as it plays with idx->off */
        if (idx->off < idx->pack->mwf.size - GIT_OID_RAWSZ) {
@@ -506,9 +506,9 @@ int git_indexer_stream_finalize(git_indexer_stream *idx, git_transfer_progress *
        /* Write out the object names (SHA-1 hashes) */
        git_vector_foreach(&idx->objects, i, entry) {
                git_filebuf_write(&idx->index_file, &entry->oid, sizeof(git_oid));
-               git_hash_update(ctx, &entry->oid, GIT_OID_RAWSZ);
+               git_hash_update(&ctx, &entry->oid, GIT_OID_RAWSZ);
        }
-       git_hash_final(&idx->hash, ctx);
+       git_hash_final(&idx->hash, &ctx);
 
        /* Write out the CRC32 values */
        git_vector_foreach(&idx->objects, i, entry) {
@@ -583,7 +583,7 @@ on_error:
        p_close(idx->pack->mwf.fd);
        git_filebuf_cleanup(&idx->index_file);
        git_buf_free(&filename);
-       git_hash_ctx_free(ctx);
+       git_hash_ctx_cleanup(&ctx);
        return -1;
 }
 
@@ -684,10 +684,10 @@ int git_indexer_write(git_indexer *idx)
        struct entry *entry;
        void *packfile_hash;
        git_oid file_hash;
-       git_hash_ctx *ctx;
+       git_hash_ctx ctx;
 
-       ctx = git_hash_ctx_new();
-       GITERR_CHECK_ALLOC(ctx);
+       if (git_hash_ctx_init(&ctx) < 0)
+               return -1;
 
        git_vector_sort(&idx->objects);
 
@@ -719,11 +719,11 @@ int git_indexer_write(git_indexer *idx)
        /* Write out the object names (SHA-1 hashes) */
        git_vector_foreach(&idx->objects, i, entry) {
                if ((error = git_filebuf_write(&idx->file, &entry->oid, sizeof(git_oid))) < 0 ||
-                       (error = git_hash_update(ctx, &entry->oid, GIT_OID_RAWSZ)) < 0)
+                       (error = git_hash_update(&ctx, &entry->oid, GIT_OID_RAWSZ)) < 0)
                        goto cleanup;
        }
 
-       if ((error = git_hash_final(&idx->hash, ctx)) < 0)
+       if ((error = git_hash_final(&idx->hash, &ctx)) < 0)
                goto cleanup;
 
        /* Write out the CRC32 values */
@@ -802,7 +802,7 @@ cleanup:
        if (error < 0)
                git_filebuf_cleanup(&idx->file);
        git_buf_free(&filename);
-       git_hash_ctx_free(ctx);
+       git_hash_ctx_cleanup(&ctx);
 
        return error;
 }
index 027aeddaab7711edfb97ac9380d7c55ae94ecdad..bc135e35c4f7d2917aafdbbf0f04773f41703466 100644 (file)
--- a/src/odb.c
+++ b/src/odb.c
@@ -117,7 +117,7 @@ int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_otype type)
 {
        int hdr_len;
        char hdr[64], buffer[2048];
-       git_hash_ctx *ctx;
+       git_hash_ctx ctx;
        ssize_t read_len = 0;
        int error = 0;
 
@@ -126,16 +126,16 @@ int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_otype type)
                return -1;
        }
 
-       ctx = git_hash_ctx_new();
-       GITERR_CHECK_ALLOC(ctx);
+       if ((error = git_hash_ctx_init(&ctx)) < 0)
+               return -1;
 
        hdr_len = format_object_header(hdr, sizeof(hdr), size, type);
 
-       if ((error = git_hash_update(ctx, hdr, hdr_len)) < 0)
+       if ((error = git_hash_update(&ctx, hdr, hdr_len)) < 0)
                goto done;
 
        while (size > 0 && (read_len = p_read(fd, buffer, sizeof(buffer))) > 0) {
-               if ((error = git_hash_update(ctx, buffer, read_len)) < 0)
+               if ((error = git_hash_update(&ctx, buffer, read_len)) < 0)
                        goto done;
 
                size -= read_len;
@@ -152,10 +152,10 @@ int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_otype type)
                return -1;
        }
 
-       error = git_hash_final(out, ctx);
+       error = git_hash_final(out, &ctx);
 
 done:
-       git_hash_ctx_free(ctx);
+       git_hash_ctx_cleanup(&ctx);
        return error;
 }
 
index 58a70d0e062fe67d10c9081843a85c14ba7ad8f4..f75267629e15cdb6584f711e23f7644ec0aac481 100644 (file)
@@ -103,7 +103,7 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
 
        *out = NULL;
 
-       pb = git__calloc(sizeof(*pb), 1);
+       pb = git__calloc(1, sizeof(*pb));
        GITERR_CHECK_ALLOC(pb);
 
        pb->object_ix = git_oidmap_alloc();
@@ -113,9 +113,8 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
 
        pb->repo = repo;
        pb->nr_threads = 1; /* do not spawn any thread by default */
-       pb->ctx = git_hash_ctx_new();
 
-       if (!pb->ctx ||
+       if (git_hash_ctx_init(&pb->ctx) < 0 ||
                git_repository_odb(&pb->odb, repo) < 0 ||
                packbuilder_config(pb) < 0)
                goto on_error;
@@ -297,12 +296,12 @@ static int write_object(git_buf *buf, git_packbuilder *pb, git_pobject *po)
        if (git_buf_put(buf, (char *)hdr, hdr_len) < 0)
                goto on_error;
 
-       if (git_hash_update(pb->ctx, hdr, hdr_len) < 0)
+       if (git_hash_update(&pb->ctx, hdr, hdr_len) < 0)
                goto on_error;
 
        if (type == GIT_OBJ_REF_DELTA) {
                if (git_buf_put(buf, (char *)po->delta->id.id, GIT_OID_RAWSZ) < 0 ||
-                       git_hash_update(pb->ctx, po->delta->id.id, GIT_OID_RAWSZ) < 0)
+                       git_hash_update(&pb->ctx, po->delta->id.id, GIT_OID_RAWSZ) < 0)
                        goto on_error;
        }
 
@@ -319,7 +318,7 @@ static int write_object(git_buf *buf, git_packbuilder *pb, git_pobject *po)
        }
 
        if (git_buf_put(buf, data, size) < 0 ||
-               git_hash_update(pb->ctx, data, size) < 0)
+               git_hash_update(&pb->ctx, data, size) < 0)
                goto on_error;
 
        if (po->delta_data)
@@ -571,7 +570,7 @@ static int write_pack(git_packbuilder *pb,
        if (cb(&ph, sizeof(ph), data) < 0)
                goto on_error;
 
-       if (git_hash_update(pb->ctx, &ph, sizeof(ph)) < 0)
+       if (git_hash_update(&pb->ctx, &ph, sizeof(ph)) < 0)
                goto on_error;
 
        pb->nr_remaining = pb->nr_objects;
@@ -592,7 +591,7 @@ static int write_pack(git_packbuilder *pb,
        git__free(write_order);
        git_buf_free(&buf);
 
-       if (git_hash_final(&pb->pack_oid, pb->ctx) < 0)
+       if (git_hash_final(&pb->pack_oid, &pb->ctx) < 0)
                goto on_error;
 
        return cb(pb->pack_oid.id, GIT_OID_RAWSZ, data);
@@ -1319,14 +1318,13 @@ void git_packbuilder_free(git_packbuilder *pb)
        if (pb->odb)
                git_odb_free(pb->odb);
 
-       if (pb->ctx)
-               git_hash_ctx_free(pb->ctx);
-
        if (pb->object_ix)
                git_oidmap_free(pb->object_ix);
 
        if (pb->object_list)
                git__free(pb->object_list);
 
+       git_hash_ctx_cleanup(&pb->ctx);
+
        git__free(pb);
 }
index 0a88f7dd73d576d60749c29c61577d547f987490..8c01f7189be732e5c15e17291c66e481e251b6cb 100644 (file)
@@ -52,7 +52,7 @@ struct git_packbuilder {
        git_repository *repo; /* associated repository */
        git_odb *odb; /* associated object database */
 
-       git_hash_ctx *ctx;
+       git_hash_ctx ctx;
 
        uint32_t nr_objects,
                 nr_alloc,
diff --git a/src/sha1.h b/src/sha1.h
deleted file mode 100644 (file)
index 41e8aba..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2009-2012 the libgit2 contributors
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-
-#ifndef INCLUDE_sha1_h__
-#define INCLUDE_sha1_h__
-
-#ifdef OPENSSL_SHA
-# include <openssl/sha.h>
-
-#else
-typedef struct {
-       unsigned long long size;
-       unsigned int H[5];
-       unsigned int W[16];
-} blk_SHA_CTX;
-
-
-void git__blk_SHA1_Init(blk_SHA_CTX *ctx);
-void git__blk_SHA1_Update(blk_SHA_CTX *ctx, const void *dataIn, size_t len);
-void git__blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx);
-
-#define SHA_CTX                blk_SHA_CTX
-#define SHA1_Init      git__blk_SHA1_Init
-#define SHA1_Update    git__blk_SHA1_Update
-#define SHA1_Final     git__blk_SHA1_Final
-
-#endif // OPENSSL_SHA
-
-#endif
index 94be42cdcd87800520c8d0797e8330ab31b0780b..f26035e45cc0edb3f2e63778408dcbc39d7c08e1 100644 (file)
@@ -23,25 +23,25 @@ static char *bye_text = "bye world\n";
 
 void test_object_raw_hash__hash_by_blocks(void)
 {
-    git_hash_ctx *ctx;
+    git_hash_ctx ctx;
     git_oid id1, id2;
 
-    cl_assert((ctx = git_hash_ctx_new()) != NULL);
+       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_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_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);
 
-    git_hash_ctx_free(ctx);
+    git_hash_ctx_cleanup(&ctx);
 }
 
 void test_object_raw_hash__hash_buffer_in_single_call(void)