]> git.ipfire.org Git - thirdparty/git.git/blame - csum-file.h
Git 2.23-rc1
[thirdparty/git.git] / csum-file.h
CommitLineData
c38138cd
LT
1#ifndef CSUM_FILE_H
2#define CSUM_FILE_H
3
ef3ca954
EN
4#include "hash.h"
5
2a128d63
NP
6struct progress;
7
c38138cd 8/* A SHA1-protected file */
98a3beab 9struct hashfile {
ec640ed1 10 int fd;
e337a04d 11 int check_fd;
ec640ed1 12 unsigned int offset;
4d273500 13 git_hash_ctx ctx;
218558af 14 off_t total;
2a128d63 15 struct progress *tp;
ec640ed1 16 const char *name;
78d1e84f
NP
17 int do_crc;
18 uint32_t crc32;
c38138cd
LT
19 unsigned char buffer[8192];
20};
21
6c526148 22/* Checkpoint */
98a3beab 23struct hashfile_checkpoint {
6c526148 24 off_t offset;
4d273500 25 git_hash_ctx ctx;
6c526148
JH
26};
27
55454427
DL
28void hashfile_checkpoint(struct hashfile *, struct hashfile_checkpoint *);
29int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *);
6c526148 30
f2af9f5e 31/* finalize_hashfile flags */
cfe83216
DS
32#define CSUM_CLOSE 1
33#define CSUM_FSYNC 2
34#define CSUM_HASH_IN_STREAM 4
4c81b03e 35
55454427
DL
36struct hashfile *hashfd(int fd, const char *name);
37struct hashfile *hashfd_check(const char *name);
38struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp);
39int finalize_hashfile(struct hashfile *, unsigned char *, unsigned int);
40void hashwrite(struct hashfile *, const void *, unsigned int);
41void hashflush(struct hashfile *f);
42void crc32_begin(struct hashfile *);
43uint32_t crc32_end(struct hashfile *);
c38138cd 44
98a3beab 45static inline void hashwrite_u8(struct hashfile *f, uint8_t data)
b5007211 46{
98a3beab 47 hashwrite(f, &data, sizeof(data));
b5007211
KB
48}
49
98a3beab 50static inline void hashwrite_be32(struct hashfile *f, uint32_t data)
b5007211
KB
51{
52 data = htonl(data);
98a3beab 53 hashwrite(f, &data, sizeof(data));
b5007211
KB
54}
55
c38138cd 56#endif