commit 0ed2285b0119b293d6b77b882c707c0377e176cd from: Stefan Sperling date: Wed Mar 09 08:55:42 2022 UTC handle reference arguments which look like short object IDs Match command line arguments against references before matching object IDs. This makes it possible to use reference names that happen to match a short object ID. For example, a branch called "11ac" could not be diffed in OpenBSD src.git which happens to contain commit IDs that begin with hex digits 0x11ac. A bogus error would be reported in this situation: $ got diff master 11ac got: ambiguous object ID ok naddy commit - d955343d21ec47956137ebce96b31ce9c0de5669 commit + 0ed2285b0119b293d6b77b882c707c0377e176cd blob - 52605751687dfacb015e943762eb3bfc59fcdfd7 blob + 8885743e283c1cb4fc9c98d7c28f6d6732f33469 --- lib/repository.c +++ lib/repository.c @@ -1776,12 +1776,10 @@ got_repo_match_object_id(struct got_object_id **id, ch return err; } - err = got_repo_match_object_id_prefix(id, id_str, obj_type, repo); - if (err) { - if (err->code != GOT_ERR_BAD_OBJ_ID_STR) - return err; - err = got_ref_open(&ref, repo, id_str, 0); - if (err != NULL) + err = got_ref_open(&ref, repo, id_str, 0); + if (err == NULL) { + err = got_ref_resolve(id, repo, ref); + if (err) goto done; if (label) { *label = strdup(got_ref_get_name(ref)); @@ -1790,13 +1788,24 @@ got_repo_match_object_id(struct got_object_id **id, ch goto done; } } - err = got_ref_resolve(id, repo, ref); - } else if (label) { - err = got_object_id_str(label, *id); - if (*label == NULL) { - err = got_error_from_errno("strdup"); + } else { + if (err->code != GOT_ERR_NOT_REF && + err->code != GOT_ERR_BAD_REF_NAME) goto done; + err = got_repo_match_object_id_prefix(id, id_str, + obj_type, repo); + if (err) { + if (err->code == GOT_ERR_BAD_OBJ_ID_STR) + err = got_error_not_ref(id_str); + goto done; } + if (label) { + err = got_object_id_str(label, *id); + if (*label == NULL) { + err = got_error_from_errno("strdup"); + goto done; + } + } } done: if (ref)