5 #include "write-or-die.h"
9 /* A SHA1-protected file */
14 struct git_hash_ctx ctx
;
21 unsigned char *buffer
;
22 unsigned char *check_buffer
;
23 const struct git_hash_algo
*algop
;
26 * If non-zero, skip_hash indicates that we should
27 * not actually compute the hash for this hashfile and
28 * instead only use it as a buffered write.
34 struct hashfile_checkpoint
{
36 struct git_hash_ctx ctx
;
39 void hashfile_checkpoint_init(struct hashfile
*, struct hashfile_checkpoint
*);
40 void hashfile_checkpoint(struct hashfile
*, struct hashfile_checkpoint
*);
41 int hashfile_truncate(struct hashfile
*, struct hashfile_checkpoint
*);
43 /* finalize_hashfile flags */
46 #define CSUM_HASH_IN_STREAM 4
48 struct hashfile
*hashfd(const struct git_hash_algo
*algop
,
49 int fd
, const char *name
);
50 struct hashfile
*hashfd_check(const struct git_hash_algo
*algop
,
52 struct hashfile
*hashfd_throughput(const struct git_hash_algo
*algop
,
53 int fd
, const char *name
, struct progress
*tp
);
56 * Free the hashfile without flushing its contents to disk. This only
57 * needs to be called when not calling `finalize_hashfile()`.
59 void free_hashfile(struct hashfile
*f
);
62 * Finalize the hashfile by flushing data to disk and free'ing it.
64 int finalize_hashfile(struct hashfile
*, unsigned char *, enum fsync_component
, unsigned int);
65 void discard_hashfile(struct hashfile
*);
66 void hashwrite(struct hashfile
*, const void *, unsigned int);
67 void hashflush(struct hashfile
*f
);
68 void crc32_begin(struct hashfile
*);
69 uint32_t crc32_end(struct hashfile
*);
71 /* Verify checksum validity while reading. Returns non-zero on success. */
72 int hashfile_checksum_valid(const struct git_hash_algo
*algop
,
73 const unsigned char *data
, size_t len
);
76 * Returns the total number of bytes fed to the hashfile so far (including ones
77 * that have not been written out to the descriptor yet).
79 static inline off_t
hashfile_total(struct hashfile
*f
)
81 return f
->total
+ f
->offset
;
84 static inline void hashwrite_u8(struct hashfile
*f
, uint8_t data
)
86 hashwrite(f
, &data
, sizeof(data
));
89 static inline void hashwrite_be32(struct hashfile
*f
, uint32_t data
)
92 hashwrite(f
, &data
, sizeof(data
));
95 static inline size_t hashwrite_be64(struct hashfile
*f
, uint64_t data
)
98 hashwrite(f
, &data
, sizeof(data
));