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) { 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_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; }
int git_tree_remove_entry_byname(git_tree *tree, const char *filename) { int idx; assert(tree && filename); idx = git_vector_search(&tree->entries, filename); if (idx == GIT_ENOTFOUND) return GIT_ENOTFOUND; return git_tree_remove_entry_byindex(tree, idx); }
git_tree_entry *git_tree_entry_byname(git_tree *tree, const char *filename) { int idx; assert(tree && filename); idx = git_vector_search(&tree->entries, filename); if (idx == GIT_ENOTFOUND) return NULL; return git_vector_get(&tree->entries, idx); }
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); } }
int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs) { git_buf buf = GIT_BUF_INIT; size_t j, pos; git_remote_head key; const char* formatters[] = { GIT_REFS_DIR "%s", GIT_REFS_TAGS_DIR "%s", GIT_REFS_HEADS_DIR "%s", NULL }; git_refspec *cur = git__calloc(1, sizeof(git_refspec)); GITERR_CHECK_ALLOC(cur); cur->force = spec->force; cur->push = spec->push; cur->pattern = spec->pattern; cur->matching = spec->matching; cur->string = git__strdup(spec->string); /* shorthand on the lhs */ if (git__prefixcmp(spec->src, GIT_REFS_DIR)) { for (j = 0; formatters[j]; j++) { git_buf_clear(&buf); if (git_buf_printf(&buf, formatters[j], spec->src) < 0) return -1; key.name = (char *) git_buf_cstr(&buf); if (!git_vector_search(&pos, refs, &key)) { /* we found something to match the shorthand, set src to that */ cur->src = git_buf_detach(&buf); } } } /* No shorthands found, copy over the name */ if (cur->src == NULL && spec->src != NULL) { cur->src = git__strdup(spec->src); GITERR_CHECK_ALLOC(cur->src); } if (spec->dst && git__prefixcmp(spec->dst, GIT_REFS_DIR)) { /* if it starts with "remotes" then we just prepend "refs/" */ if (!git__prefixcmp(spec->dst, "remotes/")) { git_buf_puts(&buf, GIT_REFS_DIR); } else { git_buf_puts(&buf, GIT_REFS_HEADS_DIR); } if (git_buf_puts(&buf, spec->dst) < 0) return -1; cur->dst = git_buf_detach(&buf); } git_buf_free(&buf); if (cur->dst == NULL && spec->dst != NULL) { cur->dst = git__strdup(spec->dst); GITERR_CHECK_ALLOC(cur->dst); } return git_vector_insert(out, cur); }