static int update_target(git_refdb *db, transaction_node *node) { git_reference *ref; int error, update_reflog; if (node->ref_type == GIT_REF_OID) { ref = git_reference__alloc(node->name, &node->target.id, NULL); } else if (node->ref_type == GIT_REF_SYMBOLIC) { ref = git_reference__alloc_symbolic(node->name, node->target.symbolic); } else { abort(); } GITERR_CHECK_ALLOC(ref); update_reflog = node->reflog == NULL; if (node->remove) { error = git_refdb_unlock(db, node->payload, 2, false, ref, NULL, NULL); } else if (node->ref_type == GIT_REF_OID) { error = git_refdb_unlock(db, node->payload, true, update_reflog, ref, node->sig, node->message); } else if (node->ref_type == GIT_REF_SYMBOLIC) { error = git_refdb_unlock(db, node->payload, true, update_reflog, ref, node->sig, node->message); } else { abort(); } git_reference_free(ref); node->committed = true; return error; }
int git_reference_dup(git_reference **dest, git_reference *source) { if (source->type == GIT_REF_SYMBOLIC) *dest = git_reference__alloc_symbolic(source->name, source->target.symbolic); else *dest = git_reference__alloc(source->name, &source->target.oid, &source->peel); GITERR_CHECK_ALLOC(*dest); return 0; }
static int reference__create( git_reference **ref_out, git_repository *repo, const char *name, const git_oid *oid, const char *symbolic, int force) { char normalized[GIT_REFNAME_MAX]; git_refdb *refdb; git_reference *ref = NULL; int error = 0; if (ref_out) *ref_out = NULL; error = git_reference__normalize_name_lax(normalized, sizeof(normalized), name); if (error < 0) return error; error = git_repository_refdb__weakptr(&refdb, repo); if (error < 0) return error; if (oid != NULL) { assert(symbolic == NULL); ref = git_reference__alloc(normalized, oid, NULL); } else { ref = git_reference__alloc_symbolic(normalized, symbolic); } GITERR_CHECK_ALLOC(ref); if ((error = git_refdb_write(refdb, ref, force)) < 0) { git_reference_free(ref); return error; } if (ref_out == NULL) git_reference_free(ref); else *ref_out = ref; return 0; }
int hiredis_refdb_backend__lookup(git_reference **out, git_refdb_backend *_backend, const char *ref_name) { hiredis_refdb_backend *backend; int error = GIT_OK; redisReply *reply; git_oid oid; assert(ref_name && _backend); backend = (hiredis_refdb_backend *) _backend; reply = redisCommand(backend->db, "HMGET %s:%s:refdb:%s type target", backend->prefix, backend->repo_path, ref_name); if(reply->type == REDIS_REPLY_ARRAY) { if (reply->element[0]->type != REDIS_REPLY_NIL && reply->element[1]->type != REDIS_REPLY_NIL) { git_ref_t type = (git_ref_t) atoi(reply->element[0]->str); if (type == GIT_REF_OID) { git_oid_fromstr(&oid, reply->element[1]->str); *out = git_reference__alloc(ref_name, &oid, NULL); } else if (type == GIT_REF_SYMBOLIC) { *out = git_reference__alloc_symbolic(ref_name, reply->element[1]->str); } else { giterr_set_str(GITERR_REFERENCE, "Redis refdb storage corrupted (unknown ref type returned)"); error = GIT_ERROR; } } else { giterr_set_str(GITERR_REFERENCE, "Redis refdb couldn't find ref"); error = GIT_ENOTFOUND; } } else { giterr_set_str(GITERR_REFERENCE, "Redis refdb storage error"); error = GIT_ERROR; } freeReplyObject(reply); return error; }
static int reference__create( git_reference **ref_out, git_repository *repo, const char *name, const git_oid *oid, const char *symbolic, int force, const git_signature *signature, const char *log_message, const git_oid *old_id, const char *old_target) { git_refname_t normalized; git_refdb *refdb; git_reference *ref = NULL; int error = 0; assert(repo && name); assert(symbolic || signature); if (ref_out) *ref_out = NULL; error = reference_normalize_for_repo(normalized, repo, name); if (error < 0) return error; error = git_repository_refdb__weakptr(&refdb, repo); if (error < 0) return error; if (oid != NULL) { git_odb *odb; assert(symbolic == NULL); /* Sanity check the reference being created - target must exist. */ if ((error = git_repository_odb__weakptr(&odb, repo)) < 0) return error; if (!git_odb_exists(odb, oid)) { giterr_set(GITERR_REFERENCE, "Target OID for the reference doesn't exist on the repository"); return -1; } ref = git_reference__alloc(normalized, oid, NULL); } else { git_refname_t normalized_target; if ((error = reference_normalize_for_repo(normalized_target, repo, symbolic)) < 0) return error; ref = git_reference__alloc_symbolic(normalized, normalized_target); } GITERR_CHECK_ALLOC(ref); if ((error = git_refdb_write(refdb, ref, force, signature, log_message, old_id, old_target)) < 0) { git_reference_free(ref); return error; } if (ref_out == NULL) git_reference_free(ref); else *ref_out = ref; return 0; }
static int reference__create( git_reference **ref_out, git_repository *repo, const char *name, const git_oid *oid, const char *symbolic, int force, const git_signature *signature, const char *log_message, const git_oid *old_id, const char *old_target) { git_refname_t normalized; git_refdb *refdb; git_reference *ref = NULL; int error = 0; assert(repo && name); assert(symbolic || signature); if (ref_out) *ref_out = NULL; error = reference_normalize_for_repo(normalized, repo, name, true); if (error < 0) return error; error = git_repository_refdb__weakptr(&refdb, repo); if (error < 0) return error; if (oid != NULL) { assert(symbolic == NULL); if (!git_object__is_valid(repo, oid, GIT_OBJ_ANY)) { giterr_set(GITERR_REFERENCE, "target OID for the reference doesn't exist on the repository"); return -1; } ref = git_reference__alloc(normalized, oid, NULL); } else { git_refname_t normalized_target; error = reference_normalize_for_repo(normalized_target, repo, symbolic, git_reference__enable_symbolic_ref_target_validation); if (error < 0) return error; ref = git_reference__alloc_symbolic(normalized, normalized_target); } GITERR_CHECK_ALLOC(ref); if ((error = git_refdb_write(refdb, ref, force, signature, log_message, old_id, old_target)) < 0) { git_reference_free(ref); return error; } if (ref_out == NULL) git_reference_free(ref); else *ref_out = ref; return 0; }