static int load_alternates(git_odb *odb, const char *objects_dir) { char alternates_path[GIT_PATH_MAX]; char alternate[GIT_PATH_MAX]; char *buffer; gitfo_buf alternates_buf = GITFO_BUF_INIT; int error; git__joinpath(alternates_path, objects_dir, GIT_ALTERNATES_FILE); if (gitfo_exists(alternates_path) < GIT_SUCCESS) return GIT_SUCCESS; if (gitfo_read_file(&alternates_buf, alternates_path) < GIT_SUCCESS) return GIT_EOSERR; buffer = (char *)alternates_buf.data; error = GIT_SUCCESS; /* add each alternate as a new backend; one alternate per line */ while ((error == GIT_SUCCESS) && (buffer = git__strtok(alternate, buffer, "\r\n")) != NULL) error = add_default_backends(odb, alternate, 1); gitfo_free_buf(&alternates_buf); return error; }
int git_blob_set_rawcontent_fromfile(git_blob *blob, const char *filename) { assert(blob && filename); blob->object.modified = 1; if (blob->content.data != NULL) gitfo_free_buf(&blob->content); return gitfo_read_file(&blob->content, filename); }
int git_index_read(git_index *index) { struct stat indexst; int error = 0; assert(index->index_file_path); if (!index->on_disk || gitfo_exists(index->index_file_path) < 0) { git_index_clear(index); index->on_disk = 0; return 0; } if (gitfo_stat(index->index_file_path, &indexst) < 0) return GIT_EOSERR; if (!S_ISREG(indexst.st_mode)) return GIT_ENOTFOUND; if (indexst.st_mtime != index->last_modified) { gitfo_buf buffer; if (gitfo_read_file(&buffer, index->index_file_path) < 0) return GIT_EOSERR; git_index_clear(index); error = git_index__parse(index, buffer.data, buffer.len); if (error == 0) index->last_modified = indexst.st_mtime; gitfo_free_buf(&buffer); } return error; }