csum-file: abstract uses of SHA-1

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>

brian m. carlson committed Feb 1, 2018 at 02:18 UTC 4d2735005a6512c4dae8b9ed892640db91351dff
2 files changed +7 -7
csum-file.c
+5 -5
@@ -47,7 +47,7 @@ void hashflush(struct hashfile *f)
47 unsigned offset = f->offset;
48
49 if (offset) {
50 - git_SHA1_Update(&f->ctx, f->buffer, offset);
50 + the_hash_algo->update_fn(&f->ctx, f->buffer, offset);
51 flush(f, f->buffer, offset);
52 f->offset = 0;
53 }
@@ -58,12 +58,12 @@ int hashclose(struct hashfile *f, unsigned char *result, unsigned int flags)
58 int fd;
59
60 hashflush(f);
61 - git_SHA1_Final(f->buffer, &f->ctx);
61 + the_hash_algo->final_fn(f->buffer, &f->ctx);
62 if (result)
63 hashcpy(result, f->buffer);
64 if (flags & (CSUM_CLOSE | CSUM_FSYNC)) {
65 /* write checksum and close fd */
66 - flush(f, f->buffer, 20);
66 + flush(f, f->buffer, the_hash_algo->rawsz);
67 if (flags & CSUM_FSYNC)
68 fsync_or_die(f->fd, f->name);
69 if (close(f->fd))
@@ -110,7 +110,7 @@ void hashwrite(struct hashfile *f, const void *buf, unsigned int count)
110 buf = (char *) buf + nr;
111 left -= nr;
112 if (!left) {
113 - git_SHA1_Update(&f->ctx, data, offset);
113 + the_hash_algo->update_fn(&f->ctx, data, offset);
114 flush(f, data, offset);
115 offset = 0;
116 }
@@ -149,7 +149,7 @@ struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp
149 f->tp = tp;
150 f->name = name;
151 f->do_crc = 0;
152 - git_SHA1_Init(&f->ctx);
152 + the_hash_algo->init_fn(&f->ctx);
153 return f;
154 }
155
csum-file.h
+2 -2
@@ -8,7 +8,7 @@ struct hashfile {
8 int fd;
9 int check_fd;
10 unsigned int offset;
11 - git_SHA_CTX ctx;
11 + git_hash_ctx ctx;
12 off_t total;
13 struct progress *tp;
14 const char *name;
@@ -20,7 +20,7 @@ struct hashfile {
20 /* Checkpoint */
21 struct hashfile_checkpoint {
22 off_t offset;
23 - git_SHA_CTX ctx;
23 + git_hash_ctx ctx;
24 };
25
26 extern void hashfile_checkpoint(struct hashfile *, struct hashfile_checkpoint *);