Skip to content

Commit 4d27350

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 98a3bea commit 4d27350

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

csum-file.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void hashflush(struct hashfile *f)
4747
unsigned offset = f->offset;
4848

4949
if (offset) {
50-
git_SHA1_Update(&f->ctx, f->buffer, offset);
50+
the_hash_algo->update_fn(&f->ctx, f->buffer, offset);
5151
flush(f, f->buffer, offset);
5252
f->offset = 0;
5353
}
@@ -58,12 +58,12 @@ int hashclose(struct hashfile *f, unsigned char *result, unsigned int flags)
5858
int fd;
5959

6060
hashflush(f);
61-
git_SHA1_Final(f->buffer, &f->ctx);
61+
the_hash_algo->final_fn(f->buffer, &f->ctx);
6262
if (result)
6363
hashcpy(result, f->buffer);
6464
if (flags & (CSUM_CLOSE | CSUM_FSYNC)) {
6565
/* write checksum and close fd */
66-
flush(f, f->buffer, 20);
66+
flush(f, f->buffer, the_hash_algo->rawsz);
6767
if (flags & CSUM_FSYNC)
6868
fsync_or_die(f->fd, f->name);
6969
if (close(f->fd))
@@ -110,7 +110,7 @@ void hashwrite(struct hashfile *f, const void *buf, unsigned int count)
110110
buf = (char *) buf + nr;
111111
left -= nr;
112112
if (!left) {
113-
git_SHA1_Update(&f->ctx, data, offset);
113+
the_hash_algo->update_fn(&f->ctx, data, offset);
114114
flush(f, data, offset);
115115
offset = 0;
116116
}
@@ -149,7 +149,7 @@ struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp
149149
f->tp = tp;
150150
f->name = name;
151151
f->do_crc = 0;
152-
git_SHA1_Init(&f->ctx);
152+
the_hash_algo->init_fn(&f->ctx);
153153
return f;
154154
}
155155

csum-file.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct hashfile {
88
int fd;
99
int check_fd;
1010
unsigned int offset;
11-
git_SHA_CTX ctx;
11+
git_hash_ctx ctx;
1212
off_t total;
1313
struct progress *tp;
1414
const char *name;
@@ -20,7 +20,7 @@ struct hashfile {
2020
/* Checkpoint */
2121
struct hashfile_checkpoint {
2222
off_t offset;
23-
git_SHA_CTX ctx;
23+
git_hash_ctx ctx;
2424
};
2525

2626
extern void hashfile_checkpoint(struct hashfile *, struct hashfile_checkpoint *);

0 commit comments

Comments
 (0)