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

Function write_one_object

loose.c:173–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171}
172
173static int write_one_object(struct odb_source_loose *loose,
174 const struct object_id *oid,
175 const struct object_id *compat_oid)
176{
177 struct lock_file lock;
178 int fd;
179 struct stat st;
180 struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
181
182 strbuf_addf(&path, "%s/loose-object-idx", loose->base.path);
183 hold_lock_file_for_update_timeout(&lock, path.buf, LOCK_DIE_ON_ERROR, -1);
184
185 fd = open(path.buf, O_WRONLY | O_CREAT | O_APPEND, 0666);
186 if (fd < 0)
187 goto errout;
188 if (fstat(fd, &st) < 0)
189 goto errout;
190 if (!st.st_size && write_in_full(fd, loose_object_header, strlen(loose_object_header)) < 0)
191 goto errout;
192
193 strbuf_addf(&buf, "%s %s\n", oid_to_hex(oid), oid_to_hex(compat_oid));
194 if (write_in_full(fd, buf.buf, buf.len) < 0)
195 goto errout;
196 if (close(fd))
197 goto errout;
198 adjust_shared_perm(loose->base.odb->repo, path.buf);
199 rollback_lock_file(&lock);
200 strbuf_release(&buf);
201 strbuf_release(&path);
202 return 0;
203errout:
204 error_errno(_("failed to write loose object index %s"), path.buf);
205 close(fd);
206 rollback_lock_file(&lock);
207 strbuf_release(&buf);
208 strbuf_release(&path);
209 return -1;
210}
211
212int repo_add_loose_object_map(struct odb_source_loose *loose,
213 const struct object_id *oid,

Callers 1

Calls 8

strbuf_addfFunction · 0.85
write_in_fullFunction · 0.85
oid_to_hexFunction · 0.85
adjust_shared_permFunction · 0.85
rollback_lock_fileFunction · 0.85
strbuf_releaseFunction · 0.85
error_errnoFunction · 0.85

Tested by

no test coverage detected