/* * 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) { return reference__update_terminal(repo, ref_name, oid, 0); }
/* * 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 *signature, const char *log_message) { return reference__update_terminal(repo, ref_name, oid, 0, signature, log_message); }
static int reference__update_terminal( git_repository *repo, const char *ref_name, const git_oid *oid, int nesting, const git_signature *signature, const char *log_message) { git_reference *ref; int error = 0; if (nesting > MAX_NESTING_LEVEL) { giterr_set(GITERR_REFERENCE, "Reference chain too deep (%d)", nesting); return GIT_ENOTFOUND; } error = git_reference_lookup(&ref, repo, ref_name); /* If we haven't found the reference at all, create a new reference. */ if (error == GIT_ENOTFOUND) { giterr_clear(); return git_reference_create(NULL, repo, ref_name, oid, 0, signature, log_message); } if (error < 0) return error; /* If the ref is a symbolic reference, follow its target. */ if (git_reference_type(ref) == GIT_REF_SYMBOLIC) { error = reference__update_terminal(repo, git_reference_symbolic_target(ref), oid, nesting+1, signature, log_message); git_reference_free(ref); } else { /* If we're not moving the target, don't recreate the ref */ if (0 != git_oid_cmp(git_reference_target(ref), oid)) error = git_reference_create(NULL, repo, ref_name, oid, 1, signature, log_message); git_reference_free(ref); } return error; }