MCPcopy Create free account
hub / github.com/git/git / write_chunkfile

Function write_chunkfile

chunk-format.c:65–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65int write_chunkfile(struct chunkfile *cf, void *data)
66{
67 int i, result = 0;
68 uint64_t cur_offset = hashfile_total(cf->f);
69
70 trace2_region_enter("chunkfile", "write", the_repository);
71
72 /* Add the table of contents to the current offset */
73 cur_offset += (cf->chunks_nr + 1) * CHUNK_TOC_ENTRY_SIZE;
74
75 for (i = 0; i < cf->chunks_nr; i++) {
76 hashwrite_be32(cf->f, cf->chunks[i].id);
77 hashwrite_be64(cf->f, cur_offset);
78
79 cur_offset += cf->chunks[i].size;
80 }
81
82 /* Trailing entry marks the end of the chunks */
83 hashwrite_be32(cf->f, 0);
84 hashwrite_be64(cf->f, cur_offset);
85
86 for (i = 0; i < cf->chunks_nr; i++) {
87 off_t start_offset = hashfile_total(cf->f);
88 result = cf->chunks[i].write_fn(cf->f, data);
89
90 if (result)
91 goto cleanup;
92
93 if (hashfile_total(cf->f) - start_offset != cf->chunks[i].size)
94 BUG("expected to write %"PRId64" bytes to chunk %"PRIx32", but wrote %"PRId64" instead",
95 cf->chunks[i].size, cf->chunks[i].id,
96 hashfile_total(cf->f) - start_offset);
97 }
98
99cleanup:
100 trace2_region_leave("chunkfile", "write", the_repository);
101 return result;
102}
103
104int read_table_of_contents(struct chunkfile *cf,
105 const unsigned char *mfile,

Callers 2

write_commit_graph_fileFunction · 0.85
write_midx_internalFunction · 0.85

Calls 3

hashfile_totalFunction · 0.85
hashwrite_be32Function · 0.85
hashwrite_be64Function · 0.85

Tested by

no test coverage detected