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

Function repo_write_loose_object_map

loose.c:128–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126}
127
128int repo_write_loose_object_map(struct repository *repo)
129{
130 struct odb_source_files *files = odb_source_files_downcast(repo->objects->sources);
131 kh_oid_map_t *map = files->loose->map->to_compat;
132 struct lock_file lock;
133 int fd;
134 khiter_t iter;
135 struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
136
137 if (!should_use_loose_object_map(repo))
138 return 0;
139
140 repo_common_path_replace(repo, &path, "objects/loose-object-idx");
141 fd = hold_lock_file_for_update_timeout(&lock, path.buf, LOCK_DIE_ON_ERROR, -1);
142 iter = kh_begin(map);
143 if (write_in_full(fd, loose_object_header, strlen(loose_object_header)) < 0)
144 goto errout;
145
146 for (; iter != kh_end(map); iter++) {
147 if (kh_exist(map, iter)) {
148 if (oideq(&kh_key(map, iter), repo->hash_algo->empty_tree) ||
149 oideq(&kh_key(map, iter), repo->hash_algo->empty_blob))
150 continue;
151 strbuf_addf(&buf, "%s %s\n", oid_to_hex(&kh_key(map, iter)), oid_to_hex(kh_value(map, iter)));
152 if (write_in_full(fd, buf.buf, buf.len) < 0)
153 goto errout;
154 strbuf_reset(&buf);
155 }
156 }
157 strbuf_release(&buf);
158 if (commit_lock_file(&lock) < 0) {
159 error_errno(_("could not write loose object index %s"), path.buf);
160 strbuf_release(&path);
161 return -1;
162 }
163 strbuf_release(&path);
164 return 0;
165errout:
166 rollback_lock_file(&lock);
167 strbuf_release(&buf);
168 error_errno(_("failed to write loose object index %s"), path.buf);
169 strbuf_release(&path);
170 return -1;
171}
172
173static int write_one_object(struct odb_source_loose *loose,
174 const struct object_id *oid,

Callers

nothing calls this directly

Calls 12

repo_common_path_replaceFunction · 0.85
write_in_fullFunction · 0.85
oideqFunction · 0.85
strbuf_addfFunction · 0.85
oid_to_hexFunction · 0.85
strbuf_releaseFunction · 0.85
commit_lock_fileFunction · 0.85
error_errnoFunction · 0.85
rollback_lock_fileFunction · 0.85

Tested by

no test coverage detected