int git_reference_symbolic_create_matching( git_reference **ref_out, git_repository *repo, const char *name, const char *target, int force, const char *old_target, const git_signature *signature, const char *log_message) { int error; git_signature *who = NULL; assert(target); if (!signature) { if ((error = git_reference__log_signature(&who, repo)) < 0) return error; else signature = who; } error = reference__create( ref_out, repo, name, NULL, target, force, signature, log_message, NULL, old_target); git_signature_free(who); return error; }
int git_reference_create_matching( git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id, int force, const git_oid *old_id, const git_signature *signature, const char *log_message) { int error; git_signature *who = NULL; assert(id); if (!signature) { if ((error = git_reference__log_signature(&who, repo)) < 0) return error; else signature = who; } error = reference__create( ref_out, repo, name, id, NULL, force, signature, log_message, old_id, NULL); git_signature_free(who); return error; }
/* * Starting with the reference given by `ref_name`, follows symbolic * references until a direct reference is found and updated the OID * on that direct reference to `oid`. */ int git_reference__update_terminal( git_repository *repo, const char *ref_name, const git_oid *oid, const git_signature *sig, const char *log_message) { git_reference *ref = NULL, *ref2 = NULL; git_signature *who = NULL; const git_signature *to_use; int error = 0; if (!sig && (error = git_reference__log_signature(&who, repo)) < 0) return error; to_use = sig ? sig : who; error = get_terminal(&ref, repo, ref_name, 0); /* found a dangling symref */ if (error == GIT_ENOTFOUND && ref) { assert(git_reference_type(ref) == GIT_REF_SYMBOLIC); giterr_clear(); error = reference__create(&ref2, repo, ref->target.symbolic, oid, NULL, 0, to_use, log_message, NULL, NULL); } else if (error == GIT_ENOTFOUND) { giterr_clear(); error = reference__create(&ref2, repo, ref_name, oid, NULL, 0, to_use, log_message, NULL, NULL); } else if (error == 0) { assert(git_reference_type(ref) == GIT_REF_OID); error = reference__create(&ref2, repo, ref->name, oid, NULL, 1, to_use, log_message, &ref->target.oid, NULL); } git_reference_free(ref2); git_reference_free(ref); git_signature_free(who); return error; }
int git_reference_symbolic_create( git_reference **ref_out, git_repository *repo, const char *name, const char *target, int force) { char normalized[GIT_REFNAME_MAX]; int error = 0; assert(repo && name && target); if ((error = git_reference__normalize_name_lax( normalized, sizeof(normalized), target)) < 0) return error; return reference__create(ref_out, repo, name, NULL, normalized, force); }
int git_reference__update_for_commit( git_repository *repo, git_reference *ref, const char *ref_name, const git_oid *id, const char *operation) { git_reference *ref_new = NULL; git_commit *commit = NULL; git_buf reflog_msg = GIT_BUF_INIT; const git_signature *who; int error; if ((error = git_commit_lookup(&commit, repo, id)) < 0 || (error = git_buf_printf(&reflog_msg, "%s%s: %s", operation ? operation : "commit", git_commit_parentcount(commit) == 0 ? " (initial)" : "", git_commit_summary(commit))) < 0) goto done; who = git_commit_committer(commit); if (ref) { if ((error = ensure_is_an_updatable_direct_reference(ref)) < 0) return error; error = reference__create(&ref_new, repo, ref->name, id, NULL, 1, who, git_buf_cstr(&reflog_msg), &ref->target.oid, NULL); } else error = git_reference__update_terminal( repo, ref_name, id, who, git_buf_cstr(&reflog_msg)); done: git_reference_free(ref_new); git_buf_free(&reflog_msg); git_commit_free(commit); return error; }
int git_reference_create( git_reference **ref_out, git_repository *repo, const char *name, const git_oid *oid, int force) { git_odb *odb; int error = 0; assert(repo && name && oid); /* 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; } return reference__create(ref_out, repo, name, oid, NULL, force); }