int git_branch_create( git_oid *oid_out, git_repository *repo, const char *branch_name, const git_object *target, int force) { git_otype target_type = GIT_OBJ_BAD; git_object *commit = NULL; git_reference *branch = NULL; git_buf canonical_branch_name = GIT_BUF_INIT; int error = -1; assert(repo && branch_name && target && oid_out); if (git_object_owner(target) != repo) return create_error_invalid("The given target does not belong to this repository"); target_type = git_object_type(target); switch (target_type) { case GIT_OBJ_TAG: if (git_tag_peel(&commit, (git_tag *)target) < 0) goto cleanup; if (git_object_type(commit) != GIT_OBJ_COMMIT) { create_error_invalid("The given target does not resolve to a commit"); goto cleanup; } break; case GIT_OBJ_COMMIT: commit = (git_object *)target; break; default: return create_error_invalid("Only git_tag and git_commit objects are valid targets."); } if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0) goto cleanup; if (git_reference_create_oid(&branch, repo, git_buf_cstr(&canonical_branch_name), git_object_id(commit), force) < 0) goto cleanup; git_oid_cpy(oid_out, git_reference_oid(branch)); error = 0; cleanup: if (target_type == GIT_OBJ_TAG) git_object_free(commit); git_reference_free(branch); git_buf_free(&canonical_branch_name); return error; }
int git_object_peel( git_object **peeled, const git_object *object, git_otype target_type) { git_object *source, *deref = NULL; int error; assert(object && peeled); assert(target_type == GIT_OBJ_TAG || target_type == GIT_OBJ_COMMIT || target_type == GIT_OBJ_TREE || target_type == GIT_OBJ_BLOB || target_type == GIT_OBJ_ANY); if ((error = check_type_combination(git_object_type(object), target_type)) < 0) return peel_error(error, git_object_id(object), target_type); if (git_object_type(object) == target_type) return git_object_dup(peeled, (git_object *)object); source = (git_object *)object; while (!(error = dereference_object(&deref, source))) { if (source != object) git_object_free(source); if (git_object_type(deref) == target_type) { *peeled = deref; return 0; } if (target_type == GIT_OBJ_ANY && git_object_type(deref) != git_object_type(object)) { *peeled = deref; return 0; } source = deref; deref = NULL; } if (source != object) git_object_free(source); git_object_free(deref); if (error) error = peel_error(error, git_object_id(object), target_type); return error; }
int git_object_peel( git_object **peeled, const git_object *object, git_otype target_type) { git_object *source, *deref = NULL; int error; if (target_type != GIT_OBJ_TAG && target_type != GIT_OBJ_COMMIT && target_type != GIT_OBJ_TREE && target_type != GIT_OBJ_BLOB && target_type != GIT_OBJ_ANY) return GIT_EINVALIDSPEC; assert(object && peeled); if (git_object_type(object) == target_type) return git_object__dup(peeled, (git_object *)object); source = (git_object *)object; while (!(error = dereference_object(&deref, source))) { if (source != object) git_object_free(source); if (git_object_type(deref) == target_type) { *peeled = deref; return 0; } if (target_type == GIT_OBJ_ANY && git_object_type(deref) != git_object_type(object)) { *peeled = deref; return 0; } source = deref; deref = NULL; } if (source != object) git_object_free(source); git_object_free(deref); if (error) error = peel_error(error, git_object_id(object), target_type); return error; }
void test_object_cache__cache_everything(void) { int i, start; git_oid oid; git_odb_object *odb_obj; git_object *obj; git_odb *odb; git_libgit2_opts( GIT_OPT_SET_CACHE_OBJECT_LIMIT, (int)GIT_OBJ_BLOB, (size_t)32767); cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git"))); cl_git_pass(git_repository_odb(&odb, g_repo)); start = (int)git_cache_size(&g_repo->objects); for (i = 0; g_data[i].sha != NULL; ++i) { int count = (int)git_cache_size(&g_repo->objects); cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha)); /* alternate between loading raw and parsed objects */ if ((i & 1) == 0) { cl_git_pass(git_odb_read(&odb_obj, odb, &oid)); cl_assert(g_data[i].type == git_odb_object_type(odb_obj)); git_odb_object_free(odb_obj); } else { cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); cl_assert(g_data[i].type == git_object_type(obj)); git_object_free(obj); } cl_assert_equal_i(count + 1, (int)git_cache_size(&g_repo->objects)); } cl_assert_equal_i(i, (int)git_cache_size(&g_repo->objects) - start); git_odb_free(odb); for (i = 0; g_data[i].sha != NULL; ++i) { int count = (int)git_cache_size(&g_repo->objects); cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha)); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); cl_assert(g_data[i].type == git_object_type(obj)); git_object_free(obj); cl_assert_equal_i(count, (int)git_cache_size(&g_repo->objects)); } }
static int show_ref(git_reference *ref, void *data) { git_repository *repo = data; git_reference *resolved = NULL; char hex[GIT_OID_HEXSZ+1]; const git_oid *oid; git_object *obj; if (git_reference_type(ref) == GIT_REF_SYMBOLIC) check_lg2(git_reference_resolve(&resolved, ref), "Unable to resolve symbolic reference", git_reference_name(ref)); oid = git_reference_target(resolved ? resolved : ref); git_oid_fmt(hex, oid); hex[GIT_OID_HEXSZ] = 0; check_lg2(git_object_lookup(&obj, repo, oid, GIT_OBJ_ANY), "Unable to lookup object", hex); printf("%s %-6s\t%s\n", hex, git_object_type2string(git_object_type(obj)), git_reference_name(ref)); if (resolved) git_reference_free(resolved); return 0; }
void test_refs_read__nested_symbolic(void) { // lookup a nested symbolic reference git_reference *reference, *resolved_ref; git_object *object; git_oid id; cl_git_pass(git_reference_lookup(&reference, g_repo, head_tracker_sym_ref_name)); cl_assert(git_reference_type(reference) & GIT_REF_SYMBOLIC); cl_assert(git_reference_is_packed(reference) == 0); cl_assert_equal_s(reference->name, head_tracker_sym_ref_name); cl_git_pass(git_reference_resolve(&resolved_ref, reference)); cl_assert(git_reference_type(resolved_ref) == GIT_REF_OID); cl_git_pass(git_object_lookup(&object, g_repo, git_reference_target(resolved_ref), GIT_OBJ_ANY)); cl_assert(object != NULL); cl_assert(git_object_type(object) == GIT_OBJ_COMMIT); git_oid_fromstr(&id, current_master_tip); cl_assert(git_oid_cmp(&id, git_object_id(object)) == 0); git_object_free(object); git_reference_free(reference); git_reference_free(resolved_ref); }
/* * call-seq: * tag.target -> git_object */ static VALUE rb_git_tag_target(VALUE self) { git_reference *ref, *resolved_ref; git_repository *repo; git_object *target; int error; VALUE rb_repo = rugged_owner(self); rugged_check_repo(rb_repo); Data_Get_Struct(self, git_reference, ref); Data_Get_Struct(rb_repo, git_repository, repo); error = git_reference_resolve(&resolved_ref, ref); rugged_exception_check(error); error = git_object_lookup(&target, repo, git_reference_target(resolved_ref), GIT_OBJ_ANY); git_reference_free(resolved_ref); rugged_exception_check(error); if (git_object_type(target) == GIT_OBJ_TAG) { git_object *annotation_target; error = git_tag_target(&annotation_target, (git_tag *)target); git_object_free(target); rugged_exception_check(error); return rugged_object_new(rb_repo, annotation_target); } else { return rugged_object_new(rb_repo, target); } }
static int write_tag_annotation( git_oid *oid, git_repository *repo, const char *tag_name, const git_object *target, const git_signature *tagger, const char *message) { git_buf tag = GIT_BUF_INIT; git_odb *odb; git_oid__writebuf(&tag, "object ", git_object_id(target)); git_buf_printf(&tag, "type %s\n", git_object_type2string(git_object_type(target))); git_buf_printf(&tag, "tag %s\n", tag_name); git_signature__writebuf(&tag, "tagger ", tagger); git_buf_putc(&tag, '\n'); if (git_buf_puts(&tag, message) < 0) goto on_error; if (git_repository_odb__weakptr(&odb, repo) < 0) goto on_error; if (git_odb_write(oid, odb, tag.ptr, tag.size, GIT_OBJ_TAG) < 0) goto on_error; git_buf_free(&tag); return 0; on_error: git_buf_free(&tag); giterr_set(GITERR_OBJECT, "Failed to create tag annotation."); return -1; }
GIT_INLINE(jobject) git_java_object_init(JNIEnv *env, jobject repo_java, jobject oid_java, git_object *object) { jclass object_class; jmethodID object_initmethod; git_otype type; const char *object_classname; switch((type = git_object_type(object))) { case GIT_OBJ_COMMIT: object_classname = GIT_JAVA_CLASS_COMMIT; break; case GIT_OBJ_TREE: object_classname = GIT_JAVA_CLASS_TREE; break; case GIT_OBJ_BLOB: object_classname = GIT_JAVA_CLASS_BLOB; break; default: git_java_exception_throw(env, "unknown object type: %d", type); return NULL; } if ((object_class = (*env)->FindClass(env, object_classname)) == NULL || (object_initmethod = (*env)->GetMethodID(env, object_class, "<init>", "(Lorg/libgit2/jagged/Repository;Lorg/libgit2/jagged/ObjectId;)V")) == NULL) return NULL; return (*env)->NewObject(env, object_class, object_initmethod, repo_java, oid_java); }
PyObject * wrap_object(git_object *c_object, Repository *repo) { Object *py_obj = NULL; switch (git_object_type(c_object)) { case GIT_OBJ_COMMIT: py_obj = PyObject_New(Object, &CommitType); break; case GIT_OBJ_TREE: py_obj = PyObject_New(Object, &TreeType); break; case GIT_OBJ_BLOB: py_obj = PyObject_New(Object, &BlobType); break; case GIT_OBJ_TAG: py_obj = PyObject_New(Object, &TagType); break; default: assert(0); } if (py_obj) { py_obj->obj = c_object; if (repo) { py_obj->repo = repo; Py_INCREF(repo); } } return (PyObject *)py_obj; }
static int dereference_to_non_tag(git_object **out, git_object *obj) { if (git_object_type(obj) == GIT_OBJ_TAG) return git_tag_peel(out, (git_tag *)obj); return git_object_dup(out, obj); }
void test_refs_read__loose_tag(void) { // lookup a loose tag reference git_reference *reference; git_object *object; git_buf ref_name_from_tag_name = GIT_BUF_INIT; cl_git_pass(git_reference_lookup(&reference, g_repo, loose_tag_ref_name)); cl_assert(git_reference_type(reference) & GIT_REF_OID); cl_assert(git_reference_is_packed(reference) == 0); cl_assert_equal_s(reference->name, loose_tag_ref_name); cl_git_pass(git_object_lookup(&object, g_repo, git_reference_target(reference), GIT_OBJ_ANY)); cl_assert(object != NULL); cl_assert(git_object_type(object) == GIT_OBJ_TAG); /* Ensure the name of the tag matches the name of the reference */ cl_git_pass(git_buf_joinpath(&ref_name_from_tag_name, GIT_REFS_TAGS_DIR, git_tag_name((git_tag *)object))); cl_assert_equal_s(ref_name_from_tag_name.ptr, loose_tag_ref_name); git_buf_free(&ref_name_from_tag_name); git_object_free(object); git_reference_free(reference); }
static int read_file_git(const char *repo_path, const char *name, void **out, size_t *outlen) { int ret, retcode = -1; git_repository *repo; ret = git_repository_open_bare(&repo, repo_path); if(check_lg2(ret, "opening repo")) goto out; git_object *master; ret = git_revparse_single(&master, repo, "master"); if(check_lg2(ret, "getting master branch")) goto out_repo; if(git_object_type(master) != GIT_OBJ_COMMIT) { debug("master is not a commit"); goto out_master; } git_tree *tree; ret = git_commit_tree(&tree, (git_commit*)master); if(check_lg2(ret, "getting tree from commit")) goto out_master; const git_tree_entry *entry = git_tree_entry_byname(tree, name); if(!entry) { debug("entry %s not found", name); goto out_tree; } if(git_tree_entry_type(entry) != GIT_OBJ_BLOB) { debug("entry is not a blob"); goto out_tree; } git_object *file; ret = git_tree_entry_to_object(&file, repo, entry); if(check_lg2(ret, "getting file from tree entry")) goto out_tree; const void *data = git_blob_rawcontent((git_blob*)file); *outlen = git_blob_rawsize((git_blob*)file); *out = malloc(*outlen); memcpy(*out, data, *outlen); retcode = 0; git_object_free(file); out_tree: git_tree_free(tree); out_master: git_object_free(master); out_repo: git_repository_free(repo); out: return retcode; }
git_tree *resolve_commit_oid_to_tree( git_repository *repo, const char *partial_oid) { size_t len = strlen(partial_oid); git_oid oid; git_object *obj = NULL; git_tree *tree = NULL; if (git_oid_fromstrn(&oid, partial_oid, len) == 0) git_object_lookup_prefix(&obj, repo, &oid, len, GIT_OBJ_ANY); cl_assert(obj); if (git_object_type(obj) == GIT_OBJ_TREE) return (git_tree *)obj; cl_assert(git_object_type(obj) == GIT_OBJ_COMMIT); cl_git_pass(git_commit_tree(&tree, (git_commit *)obj)); git_object_free(obj); return tree; }
static void assert_merge_and_or_remote_key_missing(git_repository *repository, const git_commit *target, const char *entry_name) { git_reference *branch; cl_assert_equal_i(GIT_OBJ_COMMIT, git_object_type((git_object*)target)); cl_git_pass(git_branch_create(&branch, repository, entry_name, (git_commit*)target, 0)); cl_assert_equal_i(GIT_ENOTFOUND, git_branch_tracking(&tracking, branch)); git_reference_free(branch); }
void test_repo_head__set_head_detached_Detaches_HEAD_and_make_it_point_to_the_peeled_commit(void) { git_object *tag; cl_git_pass(git_revparse_single(&tag, repo, "tags/test")); cl_assert_equal_i(GIT_OBJECT_TAG, git_object_type(tag)); cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag))); assert_head_is_correctly_detached(); git_object_free(tag); }
static void *cache_parsed(void *arg) { int i; git_oid oid; git_object *obj; for (i = ((int *)arg)[1]; g_data[i].sha != NULL; i += 2) { cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha)); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); cl_assert(g_data[i].type == git_object_type(obj)); git_object_free(obj); } for (i = 0; i < ((int *)arg)[1]; i += 2) { cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha)); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); cl_assert(g_data[i].type == git_object_type(obj)); git_object_free(obj); } return arg; }
char *gbr_ctime_object(char *buf, int sz, git_object *object) { git_time_t ts; switch (git_object_type(object)) { case GIT_OBJ_COMMIT: ts = git_commit_time((git_commit *)object); break; default: ts = 0; break; } return ctime_ts(buf, sz, ts); }
static int mne_git_get_tag_commit_oid(const git_oid **tag_commit_oid, git_tag* tag) { git_object *tag_object; int err = git_tag_peel(&tag_object, tag); mne_check_error("git_tag_peel()", err, __FILE__, __LINE__); const git_otype type = git_object_type(tag_object); if (type != GIT_OBJ_COMMIT) return MNE_GIT_TARGET_NOT_COMMIT; *tag_commit_oid = git_object_id(tag_object); assert(tag_commit_oid != NULL); git_object_free(tag_object); return MNE_GIT_OK; }
static void assert_object_oid(const char* revision, const char* expected_oid, git_otype type) { int result; git_object *obj; result = git_revparse_single(&obj, repo, revision); if (!expected_oid) { cl_assert_equal_i(GIT_ENOTFOUND, result); return; } else cl_assert_equal_i(0, result); cl_git_pass(git_oid_streq(git_object_id(obj), expected_oid)); cl_assert_equal_i(type, git_object_type(obj)); git_object_free(obj); }
int git_reference_peel( git_object **peeled, git_reference *ref, git_otype target_type) { git_reference *resolved = NULL; git_object *target = NULL; int error; assert(ref); if (ref->type == GIT_REF_OID) { resolved = ref; } else { if ((error = git_reference_resolve(&resolved, ref)) < 0) return peel_error(error, ref, "Cannot resolve reference"); } if (!git_oid_iszero(&resolved->peel)) { error = git_object_lookup(&target, git_reference_owner(ref), &resolved->peel, GIT_OBJ_ANY); } else { error = git_object_lookup(&target, git_reference_owner(ref), &resolved->target.oid, GIT_OBJ_ANY); } if (error < 0) { peel_error(error, ref, "Cannot retrieve reference target"); goto cleanup; } if (target_type == GIT_OBJ_ANY && git_object_type(target) != GIT_OBJ_TAG) error = git_object_dup(peeled, target); else error = git_object_peel(peeled, target, target_type); cleanup: git_object_free(target); if (resolved != ref) git_reference_free(resolved); return error; }
static int dereference_object(git_object **dereferenced, git_object *obj) { git_otype type = git_object_type(obj); switch (type) { case GIT_OBJ_COMMIT: return git_commit_tree((git_tree **)dereferenced, (git_commit*)obj); case GIT_OBJ_TAG: return git_tag_target(dereferenced, (git_tag*)obj); case GIT_OBJ_BLOB: case GIT_OBJ_TREE: return GIT_EPEEL; default: return GIT_EINVALIDSPEC; } }
void test_refs_read__packed(void) { // lookup a packed reference git_reference *reference; git_object *object; cl_git_pass(git_reference_lookup(&reference, g_repo, packed_head_name)); cl_assert(git_reference_type(reference) & GIT_REF_OID); cl_assert(git_reference_is_packed(reference)); cl_assert_equal_s(reference->name, packed_head_name); cl_git_pass(git_object_lookup(&object, g_repo, git_reference_target(reference), GIT_OBJ_ANY)); cl_assert(object != NULL); cl_assert(git_object_type(object) == GIT_OBJ_COMMIT); git_object_free(object); git_reference_free(reference); }
ERL_NIF_TERM geef_revparse_single(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { ErlNifBinary bin, id; geef_repository *repo; geef_object *obj; ERL_NIF_TERM type, term_obj; if (!enif_get_resource(env, argv[0], geef_repository_type, (void **) &repo)) return enif_make_badarg(env); if (!enif_inspect_iolist_as_binary(env, argv[1], &bin)) return enif_make_badarg(env); if (geef_terminate_binary(&bin) < 0) return geef_oom(env); obj = enif_alloc_resource(geef_object_type, sizeof(geef_object)); if (!obj) return geef_oom(env); if (git_revparse_single(&obj->obj, repo->repo, (char *) bin.data) < 0) { enif_release_binary(&bin); enif_release_resource(obj); return geef_error(env); } type = geef_object_type2atom(git_object_type(obj->obj)); if (geef_oid_bin(&id, git_object_id(obj->obj)) < 0) return geef_oom(env); term_obj = enif_make_resource(env, obj); enif_release_resource(obj); obj->repo = repo; enif_keep_resource(repo); return enif_make_tuple4(env, atoms.ok, term_obj, type, enif_make_binary(env, &id)); }
GgitObject * ggit_utils_create_real_object (git_object *obj, gboolean owned) { git_otype otype; otype = git_object_type (obj); switch (otype) { case GIT_OBJ_TAG: return GGIT_OBJECT (_ggit_tag_wrap ((git_tag *)obj, owned)); case GIT_OBJ_BLOB: return GGIT_OBJECT (_ggit_blob_wrap ((git_blob *)obj, owned)); case GIT_OBJ_COMMIT: return GGIT_OBJECT (_ggit_commit_wrap ((git_commit *)obj, owned)); case GIT_OBJ_TREE: return GGIT_OBJECT (_ggit_tree_wrap ((git_tree *)obj, owned)); default: return NULL; } }
/** Tag listing: Lookup tags based on ref name and dispatch to print */ static int each_tag(const char *name, tag_state *state) { git_repository *repo = state->repo; git_object *obj; check_lg2(git_revparse_single(&obj, repo, name), "Failed to lookup rev", name); switch (git_object_type(obj)) { case GIT_OBJ_TAG: print_tag((git_tag *) obj, state); break; case GIT_OBJ_COMMIT: print_commit((git_commit *) obj, name, state); break; default: print_name(name); } git_object_free(obj); return 0; }
static void assert_peel( const char *ref_name, git_otype requested_type, const char* expected_sha, git_otype expected_type) { git_oid expected_oid; git_reference *ref; git_object *peeled; cl_git_pass(git_reference_lookup(&ref, g_repo, ref_name)); cl_git_pass(git_reference_peel(&peeled, ref, requested_type)); cl_git_pass(git_oid_fromstr(&expected_oid, expected_sha)); cl_assert_equal_i(0, git_oid_cmp(&expected_oid, git_object_id(peeled))); cl_assert_equal_i(expected_type, git_object_type(peeled)); git_object_free(peeled); git_reference_free(ref); }
static void assert_peel( const char *sha, git_otype requested_type, const char* expected_sha, git_otype expected_type) { git_oid oid, expected_oid; git_object *obj; git_object *peeled; cl_git_pass(git_oid_fromstr(&oid, sha)); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); cl_git_pass(git_object_peel(&peeled, obj, requested_type)); cl_git_pass(git_oid_fromstr(&expected_oid, expected_sha)); cl_assert_equal_i(0, git_oid_cmp(&expected_oid, git_object_id(peeled))); cl_assert_equal_i(expected_type, git_object_type(peeled)); git_object_free(peeled); git_object_free(obj); }
PyObject * lookup_object_prefix(Repository *repo, const git_oid *oid, size_t len, git_otype type) { int err; git_object *obj; Object *py_obj = NULL; err = git_object_lookup_prefix(&obj, repo->repo, oid, (unsigned int)len, type); if (err < 0) return Error_set_oid(err, oid, len); switch (git_object_type(obj)) { case GIT_OBJ_COMMIT: py_obj = PyObject_New(Object, &CommitType); break; case GIT_OBJ_TREE: py_obj = PyObject_New(Object, &TreeType); break; case GIT_OBJ_BLOB: py_obj = PyObject_New(Object, &BlobType); break; case GIT_OBJ_TAG: py_obj = PyObject_New(Object, &TagType); break; default: assert(0); } if (py_obj) { py_obj->obj = obj; py_obj->repo = repo; Py_INCREF(repo); } return (PyObject*)py_obj; }
int git_reset( git_repository *repo, const git_object *target, git_reset_type reset_type) { git_otype target_type = GIT_OBJ_BAD; git_object *commit = NULL; git_index *index = NULL; git_tree *tree = NULL; int error = -1; assert(repo && target); assert(reset_type == GIT_RESET_SOFT || reset_type == GIT_RESET_MIXED); if (git_object_owner(target) != repo) return reset_error_invalid("The given target does not belong to this repository."); if (reset_type == GIT_RESET_MIXED && git_repository_is_bare(repo)) return reset_error_invalid("Mixed reset is not allowed in a bare repository."); target_type = git_object_type(target); switch (target_type) { case GIT_OBJ_TAG: if (git_tag_peel(&commit, (git_tag *)target) < 0) goto cleanup; if (git_object_type(commit) != GIT_OBJ_COMMIT) { reset_error_invalid("The given target does not resolve to a commit."); goto cleanup; } break; case GIT_OBJ_COMMIT: commit = (git_object *)target; break; default: return reset_error_invalid("Only git_tag and git_commit objects are valid targets."); } //TODO: Check for unmerged entries if (git_reference__update(repo, git_object_id(commit), GIT_HEAD_FILE) < 0) goto cleanup; if (reset_type == GIT_RESET_SOFT) { error = 0; goto cleanup; } if (git_commit_tree(&tree, (git_commit *)commit) < 0) { giterr_set(GITERR_OBJECT, "%s - Failed to retrieve the commit tree.", ERROR_MSG); goto cleanup; } if (git_repository_index(&index, repo) < 0) { giterr_set(GITERR_OBJECT, "%s - Failed to retrieve the index.", ERROR_MSG); goto cleanup; } if (git_index_read_tree(index, tree) < 0) { giterr_set(GITERR_INDEX, "%s - Failed to update the index.", ERROR_MSG); goto cleanup; } if (git_index_write(index) < 0) { giterr_set(GITERR_INDEX, "%s - Failed to write the index.", ERROR_MSG); goto cleanup; } error = 0; cleanup: if (target_type == GIT_OBJ_TAG) git_object_free(commit); git_index_free(index); git_tree_free(tree); return error; }