Coverage Report

Created: 2026-03-31 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/git/csum-file.h
Line
Count
Source
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
  struct 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
  const struct git_hash_algo *algop;
24
25
  /**
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.
29
   */
30
  int skip_hash;
31
};
32
33
/* Checkpoint */
34
struct hashfile_checkpoint {
35
  off_t offset;
36
  struct git_hash_ctx ctx;
37
};
38
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 *);
42
43
/* finalize_hashfile flags */
44
0
#define CSUM_CLOSE    1
45
0
#define CSUM_FSYNC    2
46
0
#define CSUM_HASH_IN_STREAM 4
47
48
struct hashfd_options {
49
  /*
50
   * Throughput progress that counts the number of bytes that have been
51
   * hashed.
52
   */
53
  struct progress *progress;
54
55
  /* The length of the buffer that shall be used read read data. */
56
  size_t buffer_len;
57
};
58
59
struct hashfile *hashfd_ext(const struct git_hash_algo *algop,
60
          int fd, const char *name,
61
          const struct hashfd_options *opts);
62
struct hashfile *hashfd(const struct git_hash_algo *algop,
63
      int fd, const char *name);
64
struct hashfile *hashfd_check(const struct git_hash_algo *algop,
65
            const char *name);
66
67
/*
68
 * Free the hashfile without flushing its contents to disk. This only
69
 * needs to be called when not calling `finalize_hashfile()`.
70
 */
71
void free_hashfile(struct hashfile *f);
72
73
/*
74
 * Finalize the hashfile by flushing data to disk and free'ing it.
75
 */
76
int finalize_hashfile(struct hashfile *, unsigned char *, enum fsync_component, unsigned int);
77
void discard_hashfile(struct hashfile *);
78
void hashwrite(struct hashfile *, const void *, uint32_t);
79
void hashflush(struct hashfile *f);
80
void crc32_begin(struct hashfile *);
81
uint32_t crc32_end(struct hashfile *);
82
83
/* Verify checksum validity while reading. Returns non-zero on success. */
84
int hashfile_checksum_valid(const struct git_hash_algo *algop,
85
          const unsigned char *data, size_t len);
86
87
/*
88
 * Returns the total number of bytes fed to the hashfile so far (including ones
89
 * that have not been written out to the descriptor yet).
90
 */
91
static inline off_t hashfile_total(struct hashfile *f)
92
0
{
93
0
  return f->total + f->offset;
94
0
}
Unexecuted instantiation: object-file.c:hashfile_total
Unexecuted instantiation: pack-write.c:hashfile_total
Unexecuted instantiation: packfile.c:hashfile_total
Unexecuted instantiation: read-cache.c:hashfile_total
Unexecuted instantiation: repo-settings.c:hashfile_total
Unexecuted instantiation: chunk-format.c:hashfile_total
Unexecuted instantiation: commit-graph.c:hashfile_total
Unexecuted instantiation: csum-file.c:hashfile_total
Unexecuted instantiation: fetch-pack.c:hashfile_total
Unexecuted instantiation: midx.c:hashfile_total
Unexecuted instantiation: pack-check.c:hashfile_total
Unexecuted instantiation: pack-revindex.c:hashfile_total
95
96
static inline void hashwrite_u8(struct hashfile *f, uint8_t data)
97
0
{
98
0
  hashwrite(f, &data, sizeof(data));
99
0
}
Unexecuted instantiation: object-file.c:hashwrite_u8
Unexecuted instantiation: pack-write.c:hashwrite_u8
Unexecuted instantiation: packfile.c:hashwrite_u8
Unexecuted instantiation: read-cache.c:hashwrite_u8
Unexecuted instantiation: repo-settings.c:hashwrite_u8
Unexecuted instantiation: chunk-format.c:hashwrite_u8
Unexecuted instantiation: commit-graph.c:hashwrite_u8
Unexecuted instantiation: csum-file.c:hashwrite_u8
Unexecuted instantiation: fetch-pack.c:hashwrite_u8
Unexecuted instantiation: midx.c:hashwrite_u8
Unexecuted instantiation: pack-check.c:hashwrite_u8
Unexecuted instantiation: pack-revindex.c:hashwrite_u8
100
101
static inline void hashwrite_be32(struct hashfile *f, uint32_t data)
102
0
{
103
0
  data = htonl(data);
104
0
  hashwrite(f, &data, sizeof(data));
105
0
}
Unexecuted instantiation: object-file.c:hashwrite_be32
Unexecuted instantiation: pack-write.c:hashwrite_be32
Unexecuted instantiation: packfile.c:hashwrite_be32
Unexecuted instantiation: read-cache.c:hashwrite_be32
Unexecuted instantiation: repo-settings.c:hashwrite_be32
Unexecuted instantiation: chunk-format.c:hashwrite_be32
Unexecuted instantiation: commit-graph.c:hashwrite_be32
Unexecuted instantiation: csum-file.c:hashwrite_be32
Unexecuted instantiation: fetch-pack.c:hashwrite_be32
Unexecuted instantiation: midx.c:hashwrite_be32
Unexecuted instantiation: pack-check.c:hashwrite_be32
Unexecuted instantiation: pack-revindex.c:hashwrite_be32
106
107
static inline size_t hashwrite_be64(struct hashfile *f, uint64_t data)
108
0
{
109
0
  data = htonll(data);
110
0
  hashwrite(f, &data, sizeof(data));
111
0
  return sizeof(data);
112
0
}
Unexecuted instantiation: object-file.c:hashwrite_be64
Unexecuted instantiation: pack-write.c:hashwrite_be64
Unexecuted instantiation: packfile.c:hashwrite_be64
Unexecuted instantiation: read-cache.c:hashwrite_be64
Unexecuted instantiation: repo-settings.c:hashwrite_be64
Unexecuted instantiation: chunk-format.c:hashwrite_be64
Unexecuted instantiation: commit-graph.c:hashwrite_be64
Unexecuted instantiation: csum-file.c:hashwrite_be64
Unexecuted instantiation: fetch-pack.c:hashwrite_be64
Unexecuted instantiation: midx.c:hashwrite_be64
Unexecuted instantiation: pack-check.c:hashwrite_be64
Unexecuted instantiation: pack-revindex.c:hashwrite_be64
113
114
#endif