Commit 39479daec29a845f84812b85418dc85dc3a433a9

Christian Weisgerber 2022-03-10T22:29:28

make "got cherrypick/backout" match argument against refs 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

diff --git a/got/got.c b/got/got.c
index a8e02bf..175740d 100644
--- a/got/got.c
+++ b/got/got.c
@@ -8372,20 +8372,10 @@ cmd_cherrypick(int argc, char *argv[])
 	if (error)
 		goto done;
 
-	error = got_repo_match_object_id_prefix(&commit_id, argv[0],
-	    GOT_OBJ_TYPE_COMMIT, repo);
-	if (error != NULL) {
-		struct got_reference *ref;
-		if (error->code != GOT_ERR_BAD_OBJ_ID_STR)
-			goto done;
-		error = got_ref_open(&ref, repo, argv[0], 0);
-		if (error != NULL)
-			goto done;
-		error = got_ref_resolve(&commit_id, repo, ref);
-		got_ref_close(ref);
-		if (error != NULL)
-			goto done;
-	}
+	error = got_repo_match_object_id(&commit_id, NULL, argv[0],
+	    GOT_OBJ_TYPE_COMMIT, NULL, repo);
+	if (error)
+		goto done;
 	error = got_object_id_str(&commit_id_str, commit_id);
 	if (error)
 		goto done;
@@ -8479,20 +8469,10 @@ cmd_backout(int argc, char *argv[])
 	if (error)
 		goto done;
 
-	error = got_repo_match_object_id_prefix(&commit_id, argv[0],
-	    GOT_OBJ_TYPE_COMMIT, repo);
-	if (error != NULL) {
-		struct got_reference *ref;
-		if (error->code != GOT_ERR_BAD_OBJ_ID_STR)
-			goto done;
-		error = got_ref_open(&ref, repo, argv[0], 0);
-		if (error != NULL)
-			goto done;
-		error = got_ref_resolve(&commit_id, repo, ref);
-		got_ref_close(ref);
-		if (error != NULL)
-			goto done;
-	}
+	error = got_repo_match_object_id(&commit_id, NULL, argv[0],
+	    GOT_OBJ_TYPE_COMMIT, NULL, repo);
+	if (error)
+		goto done;
 	error = got_object_id_str(&commit_id_str, commit_id);
 	if (error)
 		goto done;