commit - d3830477eab7ce40f587d0a086dac840174c92bf
commit + f111bd6ad40f24789055cc9fd2cfc398a54f79ed
blob - c2f5e271570a023ed95b95d16eff2352256e44ad
blob + 216586765e6c46489da686b0fac76236066f3c6c
--- got/got.c
+++ got/got.c
add_ref(struct got_repository *repo, const char *refname, const char *target)
{
const struct got_error *err = NULL;
- struct got_object_id *id;
+ struct got_object_id *id = NULL;
struct got_reference *ref = NULL;
+ struct got_reflist_head refs;
/*
* Don't let the user create a reference name with a leading '-'.
if (refname[0] == '-')
return got_error_path(refname, GOT_ERR_REF_NAME_MINUS);
- err = got_repo_match_object_id_prefix(&id, target, GOT_OBJ_TYPE_ANY,
- repo);
- if (err) {
- struct got_reference *target_ref;
-
- if (err->code != GOT_ERR_BAD_OBJ_ID_STR)
- return err;
- err = got_ref_open(&target_ref, repo, target, 0);
- if (err)
- return err;
- err = got_ref_resolve(&id, repo, target_ref);
- got_ref_close(target_ref);
- if (err)
- return err;
- }
+ TAILQ_INIT(&refs);
+ err = got_ref_list(&refs, repo, NULL, got_ref_cmp_by_name, NULL);
+ if (err)
+ goto done;
+ err = got_repo_match_object_id(&id, NULL, target, GOT_OBJ_TYPE_ANY,
+ &refs, repo);
+ got_ref_list_free(&refs);
+ if (err)
+ goto done;
err = got_ref_alloc(&ref, refname, id);
if (err)