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

From:
Omar Polo <op@omarpolo.com>
Subject:
improve `got he' error reporting (and accept shortened ids)
To:
gameoftrees@openbsd.org
Date:
Mon, 27 Feb 2023 10:15:54 +0100

Download raw body.

Thread
This should improve the error reporting from the histedit script
parsing.  Instead of an imperscrutable "syntax error", I'm trying to
include more clues to what went wrong.  knowing that an "unknown
command" was used or an "invalid object id" was provided seems useful.

While here I'm also bundling another small change: allow the usage of
shortened commit ids.

diff /home/op/w/got
commit - e96d39bf87c8025d794e9c5c5bfcbbca58c216ac
path + /home/op/w/got
blob - e95ba2936e96e58c1f16c13b3a81b482f35d02a4
file + got/got.c
--- got/got.c
+++ got/got.c
@@ -11591,13 +11591,13 @@ histedit_syntax_error(int lineno)
 }
 
 static const struct got_error *
-histedit_syntax_error(int lineno)
+histedit_syntax_error(int lineno, const char *reason)
 {
 	static char msg[42];
 	int ret;
 
-	ret = snprintf(msg, sizeof(msg), "histedit syntax error on line %d",
-	    lineno);
+	ret = snprintf(msg, sizeof(msg),
+	    "histedit syntax error on line %d: %s", lineno, reason);
 	if (ret < 0 || (size_t)ret >= sizeof(msg))
 		return got_error(GOT_ERR_HISTEDIT_SYNTAX);
 
@@ -11782,7 +11782,7 @@ histedit_parse_list(struct got_histedit_list *histedit
 			}
 		}
 		if (i == nitems(got_histedit_cmds)) {
-			err = histedit_syntax_error(lineno);
+			err = histedit_syntax_error(lineno, "unknown command");
 			break;
 		}
 		while (isspace((unsigned char)p[0]))
@@ -11812,10 +11812,12 @@ histedit_parse_list(struct got_histedit_list *histedit
 				end++;
 			*end = '\0';
 
-			err = got_object_resolve_id_str(&commit_id, repo, p);
+			err = got_repo_match_object_id_prefix(&commit_id,
+			    p, GOT_OBJ_TYPE_COMMIT, repo);
 			if (err) {
 				/* override error code */
-				err = histedit_syntax_error(lineno);
+				err = histedit_syntax_error(lineno,
+				    "invalid object id");
 				break;
 			}
 		}