"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
handle reference arguments that look like short object IDs
To:
gameoftrees@openbsd.org
Date:
Mon, 7 Mar 2022 11:54:38 +0100

Download raw body.

Thread
I have a branch called "11ac" which I cannot diff by name because
got diff errors out as follows:

$ got diff master 11ac
got: ambiguous object ID
$

This branch name happens to look like a short object ID for these commits:

$ got log | grep '^commit 11ac'
commit 11acbd79e0b4d889558d2ee5c5773ca249512a41
commit 11ac5a8e47e16be06760af9552d032a0c79da4e5
commit 11ac80a095affa347969defb1ccdb14bbdba914f
commit 11aca5de0641899f73ba1613800ee4888b89ef9f
$

As a workaround, I can use 'got diff master refs/heads/11ac'. But this
does not seem intuitive.

With the patch below, 'got diff master 11ac' produces the expected output:

$ got diff master 11ac | diffstat
 dev/pci/if_iwx.c              |  357 +++++++++++++++++++++++++++++++++++-------
 dev/pci/if_iwxreg.h           |    4 
 dev/pci/if_iwxvar.h           |    1 
 net80211/ieee80211.c          |    4 
 net80211/ieee80211.h          |   90 ++++++++++
 net80211/ieee80211_input.c    |   59 ++++++
 net80211/ieee80211_ioctl.h    |    3 
 net80211/ieee80211_node.c     |   77 +++++++++
 net80211/ieee80211_node.h     |   79 +++++++++
 net80211/ieee80211_output.c   |   38 ++++
 net80211/ieee80211_proto.c    |   59 ++++++
 net80211/ieee80211_proto.h    |    3 
 net80211/ieee80211_radiotap.h |    1 
 net80211/ieee80211_var.h      |   16 +
 14 files changed, 719 insertions(+), 72 deletions(-)
$

Regression tests are still passing.

Ok?

-----------------------------------------------
commit c9d2182094098f4ceb70560b5df9a76f7d6b5865 (match-refs-first)
from: Stefan Sperling <stsp@stsp.name>
date: Mon Mar  7 10:40:57 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
 
diff d802d72265281c9200c722522d463710c2e40160 0540c7ad644c868c5731bddaab5485ab2f580578
blob - 52605751687dfacb015e943762eb3bfc59fcdfd7
blob + 8885743e283c1cb4fc9c98d7c28f6d6732f33469
--- lib/repository.c
+++ lib/repository.c
@@ -1776,27 +1776,36 @@ 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)
-			goto done;
-		if (label) {
-			*label = strdup(got_ref_get_name(ref));
-			if (*label == NULL) {
-				err = got_error_from_errno("strdup");
-				goto done;
-			}
-		}
+	err = got_ref_open(&ref, repo, id_str, 0);
+	if (err == NULL) {
 		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");
+		if (err)
 			goto done;
+		if (label) {
+			*label = strdup(got_ref_get_name(ref));
+			if (*label == NULL) {
+				err = got_error_from_errno("strdup");
+				goto done;
+			}
 		}
+	} 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)