]> git.ipfire.org Git - thirdparty/git.git/commitdiff
csum-file: abstract uses of SHA-1
authorbrian m. carlson <sandals@crustytoothpaste.net>
Thu, 1 Feb 2018 02:18:47 +0000 (02:18 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 2 Feb 2018 19:28:41 +0000 (11:28 -0800)
Convert several direct uses of SHA-1 to use the_hash_algo instead.
Convert one use of the constant 20 as well.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
csum-file.c
csum-file.h

index e4ad6337dc97bb4cbf6406bc982dc69761d460cc..5eda7fb6af673ae82989dab871aaac74ec9ff629 100644 (file)
@@ -47,7 +47,7 @@ void hashflush(struct hashfile *f)
        unsigned offset = f->offset;
 
        if (offset) {
-               git_SHA1_Update(&f->ctx, f->buffer, offset);
+               the_hash_algo->update_fn(&f->ctx, f->buffer, offset);
                flush(f, f->buffer, offset);
                f->offset = 0;
        }
@@ -58,12 +58,12 @@ int hashclose(struct hashfile *f, unsigned char *result, unsigned int flags)
        int fd;
 
        hashflush(f);
-       git_SHA1_Final(f->buffer, &f->ctx);
+       the_hash_algo->final_fn(f->buffer, &f->ctx);
        if (result)
                hashcpy(result, f->buffer);
        if (flags & (CSUM_CLOSE | CSUM_FSYNC)) {
                /* write checksum and close fd */
-               flush(f, f->buffer, 20);
+               flush(f, f->buffer, the_hash_algo->rawsz);
                if (flags & CSUM_FSYNC)
                        fsync_or_die(f->fd, f->name);
                if (close(f->fd))
@@ -110,7 +110,7 @@ void hashwrite(struct hashfile *f, const void *buf, unsigned int count)
                buf = (char *) buf + nr;
                left -= nr;
                if (!left) {
-                       git_SHA1_Update(&f->ctx, data, offset);
+                       the_hash_algo->update_fn(&f->ctx, data, offset);
                        flush(f, data, offset);
                        offset = 0;
                }
@@ -149,7 +149,7 @@ struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp
        f->tp = tp;
        f->name = name;
        f->do_crc = 0;
-       git_SHA1_Init(&f->ctx);
+       the_hash_algo->init_fn(&f->ctx);
        return f;
 }
 
index ceb3e5712d3a10594233489c0ce83a4f7474814a..992e5c014122d8fed3ee782d400e61de78e55271 100644 (file)
@@ -8,7 +8,7 @@ struct hashfile {
        int fd;
        int check_fd;
        unsigned int offset;
-       git_SHA_CTX ctx;
+       git_hash_ctx ctx;
        off_t total;
        struct progress *tp;
        const char *name;
@@ -20,7 +20,7 @@ struct hashfile {
 /* Checkpoint */
 struct hashfile_checkpoint {
        off_t offset;
-       git_SHA_CTX ctx;
+       git_hash_ctx ctx;
 };
 
 extern void hashfile_checkpoint(struct hashfile *, struct hashfile_checkpoint *);