static void ggit_object_finalize (GObject *object) { GgitObject *obj = GGIT_OBJECT (object); git_object_close (obj->priv->obj); G_OBJECT_CLASS (ggit_object_parent_class)->finalize (object); }
void git_revwalk_reset(git_revwalk *walk) { const void *_unused; git_revwalk_commit *commit; assert(walk); GIT_HASHTABLE_FOREACH(walk->commits, _unused, commit, { git_object_close((git_object *)commit->commit_object); git_revwalk_list_clear(&commit->parents); free(commit); });
int git_blob_writefile(git_oid *written_id, git_repository *repo, const char *path) { int error; git_blob *blob; if (gitfo_exists(path) < 0) return GIT_ENOTFOUND; if ((error = git_blob_new(&blob, repo)) < GIT_SUCCESS) return error; if ((error = git_blob_set_rawcontent_fromfile(blob, path)) < GIT_SUCCESS) return error; if ((error = git_object_write((git_object *)blob)) < GIT_SUCCESS) return error; git_oid_cpy(written_id, git_object_id((git_object *)blob)); /* FIXME: maybe we don't want to free this already? * the user may want to access it again */ git_object_close((git_object *)blob); return GIT_SUCCESS; }
static int add_ref(const char *name, git_repository *repo, git_vector *vec) { const char peeled[] = "^{}"; git_remote_head *head; git_reference *ref; git_object *obj = NULL; int error = GIT_SUCCESS, peel_len, ret; head = git__malloc(sizeof(git_remote_head)); if (head == NULL) return GIT_ENOMEM; head->name = git__strdup(name); if (head->name == NULL) { error = GIT_ENOMEM; goto out; } error = git_reference_lookup(&ref, repo, name); if (error < GIT_SUCCESS) goto out; error = git_reference_resolve(&ref, ref); if (error < GIT_SUCCESS) goto out; git_oid_cpy(&head->oid, git_reference_oid(ref)); error = git_vector_insert(vec, head); if (error < GIT_SUCCESS) goto out; /* If it's not a tag, we don't need to try to peel it */ if (git__prefixcmp(name, GIT_REFS_TAGS_DIR)) goto out; error = git_object_lookup(&obj, repo, &head->oid, GIT_OBJ_ANY); if (error < GIT_SUCCESS) { git__rethrow(error, "Failed to lookup object"); } /* If it's not an annotated tag, just get out */ if (git_object_type(obj) != GIT_OBJ_TAG) goto out; /* And if it's a tag, peel it, and add it to the list */ head = git__malloc(sizeof(git_remote_head)); peel_len = strlen(name) + STRLEN(peeled); head->name = git__malloc(peel_len + 1); ret = snprintf(head->name, peel_len + 1, "%s%s", name, peeled); if (ret >= peel_len + 1) { error = git__throw(GIT_ERROR, "The string is magically to long"); } git_oid_cpy(&head->oid, git_tag_target_oid((git_tag *) obj)); error = git_vector_insert(vec, head); if (error < GIT_SUCCESS) goto out; out: git_object_close(obj); if (error < GIT_SUCCESS) { free(head->name); free(head); } return error; }