Coverage Report

Created: 2024-09-08 06:23

/src/git/csum-file.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef CSUM_FILE_H
2
#define CSUM_FILE_H
3
4
#include "hash.h"
5
#include "write-or-die.h"
6
7
struct progress;
8
9
/* A SHA1-protected file */
10
struct hashfile {
11
  int fd;
12
  int check_fd;
13
  unsigned int offset;
14
  git_hash_ctx ctx;
15
  off_t total;
16
  struct progress *tp;
17
  const char *name;
18
  int do_crc;
19
  uint32_t crc32;
20
  size_t buffer_len;
21
  unsigned char *buffer;
22
  unsigned char *check_buffer;
23
24
  /**
25
   * If non-zero, skip_hash indicates that we should
26
   * not actually compute the hash for this hashfile and
27
   * instead only use it as a buffered write.
28
   */
29
  int skip_hash;
30
};
31
32
/* Checkpoint */
33
struct hashfile_checkpoint {
34
  off_t offset;
35
  git_hash_ctx ctx;
36
};
37
38
void hashfile_checkpoint(struct hashfile *, struct hashfile_checkpoint *);
39
int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *);
40
41
/* finalize_hashfile flags */
42
0
#define CSUM_CLOSE    1
43
0
#define CSUM_FSYNC    2
44
0
#define CSUM_HASH_IN_STREAM 4
45
46
struct hashfile *hashfd(int fd, const char *name);
47
struct hashfile *hashfd_check(const char *name);
48
struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp);
49
50
/*
51
 * Free the hashfile without flushing its contents to disk. This only
52
 * needs to be called when not calling `finalize_hashfile()`.
53
 */
54
void free_hashfile(struct hashfile *f);
55
56
/*
57
 * Finalize the hashfile by flushing data to disk and free'ing it.
58
 */
59
int finalize_hashfile(struct hashfile *, unsigned char *, enum fsync_component, unsigned int);
60
void discard_hashfile(struct hashfile *);
61
void hashwrite(struct hashfile *, const void *, unsigned int);
62
void hashflush(struct hashfile *f);
63
void crc32_begin(struct hashfile *);
64
uint32_t crc32_end(struct hashfile *);
65
66
/* Verify checksum validity while reading. Returns non-zero on success. */
67
int hashfile_checksum_valid(const unsigned char *data, size_t len);
68
69
/*
70
 * Returns the total number of bytes fed to the hashfile so far (including ones
71
 * that have not been written out to the descriptor yet).
72
 */
