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

Function safe_append

sequencer.c:3907–3942  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3905}
3906
3907__attribute__((format (printf, 2, 3)))
3908static int safe_append(const char *filename, const char *fmt, ...)
3909{
3910 va_list ap;
3911 struct lock_file lock = LOCK_INIT;
3912 int fd = hold_lock_file_for_update(&lock, filename,
3913 LOCK_REPORT_ON_ERROR);
3914 struct strbuf buf = STRBUF_INIT;
3915
3916 if (fd < 0)
3917 return -1;
3918
3919 if (strbuf_read_file(&buf, filename, 0) < 0 && errno != ENOENT) {
3920 error_errno(_("could not read '%s'"), filename);
3921 rollback_lock_file(&lock);
3922 return -1;
3923 }
3924 strbuf_complete(&buf, '\n');
3925 va_start(ap, fmt);
3926 strbuf_vaddf(&buf, fmt, ap);
3927 va_end(ap);
3928
3929 if (write_in_full(fd, buf.buf, buf.len) < 0) {
3930 error_errno(_("could not write to '%s'"), filename);
3931 strbuf_release(&buf);
3932 rollback_lock_file(&lock);
3933 return -1;
3934 }
3935 if (commit_lock_file(&lock) < 0) {
3936 strbuf_release(&buf);
3937 return error(_("failed to finalize '%s'"), filename);
3938 }
3939
3940 strbuf_release(&buf);
3941 return 0;
3942}
3943
3944static int do_label(struct repository *r, const char *name, int len)
3945{

Callers 1

do_labelFunction · 0.85

Calls 10

strbuf_read_fileFunction · 0.85
error_errnoFunction · 0.85
rollback_lock_fileFunction · 0.85
strbuf_completeFunction · 0.85
strbuf_vaddfFunction · 0.85
write_in_fullFunction · 0.85
strbuf_releaseFunction · 0.85
commit_lock_fileFunction · 0.85
errorFunction · 0.85

Tested by

no test coverage detected