make "got ref" match argument against references before object IDs Use got_repo_match_object_id() instead of hand-rolled code and pick up the updated handling of reference arguments. ok stsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
diff --git a/got/got.c b/got/got.c
index 5939e93..a8e02bf 100644
--- a/got/got.c
+++ b/got/got.c
@@ -5661,8 +5661,9 @@ static const struct got_error *
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 '-'.
@@ -5672,21 +5673,15 @@ add_ref(struct got_repository *repo, const char *refname, const char *target)
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)