MCPcopy Index your code
hub / github.com/git/git / write_commit_graph_file

Function write_commit_graph_file

commit-graph.c:2094–2278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2092}
2093
2094static int write_commit_graph_file(struct write_commit_graph_context *ctx)
2095{
2096 uint32_t i;
2097 struct hashfile *f;
2098 struct tempfile *graph_layer; /* when ctx->split is non-zero */
2099 struct lock_file lk = LOCK_INIT;
2100 const unsigned hashsz = ctx->r->hash_algo->rawsz;
2101 struct strbuf progress_title = STRBUF_INIT;
2102 struct chunkfile *cf;
2103 unsigned char file_hash[GIT_MAX_RAWSZ];
2104
2105 if (ctx->split) {
2106 struct strbuf tmp_file = STRBUF_INIT;
2107
2108 strbuf_addf(&tmp_file,
2109 "%s/info/commit-graphs/tmp_graph_XXXXXX",
2110 ctx->odb_source->path);
2111 ctx->graph_name = strbuf_detach(&tmp_file, NULL);
2112 } else {
2113 ctx->graph_name = get_commit_graph_filename(ctx->odb_source);
2114 }
2115
2116 if (safe_create_leading_directories(ctx->r, ctx->graph_name)) {
2117 error(_("unable to create leading directories of %s"),
2118 ctx->graph_name);
2119 return -1;
2120 }
2121
2122 if (ctx->split) {
2123 char *lock_name = get_commit_graph_chain_filename(ctx->odb_source);
2124
2125 hold_lock_file_for_update_mode(&lk, lock_name,
2126 LOCK_DIE_ON_ERROR, 0444);
2127 free(lock_name);
2128
2129 graph_layer = mks_tempfile_m(ctx->graph_name, 0444);
2130 if (!graph_layer) {
2131 error(_("unable to create temporary graph layer"));
2132 return -1;
2133 }
2134
2135 if (adjust_shared_perm(ctx->r, get_tempfile_path(graph_layer))) {
2136 error(_("unable to adjust shared permissions for '%s'"),
2137 get_tempfile_path(graph_layer));
2138 return -1;
2139 }
2140
2141 f = hashfd(ctx->r->hash_algo,
2142 get_tempfile_fd(graph_layer), get_tempfile_path(graph_layer));
2143 } else {
2144 hold_lock_file_for_update_mode(&lk, ctx->graph_name,
2145 LOCK_DIE_ON_ERROR, 0444);
2146 f = hashfd(ctx->r->hash_algo,
2147 get_lock_file_fd(&lk), get_lock_file_path(&lk));
2148 }
2149
2150 cf = init_chunkfile(f);
2151

Callers 1

write_commit_graphFunction · 0.85

Calls 15

strbuf_addfFunction · 0.85
strbuf_detachFunction · 0.85
errorFunction · 0.85
mks_tempfile_mFunction · 0.85
adjust_shared_permFunction · 0.85
get_tempfile_pathFunction · 0.85
hashfdFunction · 0.85
get_tempfile_fdFunction · 0.85

Tested by

no test coverage detected