static void patch_parsed__free(git_patch *p) { git_patch_parsed *patch = (git_patch_parsed *)p; if (!patch) return; git_patch_parse_ctx_free(patch->ctx); git__free((char *)patch->base.binary.old_file.data); git__free((char *)patch->base.binary.new_file.data); git_array_clear(patch->base.hunks); git_array_clear(patch->base.lines); git__free(patch->base.delta); git__free(patch->old_prefix); git__free(patch->new_prefix); git__free(patch->header_old_path); git__free(patch->header_new_path); git__free(patch->rename_old_path); git__free(patch->rename_new_path); git__free(patch->old_path); git__free(patch->new_path); git__free(patch); }
static int mark_uninteresting(git_revwalk *walk, git_commit_list_node *commit) { int error; unsigned short i; git_array_t(git_commit_list_node *) pending = GIT_ARRAY_INIT; git_commit_list_node **tmp; assert(commit); do { commit->uninteresting = 1; if ((error = git_commit_list_parse(walk, commit)) < 0) return error; for (i = 0; i < commit->out_degree; ++i) if (!commit->parents[i]->uninteresting) { git_commit_list_node **node = git_array_alloc(pending); GITERR_CHECK_ALLOC(node); *node = commit->parents[i]; } tmp = git_array_pop(pending); commit = tmp ? *tmp : NULL; } while (commit != NULL); git_array_clear(pending); return 0; }
int git_commit_create_buffer(git_buf *out, git_repository *repo, const git_signature *author, const git_signature *committer, const char *message_encoding, const char *message, const git_tree *tree, size_t parent_count, const git_commit *parents[]) { int error; commit_parent_data data = { parent_count, parents, repo }; git_array_oid_t parents_arr = GIT_ARRAY_INIT; const git_oid *tree_id; assert(tree && git_tree_owner(tree) == repo); tree_id = git_tree_id(tree); if ((error = validate_tree_and_parents(&parents_arr, repo, tree_id, commit_parent_from_array, &data, NULL, true)) < 0) return error; error = git_commit__create_buffer_internal( out, author, committer, message_encoding, message, tree_id, &parents_arr); git_array_clear(parents_arr); return error; }
static int git_commit__create_internal( git_oid *id, git_repository *repo, const char *update_ref, const git_signature *author, const git_signature *committer, const char *message_encoding, const char *message, const git_oid *tree, git_commit_parent_callback parent_cb, void *parent_payload, bool validate) { int error; git_odb *odb; git_reference *ref = NULL; git_buf buf = GIT_BUF_INIT; const git_oid *current_id = NULL; git_array_oid_t parents = GIT_ARRAY_INIT; if (update_ref) { error = git_reference_lookup_resolved(&ref, repo, update_ref, 10); if (error < 0 && error != GIT_ENOTFOUND) return error; } giterr_clear(); if (ref) current_id = git_reference_target(ref); if ((error = validate_tree_and_parents(&parents, repo, tree, parent_cb, parent_payload, current_id, validate)) < 0) goto cleanup; error = git_commit__create_buffer_internal(&buf, author, committer, message_encoding, message, tree, &parents); if (error < 0) goto cleanup; if (git_repository_odb__weakptr(&odb, repo) < 0) goto cleanup; if (git_odb_write(id, odb, buf.ptr, buf.size, GIT_OBJ_COMMIT) < 0) goto cleanup; if (update_ref != NULL) { error = git_reference__update_for_commit( repo, ref, update_ref, id, "commit"); goto cleanup; } cleanup: git_array_clear(parents); git_reference_free(ref); git_buf_free(&buf); return error; }
void git_rebase_free(git_rebase *rebase) { if (rebase == NULL) return; git__free(rebase->onto_name); git__free(rebase->orig_head_name); git__free(rebase->state_path); git_array_clear(rebase->operations); git__free(rebase); }
void git_rebase_free(git_rebase *rebase) { if (rebase == NULL) return; git_index_free(rebase->index); git_commit_free(rebase->last_commit); git__free(rebase->onto_name); git__free(rebase->orig_head_name); git__free(rebase->state_path); git_array_clear(rebase->operations); git__free((char *)rebase->options.rewrite_notes_ref); git__free(rebase); }
void git_diff_driver_free(git_diff_driver *driver) { size_t i; if (!driver) return; for (i = 0; i < git_array_size(driver->fn_patterns); ++i) regfree(& git_array_get(driver->fn_patterns, i)->re); git_array_clear(driver->fn_patterns); regfree(&driver->word_pattern); git__free(driver); }
void git_commit__free(void *_commit) { git_commit *commit = _commit; git_array_clear(commit->parent_ids); git_signature_free(commit->author); git_signature_free(commit->committer); git__free(commit->raw_header); git__free(commit->raw_message); git__free(commit->message_encoding); git__free(commit->summary); git__free(commit); }
static int validate_tree_and_parents(git_array_oid_t *parents, git_repository *repo, const git_oid *tree, git_commit_parent_callback parent_cb, void *parent_payload, const git_oid *current_id, bool validate) { size_t i; int error; git_oid *parent_cpy; const git_oid *parent; if (validate && !git_object__is_valid(repo, tree, GIT_OBJECT_TREE)) return -1; i = 0; while ((parent = parent_cb(i, parent_payload)) != NULL) { if (validate && !git_object__is_valid(repo, parent, GIT_OBJECT_COMMIT)) { error = -1; goto on_error; } parent_cpy = git_array_alloc(*parents); GITERR_CHECK_ALLOC(parent_cpy); git_oid_cpy(parent_cpy, parent); i++; } if (current_id && (parents->size == 0 || git_oid_cmp(current_id, git_array_get(*parents, 0)))) { giterr_set(GITERR_OBJECT, "failed to create commit: current tip is not the first parent"); error = GIT_EMODIFIED; goto on_error; } return 0; on_error: git_array_clear(*parents); return error; }