static int write_back(git_object *object) { int error; git_oid new_id; assert(object); assert(object->source.open); assert(object->modified); object->source.raw.len = object->source.written_bytes; if ((error = git_odb_write(&new_id, object->repo->db, &object->source.raw)) < GIT_SUCCESS) return error; if (!object->in_memory) git_hashtable_remove(object->repo->objects, &object->id); git_oid_cpy(&object->id, &new_id); git_hashtable_insert(object->repo->objects, &object->id, object); object->source.write_ptr = NULL; object->source.written_bytes = 0; object->modified = 0; object->in_memory = 0; git_object__source_close(object); return GIT_SUCCESS; }
void git_object_free(git_object *object) { if (object == NULL) return; git_object__source_close(object); git_hashtable_remove(object->repo->objects, &object->id); switch (object->source.raw.type) { case GIT_OBJ_COMMIT: git_commit__free((git_commit *)object); break; case GIT_OBJ_TREE: git_tree__free((git_tree *)object); break; case GIT_OBJ_TAG: git_tag__free((git_tag *)object); break; case GIT_OBJ_BLOB: git_blob__free((git_blob *)object); break; default: free(object); break; } }
void git_object_close(git_object *object) { if (object == NULL) return; if (--object->refcount <= 0) { if (object->repo != NULL) { if (object->in_memory) { int idx = git_vector_search(&object->repo->memory_objects, object); git_vector_remove(&object->repo->memory_objects, idx); } else { git_hashtable_remove(object->repo->objects, &object->id); } } git_object__free(object); } }