static int index_reader_read( git_buf *out, git_oid *out_id, git_filemode_t *out_filemode, git_reader *_reader, const char *filename) { index_reader *reader = (index_reader *)_reader; const git_index_entry *entry; git_blob *blob; int error; if ((entry = git_index_get_bypath(reader->index, filename, 0)) == NULL) return GIT_ENOTFOUND; if ((error = git_blob_lookup(&blob, reader->repo, &entry->id)) < 0) goto done; if (out_id) git_oid_cpy(out_id, &entry->id); if (out_filemode) *out_filemode = entry->mode; error = git_blob__getbuf(out, blob); done: git_blob_free(blob); return error; }
static int blob_content_to_file( git_blob *blob, const char *path, mode_t entry_filemode, git_checkout_opts *opts) { int error = -1, nb_filters = 0; mode_t file_mode = opts->file_mode; bool dont_free_filtered = false; git_buf unfiltered = GIT_BUF_INIT, filtered = GIT_BUF_INIT; git_vector filters = GIT_VECTOR_INIT; if (opts->disable_filters || (nb_filters = git_filters_load( &filters, git_object_owner((git_object *)blob), path, GIT_FILTER_TO_WORKTREE)) == 0) { /* Create a fake git_buf from the blob raw data... */ filtered.ptr = blob->odb_object->raw.data; filtered.size = blob->odb_object->raw.len; /* ... and make sure it doesn't get unexpectedly freed */ dont_free_filtered = true; } if (nb_filters < 0) return nb_filters; if (nb_filters > 0) { if ((error = git_blob__getbuf(&unfiltered, blob)) < 0) goto cleanup; if ((error = git_filters_apply(&filtered, &unfiltered, &filters)) < 0) goto cleanup; } /* Allow overriding of file mode */ if (!file_mode) file_mode = entry_filemode; error = buffer_to_file(&filtered, path, opts->dir_mode, opts->file_open_flags, file_mode); cleanup: git_filters_free(&filters); git_buf_free(&unfiltered); if (!dont_free_filtered) git_buf_free(&filtered); return error; }
static int blob_content_to_link(git_blob *blob, const char *path, bool can_symlink) { git_buf linktarget = GIT_BUF_INIT; int error; if ((error = git_blob__getbuf(&linktarget, blob)) < 0) return error; if (can_symlink) error = p_symlink(git_buf_cstr(&linktarget), path); else error = git_futils_fake_symlink(git_buf_cstr(&linktarget), path); git_buf_free(&linktarget); return error; }
void test_object_blob_filter__stats(void) { int i; git_blob *blob; git_buf buf = GIT_BUF_INIT; git_buf_text_stats stats; for (i = 0; i < CRLF_NUM_TEST_OBJECTS; i++) { cl_git_pass(git_blob_lookup(&blob, g_repo, &g_crlf_oids[i])); cl_git_pass(git_blob__getbuf(&buf, blob)); git_buf_text_gather_stats(&stats, &buf, false); cl_assert_equal_i( 0, memcmp(&g_crlf_filtered_stats[i], &stats, sizeof(stats))); git_blob_free(blob); } git_buf_free(&buf); }