73
static inline off_t hashfile_total(struct hashfile *f)
74
0
{
75
0
  return f->total + f->offset;
76
0
}
Unexecuted instantiation: fast-import.c:hashfile_total
Unexecuted instantiation: fsck.c:hashfile_total
Unexecuted instantiation: gc.c:hashfile_total
Unexecuted instantiation: index-pack.c:hashfile_total
Unexecuted instantiation: pack-objects.c:hashfile_total
Unexecuted instantiation: receive-pack.c:hashfile_total
Unexecuted instantiation: repack.c:hashfile_total
Unexecuted instantiation: rev-list.c:hashfile_total
Unexecuted instantiation: show-index.c:hashfile_total
Unexecuted instantiation: unpack-objects.c:hashfile_total
Unexecuted instantiation: bulk-checkin.c:hashfile_total
Unexecuted instantiation: commit-graph.c:hashfile_total
Unexecuted instantiation: csum-file.c:hashfile_total
Unexecuted instantiation: delta-islands.c:hashfile_total
Unexecuted instantiation: fetch-pack.c:hashfile_total
Unexecuted instantiation: midx.c:hashfile_total
Unexecuted instantiation: midx-write.c:hashfile_total
Unexecuted instantiation: object-file.c:hashfile_total
Unexecuted instantiation: pack-bitmap-write.c:hashfile_total
Unexecuted instantiation: pack-bitmap.c:hashfile_total
Unexecuted instantiation: pack-check.c:hashfile_total
Unexecuted instantiation: pack-revindex.c:hashfile_total
Unexecuted instantiation: pack-write.c:hashfile_total
Unexecuted instantiation: packfile.c:hashfile_total
Unexecuted instantiation: pseudo-merge.c:hashfile_total
Unexecuted instantiation: reachable.c:hashfile_total
Unexecuted instantiation: read-cache.c:hashfile_total
Unexecuted instantiation: chunk-format.c:hashfile_total
77
78
static inline void hashwrite_u8(struct hashfile *f, uint8_t data)
79
0
{
80
0
  hashwrite(f, &data, sizeof(data));
81
0
}
Unexecuted instantiation: fast-import.c:hashwrite_u8
Unexecuted instantiation: fsck.c:hashwrite_u8
Unexecuted instantiation: gc.c:hashwrite_u8
Unexecuted instantiation: index-pack.c:hashwrite_u8
Unexecuted instantiation: pack-objects.c:hashwrite_u8
Unexecuted instantiation: receive-pack.c:hashwrite_u8
Unexecuted instantiation: repack.c:hashwrite_u8
Unexecuted instantiation: rev-list.c:hashwrite_u8
Unexecuted instantiation: show-index.c:hashwrite_u8
Unexecuted instantiation: unpack-objects.c:hashwrite_u8
Unexecuted instantiation: bulk-checkin.c:hashwrite_u8
Unexecuted instantiation: commit-graph.c:hashwrite_u8
Unexecuted instantiation: csum-file.c:hashwrite_u8
Unexecuted instantiation: delta-islands.c:hashwrite_u8
Unexecuted instantiation: fetch-pack.c:hashwrite_u8
Unexecuted instantiation: midx.c:hashwrite_u8
Unexecuted instantiation: midx-write.c:hashwrite_u8
Unexecuted instantiation: object-file.c:hashwrite_u8
Unexecuted instantiation: pack-bitmap-write.c:hashwrite_u8
Unexecuted instantiation: pack-bitmap.c:hashwrite_u8
Unexecuted instantiation: pack-check.c:hashwrite_u8
Unexecuted instantiation: pack-revindex.c:hashwrite_u8
Unexecuted instantiation: pack-write.c:hashwrite_u8
Unexecuted instantiation: packfile.c:hashwrite_u8
Unexecuted instantiation: pseudo-merge.c:hashwrite_u8
Unexecuted instantiation: reachable.c:hashwrite_u8
Unexecuted instantiation: read-cache.c:hashwrite_u8
Unexecuted instantiation: chunk-format.c:hashwrite_u8
82
83
static inline void hashwrite_be32(struct hashfile *f, uint32_t data)
84
0
{
85
0
  data = htonl(data);
86
0
  hashwrite(f, &data, sizeof(data));
87
0
}
Unexecuted instantiation: fast-import.c:hashwrite_be32
Unexecuted instantiation: fsck.c:hashwrite_be32
Unexecuted instantiation: gc.c:hashwrite_be32
Unexecuted instantiation: index-pack.c:hashwrite_be32
Unexecuted instantiation: pack-objects.c:hashwrite_be32
Unexecuted instantiation: receive-pack.c:hashwrite_be32
Unexecuted instantiation: repack.c:hashwrite_be32
Unexecuted instantiation: rev-list.c:hashwrite_be32
Unexecuted instantiation: show-index.c:hashwrite_be32
Unexecuted instantiation: unpack-objects.c:hashwrite_be32
Unexecuted instantiation: bulk-checkin.c:hashwrite_be32
Unexecuted instantiation: commit-graph.c:hashwrite_be32
Unexecuted instantiation: csum-file.c:hashwrite_be32
Unexecuted instantiation: delta-islands.c:hashwrite_be32
Unexecuted instantiation: fetch-pack.c:hashwrite_be32
Unexecuted instantiation: midx.c:hashwrite_be32
Unexecuted instantiation: midx-write.c:hashwrite_be32
Unexecuted instantiation: object-file.c:hashwrite_be32
Unexecuted instantiation: pack-bitmap-write.c:hashwrite_be32
Unexecuted instantiation: pack-bitmap.c:hashwrite_be32
Unexecuted instantiation: pack-check.c:hashwrite_be32
Unexecuted instantiation: pack-revindex.c:hashwrite_be32
Unexecuted instantiation: pack-write.c:hashwrite_be32
Unexecuted instantiation: packfile.c:hashwrite_be32
Unexecuted instantiation: pseudo-merge.c:hashwrite_be32
Unexecuted instantiation: reachable.c:hashwrite_be32
Unexecuted instantiation: read-cache.c:hashwrite_be32
Unexecuted instantiation: chunk-format.c:hashwrite_be32
88
89
static inline size_t hashwrite_be64(struct hashfile *f, uint64_t data)
90
0
{
91
0
  data = htonll(data);
92
0
  hashwrite(f, &data, sizeof(data));
93
0
  return sizeof(data);
94
0
}
Unexecuted instantiation: fast-import.c:hashwrite_be64
Unexecuted instantiation: fsck.c:hashwrite_be64
Unexecuted instantiation: gc.c:hashwrite_be64
Unexecuted instantiation: index-pack.c:hashwrite_be64
Unexecuted instantiation: pack-objects.c:hashwrite_be64
Unexecuted instantiation: receive-pack.c:hashwrite_be64
Unexecuted instantiation: repack.c:hashwrite_be64
Unexecuted instantiation: rev-list.c:hashwrite_be64
Unexecuted instantiation: show-index.c:hashwrite_be64
Unexecuted instantiation: unpack-objects.c:hashwrite_be64
Unexecuted instantiation: bulk-checkin.c:hashwrite_be64
Unexecuted instantiation: commit-graph.c:hashwrite_be64
Unexecuted instantiation: csum-file.c:hashwrite_be64
Unexecuted instantiation: delta-islands.c:hashwrite_be64
Unexecuted instantiation: fetch-pack.c:hashwrite_be64
Unexecuted instantiation: midx.c:hashwrite_be64
Unexecuted instantiation: midx-write.c:hashwrite_be64
Unexecuted instantiation: object-file.c:hashwrite_be64
Unexecuted instantiation: pack-bitmap-write.c:hashwrite_be64
Unexecuted instantiation: pack-bitmap.c:hashwrite_be64
Unexecuted instantiation: pack-check.c:hashwrite_be64
Unexecuted instantiation: pack-revindex.c:hashwrite_be64
Unexecuted instantiation: pack-write.c:hashwrite_be64
Unexecuted instantiation: packfile.c:hashwrite_be64
Unexecuted instantiation: pseudo-merge.c:hashwrite_be64
Unexecuted instantiation: reachable.c:hashwrite_be64
Unexecuted instantiation: read-cache.c:hashwrite_be64
Unexecuted instantiation: chunk-format.c:hashwrite_be64
95
96
#endif