git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: surprising error message in parse_opt_with_commit

From
Shawn O. Pearce <spearce@spearce.org>
Date
Aug 6, 2009, 19:34 UTC
Message-ID
<20090806193413.GJ1033@spearce.org>
In-Reply-To
<e1a5e9a00908061227n67a878f5tb2d5130582b4fd44@mail.gmail.com>
Tim Harper <timcharper@gmail.com> wrote:
Show 22 quoted lines
>  610 int parse_opt_with_commit(const struct option *opt, const char
> *arg, int unset)
>  611 {
>  612 	unsigned char sha1[20];
>  613 	struct commit *commit;
>  614
>  615 	if (!arg)
>  616 		return -1;
>  617 	if (get_sha1(arg, sha1))
>  618 		return error("malformed object name %s", arg);
>  619 	commit = lookup_commit_reference(sha1);
>  620 	if (!commit)
>  621 		return error("no such commit %s", arg);
>  622 	commit_list_insert(commit, opt->value);
>  623 	return 0;
>  624 }
> 
> It appears the get_sha1 call is returning true, causing the 'malformed
> object name' error to be returned.  However, it seems that ideally
> since efabdfb is not malformed (it would be a valid ref if it
> existed), the execution path should continue to line 619, receive no
> commit, and fail on 621.

get_sha1 is responsible for expanding an abbreviated ID to the full ID. If it can't do the expansion, it errors out. The code is correct as-is, though the error message on 618 is a bit odd.

-- 
Shawn.
Previous: Tim HarperNext: Tim Harper
Message 2 of 5 in “surprising error message in parse_opt_with_commit”
  1. Tim HarperAug 6, 2009
  2. Shawn O. PearceAug 6, 2009
  3. clarify error message when an abbreviated non-existent commit was specifiedTim Harper, Aug 6, 2009
  4. Tim HarperAug 7, 2009
  5. Junio C HamanoAug 7, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.